Skip to main content

All Questions

Filter by
Sorted by
Tagged with
9 votes
1 answer
2k views

Codility MaxCounters peformance in Python capping out at 77% performance

My problem is quite similar to the question found here, except I am attempting to answer the question in Python. Given an array of N counters, all initialized to 0, and an array ...
optical_anathema's user avatar
0 votes
3 answers
201 views

My take at ProjectEuler #17 - counting counting characters

I tried to tackle #17 problem on Project Euler: If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are \$3 + 3 + 5 + ...
ambitious_roi's user avatar
4 votes
1 answer
659 views

Sum of numbers which are not sum of two abundant numbers

The following program is a solution to Project Euler Problem 23. That problem defines an abundant number to be one whose sum of proper divisors is greater than it, tells us that all integers at least ...
Martin Leslie's user avatar
4 votes
2 answers
148 views

Summing all parameters, except the last, which should be subtracted instead

Working on some python koans and got one which states: ...
Kelvin's user avatar
  • 143
4 votes
5 answers
3k views

Finding if a given number is in a given range based on a flag

Question Description: Given a number n, return True if n is in the range 1..10, inclusive. ...
Anirudh's user avatar
  • 872
4 votes
1 answer
5k views

Skyline problem solved by sweep line

The Skyline problem from UVa Online Judge is as follows: You are to design a program to assist an architect in drawing the skyline of a city given the locations of the buildings in the city. A ...
user2617521's user avatar
2 votes
3 answers
377 views

Optimizing run time of Python solution to Project Euler Problem 34

This is a brute force solution to Project Euler Problem 34 with only 1 optimization (i.e.: caching factorials): ...
syntagma's user avatar
  • 231
2 votes
1 answer
2k views

Index of letter removed to make string palindrome

This code finds the index in the string and removes the one which will make the string a palindrome. If the string is already a palindrome, it should return -1. This code works correct, but I am ...
Anubhav Agarwal's user avatar
9 votes
1 answer
620 views

Horridly Inefficient Project Euler #14 in Python - Collatz Sequences

I created this solution a while ago, and have been going back over my problems to try to make them all more efficient. I have been stuck on this one, and have tried a few different ideas. So far, my ...
Jose Magana's user avatar
3 votes
1 answer
2k views

Performance in Hackerrank challenge "Sherlock and Queries"

I translated the solution by the author to his challenge from C++ to Python. It seems to be correct, but I get timeouts for the test cases 6, 9 and 12. Here is the full challenge description: ...
Tobias Hermann's user avatar
3 votes
2 answers
208 views

Answer to an implementation of Project Euler #8

I saw that there was a previous question asking to review an answer to the Project Euler question #8. My answer didn't look anything like the answer in that question and as a beginner, I was wondering ...
g.humpkins's user avatar
8 votes
1 answer
7k views

Functional Knapsack Problem in Python

This is the knapsack problem from rosettacode.org: A tourist wants to make a good trip at the weekend with his friends. They will go to the mountains to see the wonders of nature, so he needs to ...
cheezsteak's user avatar
  • 2,401
2 votes
2 answers
144 views

Optimizing code for sequence A064604

I am implementing A064604 - OEIS for positive integers up to 10 billion. I am finding the divisors in \$O(\sqrt N)\$. So, the overall time complexity of running the formula right now is \$O(N\sqrt N)\...
rayu's user avatar
  • 129
5 votes
1 answer
1k views

Project Euler #10 - summation of primes

(From Project Euler) The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. Can someone please help me improve this code? ...
Diba SH's user avatar
  • 101
6 votes
3 answers
3k views

Caesar cipher exercise

I was doing this exercise from here. I made a solution work but can't help feel it could have been done in fewer lines. I'm quite new to python so I'm not too sure of the little shortcuts. ...
MathsIsHard's user avatar
5 votes
2 answers
4k views

HackerRank "Manasa and Stones" in Python

Problem Statement: Manasa is out on a hike with friends. She finds a trail of stones with numbers on them. She starts following the trail and notices that two consecutive stones have a difference of ...
mleyfman's user avatar
  • 5,170
9 votes
3 answers
4k views

HackerRank "Service Lane" in Python

Problem statement: Calvin is driving his favorite vehicle on the 101 freeway. He notices that the check engine light of his vehicle is on, and he wants to service it immediately to avoid any risks. ...
mleyfman's user avatar
  • 5,170
