Programming challenges can be found on www.hackerrank.com, coderbytes.com, projecteuler.net, osix.net, www.reddit.com/r/dailyprogrammer, enigmagroup.org‎, codility.com etc. etc. These challenges request a good insight into combinations, permutations, prime generation, lookup tables, matching, ...

learn more… | top users | synonyms (1)

12
votes
5answers
396 views

Tape Equilibrium

I picked the first test (Tape Equilibrium) from Codility here. Question: A non-empty zero-indexed array A consisting of N integers is given. Array A represents numbers on a tape. Any integer ...
3
votes
6answers
267 views

Speeding up my implementation of Project Euler #3

Project Euler problem 3 asks for the largest prime factor of 600851475143. I have gone from 96 lines to 17 lines taking hits at this one. This is what I am left with after all of that effort: ...
3
votes
1answer
41 views

Lychrel calculator (Project Euler 55)

If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindromes so quickly. For example, 349 + 943 = 1292, 1292 + 2921 = 4213 4213 + 3124 = 7337 ...
2
votes
3answers
74 views

Login script that checks two users and their corresponding passwords

Please let me know what you think. Is the code well written? Am I using best practices (like when I chose === over ==)? Is my script too verbose? Note: I'm only asking because the tutorial I'm ...
5
votes
2answers
325 views

Sherlock and The Beast

I have recently written the program for the Sherlock and The Beast' HackerRank challenge. That's working fine, but the problem is that it takes too much time if a big number is given as a input. I ...
3
votes
5answers
495 views

Traversing binary tree

I was given the following question to answer as a part of the hiring test using Codility. I would appreciate if any of you can give me the right answer for this problem. Here is the problem ...
4
votes
2answers
88 views