4 votes
3 answers
3k views

Project Euler 81 (minimum path sum through a matrix)

Problem Statement: In the 5 by 5 matrix below, 131 673 234 103 18 201 96 342 965 150 630 803 746 422 111 537 699 497 121 956 805 732 524 37 331 ...
mleyfman's user avatar
  • 5,170
13 votes
1 answer
7k views

Optimizing "Poker hands" challenge solution

I'm trying to solve the project Euler problem 54. In the card game poker, a hand consists of five cards and are ranked, from lowest to highest, in the following way: High Card: Highest ...
Anshul Goyal's user avatar
9 votes
3 answers
11k views

Project Euler #9 - Pythagorean triplets

This code works, and I'm trying to figure out if there's a better way to optimize it. As you can see, I've cut down drastically on time just by using numbers that work for ...
Jose Magana's user avatar
7 votes
3 answers
3k views

Efficiency of Project Euler problem 35

The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime. There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, ...
yask's user avatar
  • 245
2 votes
3 answers
8k views

Finding Pythagorean Triple that sums to 1000

I am doing this Project Euler Question #9: A Pythagorean triplet is a set of three natural numbers, \$a < b < c\$, for which, $$a^2 + b^2 = c^2$$ For example, \$3^2 + 4^2 = 9 + 16 = ...
user49487's user avatar
  • 253
5 votes
3 answers
3k views

Efficiency on Project Euler Problem #8

I am doing Project Euler problem #8: The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832. ...
user49487's user avatar
  • 253
11 votes
3 answers
37k views

Sum of Squares/Square of Sum Difference

I am doing Project Euler problem #6. This is the question it asks: The sum of the squares of the first ten natural numbers is, $$1^2 + 2^2 + \ldots + 10^2 = 385$$ The square of the sum of ...
user49487's user avatar
  • 253
3 votes
2 answers
1k views

Efficiency of Project Euler 28 - number spiral diagonals

I have written a solution for Problem 28. Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows: $$\begin{array}{rrrrr} \color{red}{...
yask's user avatar
  • 245
7 votes
3 answers
19k views

Codility Frog Jump solutions [closed]

Problem details from Codility: A small frog wants to get to the other side of the road. The frog is currently located at position X and wants to get to a position greater than or equal to Y. The ...
Jay's user avatar
  • 271
2 votes
1 answer
149 views

Painting Fences - optimize for faster performance

I am attempting this problem at Codeforces. I'm stuck as it gives a time limit exceeded error for large inputs though the logic I followed is similar to that of the editorial. I'd be grateful for any ...
dgun's user avatar
  • 215
7 votes
6 answers
5k views

Improving efficiency for two sum

I am trying to solve this problem: Given an array of integers, find two numbers such that they add up to a specific target number. and this is my strategy: For each ...
Boyu Fang's user avatar
  • 223
1 vote
2 answers
1k views

Application of higher-order function in Python

If \$f\$ is a numerical function and \$n\$ is a positive integer, then we can form the \$n\$th repeated application of \$f\$, which is defined to be the function whose value at \$x\$ is \$f(f(......
overexchange's user avatar
  • 3,351
3 votes
1 answer
291 views

Speeding up Codechef FROGV

This is my solution to the FROGV problem on Codechef: ...
user3813920's user avatar
-2 votes
1 answer
9k views

hailstone sequence using recursion in python [closed]

Douglas Hofstadter's Pulitzer-prize-winning book, Gödel, Escher, Bach, poses the following mathematical puzzle: Pick a positive integer n as the start. If n is even, divide it by 2. If n is ...
overexchange's user avatar
  • 3,351
5 votes
2 answers
2k views

Minimum number of letters removed, to make a string Peragram

Here is the link to the problem Peragrams. Peragrams: If a word is an anagram of at least one palindrome, we call it a Peragram. Problem: Given a string, find the minimum number of letters ...
Kunal B.'s user avatar
  • 260
3 votes
1 answer
514 views

Typeahead Talent Buddy

Problem is Talent Buddy. Your task is to write a function that prints to the standard output (stdout) for each query the user name that matches the query if there are multiple user names ...
sundar nataraj's user avatar
5 votes
3 answers
729 views

Tweets per second

This challenge is from Talent Buddy: Tweets per second Japan Castle in the Sky airing broke a Twitter record on August 3, 2013. At one point during the classic anime movie showing, people ...
sundar nataraj's user avatar
6 votes
2 answers
896 views

Typeahead autocomplete functionality challenge

I'm working on a Talent Buddy challenge . In this challenge you have to design the autocomplete functionality of Twitter. You are given a list of queries and possible usernames. You have to return the ...
Olivier_s_j's user avatar
16 votes
6 answers
4k views

Sherlock and The Beast

This is my solution to this question from Hackerrank. Given N (<= 100000), find the largest N-digit number such that: The number has only 3 and 5 as its digits. Number of times 3 ...
sundar nataraj's user avatar
7 votes
5 answers
2k views

Improving efficiency of Project Euler 185 (16-place Mastermind)

This a solution for Project Euler Problem 185. It works fine for the example but slow for the problem statement. How can I improve its speed and efficiency? ...
sundar nataraj's user avatar
4 votes
2 answers
375 views

Efficient use of regular expression and string manipulation

The following is my solution to Java vs C++. I think the way I have used the re library is inefficient, and possible erroneous as I am getting tle. ...
user43115's user avatar
  • 329
4 votes
3 answers
1k views

Speeding up Project Euler 43 - sub-string divisibility

The number, 1406357289, is a 0 to 9 pandigital number because it is made up of each of the digits 0 to 9 in some order, but it also has a rather interesting sub-string divisibility property. ...
Joshua's user avatar
  • 857
7 votes
7 answers
9k views

Python address index +1 with list comprehension

Task from CodingBat: Return the sum of the numbers in the array, returning 0 for an empty array. Except the number 13 is very unlucky, so it does not count and numbers that come immediately after a ...
mcgyver5's user avatar
  • 638
2 votes
1 answer
310 views

Project Euler 40: Champernownes's Constant

I just finished Project Euler 40 with a brute force method. As usual, any optimizations would be helpful. (I feel like I'm getting better at this scripting thing) ...
Joshua's user avatar
  • 857
3 votes
1 answer
983 views

Project Euler 39: Integer right triangles

I just finished Project Euler 39: If p is the perimeter of a right angle triangle with integral length sides, {a, b, c} … For which value of p ≤ 1000, is the number of solutions maximised? I'm ...
Joshua's user avatar
  • 857
5 votes
3 answers
904 views

Project Euler 38: Pandigital Multiples

I just solved Project Euler 38 and was wondering if you guys could provide some suggestions on how to speed it up. I've tried adding extra conditions but they increase the time. Any ideas on how to ...
Joshua's user avatar
  • 857
3 votes
1 answer
740 views

Truncatable Primes -- Project Euler 37?

I just finished Project Euler 37 after a bit of debugging and can't figure out how to make it faster. Whenever I add extra tests that I want to speed the program up, it ends up just slowing it down. ...
Joshua's user avatar
  • 857
1 vote
3 answers
607 views

Optimizing Project Euler 36 - double-base palindromes

This one was quick and simple. Any optimizations? ...
Joshua's user avatar
  • 857
2 votes
1 answer
161 views

Project Euler 35 in Python

I'm back with a Python solution for Project Euler 35. Any help would be appreciated; I generate the numbers by observing that all circular primes can only have digits 1, 3, 7, and 9. Then I use the ...
Joshua's user avatar
  • 857
6 votes
2 answers
4k views

Project Euler 34 - digit factorials

145 is a curious number, as \$1! + 4! + 5! = 1 + 24 + 120 = 145\$. Find the sum of all numbers which are equal to the sum of the factorial of their digits. Note: as \$1! = 1\$ and \$2! = 2\...
Joshua's user avatar
  • 857
8 votes
1 answer
1k views

Project Euler Problem 33 - digit canceling fractions

Problem: The fraction \$(\dfrac{49}{98})\$ is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that \$(\dfrac{49}{98}) = (\dfrac{4}{8}...
Joshua's user avatar
  • 857
4 votes
2 answers
1k views

How to make Project Euler 32 in Python faster?

We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once; for example, the 5-digit number, 15234, is 1 through 5 pandigital. The product 7254 is ...
Joshua's user avatar
  • 857
1 vote
2 answers
1k views

Any way to optimize this already fast Python solution to Project Euler 31 (coin sums)?

This is a Python solution for all general cases. Any suggestions at all would be appreciated; in my opinion it's already quite good! Here's a link to the problem. ...
Joshua's user avatar
  • 857