Project Euler “Largest product in a grid” (#11) in Java 8

I have come up with a Java 8 solution for the following problem: In the 20×20 grid below, four numbers along a diagonal line have been marked in red (bold here). 08 02 22 97 38 15 00 40 00 75 ...
10
votes
3answers
87 views

Project Euler “Largest prime factor” (#3) in Java

The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? I wrote the following code with help of some Java 8, I'll explain the equivalent ...
11
votes
1answer
184 views

Project Euler “Even Fibonacci numbers” in Java 8

I'm looking for general advice on my code on the following problem: Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 ...
5
votes
1answer
95 views

Project Euler #15 in haskell

I've solved Project Euler #15 in Haskell, but I feel like there might be a better way to express my solution that I'm not seeing. I start out defining my types: import qualified Data.Map.Strict as ...
8
votes
3answers
181 views

Checking brackets nesting in a string

I took a training challenge on Codility that checks for the proper nesting of brackets in a string. The brackets to be checked are {,},(,),[,]. I have written the following Java program which passes ...
5
votes
1answer
39 views

Project Euler #41 - pandigital prime

I've written a solution to Euler 41: 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, 2143 is a 4-digit pandigital and is ...
3
votes
2answers
518 views

What is the 10001st prime number?

Project Euler problem 7 says: By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10001st prime number? I believe that my code is ...
2
votes
2answers
57 views

Optimizing Python code for Project Euler #5 (LCM of all numbers from 1 to 20)

This is my solution for the 5th problem of Project Euler, which asks for the least common multiples of the numbers from 1 to 20 (inclusive). Is there any way to improve the while loop conditional ...
5
votes
1answer
128 views

Optimizing my code for Project Euler Problem #23 (Non-abundant sums)

Project Euler Problem 23 asks: A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be ...
6
votes
2answers
109 views

Helper function to solve Project Euler question 26

Project Euler problem 26 asks us to: Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part. I wrote this function in Python to find the ...
3
votes
2answers
91 views

More efficient solution for Project Euler #2 (sum of Fibonacci numbers under 4 million)

I would like to get some feedback on my code. I am starting to program after doing a few online Python courses. Would you be able to help me by following my track of thinking and then pinpointing ...
3
votes
2answers
178 views

Project Euler #12 - highly divisible triangular number

The following is a solution to Project Euler problem number 12: which is to find the first triangular number with more than 500 divisors. The code takes far too long to complete (over 10 minutes). Is ...
6
votes
3answers
130 views

Coderbyte SimpleSymbols challenge in Javascript

I am working on a CoderByte problem in JavaScript. I have solved the problem below. Although I am trying to figure out if there is an easier way to do it? I am guessing RegEx will come up, although I ...
4
votes
1answer
158 views

Project Euler Problem 12 - Highly Divisible Triangular Number - Python Solution Optimization

Project Euler Problem 12 asks (paraphrased): Considering triangular numbers Tn = 1 + 2 + 3 + … + n, what is the first Tn with over 500 divisors? (For example, T7 = 28 has six divisors: 1, 2, 4, ...
4
votes
1answer
48 views

Project Euler Problem 1 - Multiples of 3 and 5

I wrote this function for Project Euler Problem 1. prob001 :: (Integral a) => [a] -> [a] -> a prob001 a b = sum [x | x <- a, product ( map (x `rem`) b ) == 0] The use is like this ...
3
votes
3answers
264 views

Smallest prime factor of a large number (using BigInteger)

I'm working on a Project Euler problem and am trying to get the smallest prime factor of a BigInteger: private static BigInteger smallestPrimeFactor( BigInteger n ){ for( BigInteger i = new ...
5
votes
2answers
156 views

Performance of modular square root

Here's Project Euler problem 451: Consider the number 15. There are eight positive numbers less than 15 which are coprime to 15: 1, 2, 4, 7, 8, 11, 13, 14. The modular inverses of these ...
7
votes
2answers
301 views

Checking for circular primes - Project Euler Problem 35

I have been trying to solve Project Euler problem number 35. The problem is to find: How many circular primes are there below one million? A circular prime is a prime where all the rotations of ...
2
votes
1answer
122 views

Project Euler #82 - path sum: three ways

Project Euler problem 82 asks: Here's my solution: def main(): matrix = [ [131, 673, 234, 103, 18], [201, 96, 342, 965, 150], [630, 803, 746, 422, 111], ...
3
votes
1answer
118 views

Function to find sum of digits in the number a^b where a, b are positive integers

I was solving Project Euler problem 16, which asks to find the sum of digits of the number 2 raised to the power 1000. Using Python, it can be solved in one line of code: sum(map(int, ...
11
votes
4answers
317 views

Suggestions for improvement on Project Euler #7

Here is a solution for Project Euler Problem #7. By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10,001st prime number? I've ...
2
votes
3answers
141 views

Project Euler #12 in C++ - highly divisible triangular number

Project Euler Problem 12 asks (paraphrased): The nth triangular number Tn = 1 + 2 + … + n. T7 = 28 has 6 divisors (1, 2, 4, 7, 14, 28). What is the first Tn to have over 500 divisors? After ...
4
votes
4answers
264 views

Alternative to a large switch

Wanted to consolidate solutions to disparate problems into a single program. I am worried that there is a interface, command pattern, or dictionary solution to what will become a massive switch ...
6
votes
2answers
128 views

Largest product in a grid

Project Euler problem 11 says: In the 20×20 grid below, four numbers along a diagonal line have been marked in bold. [red in the original] 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 ...
5
votes
3answers
425 views

Summation of primes takes forever

Project Euler Problem 10 asks: "What is the sum of all prime numbers below 2 million?" How do I speed up my code? It's taking forever and I have never gotten the answer. However, I am sure that my ...
6
votes
4answers
229 views

Finding the Pythagorean triplet that sums to 1000

Project Euler problem 9 says: A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a2 + b2 = c2 For example, 32 + 42 = 9 + 16 = 25 = 52. There ...
0
votes
1answer
25 views

Caml light and finding the prime factors

I wrote the following Caml light code to find prime factors of a number (part of an early Project Euler question). Largest prime factor The prime factors of 13195 are 5, 7, 13 and 29. ...
1
vote
1answer
120 views

Euler problem c++ / std::library usage

Euler problems (projecteuler.net) often invites to quick and dirty solutions. While hurrying through Problem 32 I found myself in want of the std:: toolkit. Not sure what it is though. The problem ...
3
votes
3answers
199 views

How Pythonic is my Project Euler #5? (LCM of [1, 2, …, 20])

I have implemented a solution to Project Euler problem 5: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive ...
3
votes
3answers
409 views

Project Euler Question #2: Sum of even Fibonacci numbers under 4 million

The question is: Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, ...
4
votes
2answers
468 views

Determining possible triangle from lengths of line segments [closed]

This Codility challenge is to take an array of integers representing lengths of line segments, and determine whether or not it is possible to choose three distinct segments to form a triangle. (The ...
2
votes
2answers
1k views

Fish Food Chain O(N)

I understand that if you don't know the trick, it's not easy create a solution with a complexity of O(N). However, I would like to ask you how to solve this tricky question: You are given two ...
1
vote
2answers
176 views

Project Euler: Problem 13 - Large Sum

I've written some code to solve this problem: Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. My solution functions correctly, but I'm having some trouble ...
1
vote
1answer
116 views

Better way of calculating Project Euler #2 (Fibonacci sequence)

Even Fibonacci numbers Problem 2 Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, ...
2
votes
3answers
107 views

Does this code violate the Single Responsibility Principle?

This is my solution to Project Euler problem 2: By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. The class ...
3
votes
2answers
159 views

Roman numeral converter in Ruby

For a Project Euler problem, I made a Ruby roman numeral converter: def romanize(num) digits = { 1000 => "M", 900 => "CM", 500 => "D", 400 => "CD", 100 => "C", ...
1
vote
1answer
351 views

Testing if numbers in the array can be added up to equal the largest number in the array

Okay, here's a challenge at Coderbyte that completely stumped me. I came up with a solution, but I know it is flawed. Have the function ArrayAdditionI(arr) take the array of numbers stored in arr ...
1
vote
3answers
127 views

Testing distance between characters in a string

Here is another challenge from Coderbyte. I found this one challenging, although not quite as much as the previous two I've posted. Based on the feedback I received on my earlier posts, I structured ...
1
vote
2answers
158 views

Trying to improve my javascript code in this simple challenge from coderbyte

Here is a slightly modified challenge from Coderbyte: Determine if a given string is an acceptable. The str parameter will be composed of + and = symbols with several letters between them (ie. ...
2
votes
3answers
531 views

Project Euler Problem 7: Find 10001st prime number

I was able to complete the problem, but I would like to improve my code and make it more idiomatic. Here is the challenge description: Problem 7 - 10001st prime By listing the first six ...
1
vote
1answer
220 views

Pythagorean number decomposition

I have a pretty interesting problem that I'm trying to solve, and I am kind of stuck. I want to count the triplets of distinct combinations a, b, c, that are smaller than LIMIThave the following ...
1
vote
3answers
103 views

Optimize calculation of distances between pairs of points

I was trying to solve a challenge. The execution time should not exceed 5s, but for some value my code took longer. I want to know if I can optimize my code for performance. public class Solution { ...
2
votes
2answers
816 views

Project Euler #4 - Largest Palindrome Product

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two ...
4
votes
2answers
309 views

Project Euler problem 92 - square digit chains

Link to problem. A number chain is created by continuously adding the square of the digits in a number to form a new number until it has been seen before. For example, 44 -> 32 -> 13 ...