Programming challenges are off-site challenges meant to offer programmers educational experiences while testing their abilities.

learn more… | top users | synonyms (2)

1
vote
1answer
29 views

Naive primality test and summation

I am starting to learn Haskell, so I coded a naive solution to the primality test and summation of primes (Project Euler Problem 10: sum of all primes under 2 million) . As I have an imperative ...
2
votes
2answers
46 views

Given a digit sequence, print the possible decodings of the given digit sequence

Examples: 12 gives: 'AB' and 'L' and 123 gives 'ABC', 'LC' and 'AW' Here is my attempt: ...
7
votes
3answers
64 views

Project Euler #8 - Largest product in a sequence

I've just finished Project Euler Problem 8, which ask for the greatest product of any sequence of 13 consecutive digits in a given string. I wonder if there's something that could be improved. ...
8
votes
2answers
73 views

Sending duplicate to heaven with Java 8

Follow up to Duplicate like a weapon, arrays like heaven. @rolfl suggested in chat that I try to complete this challenge again in a Java 8 friendly way. I took the opportunity to also employ the ...
4
votes
1answer
62 views

Project Euler problem 12 in Ruby

I've been trying to optimize this while making it readable. Thoughts? The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 ...
2
votes
1answer
30 views

Project Euler #10 in Cython

I'm trying to teach myself some Cython. To do so, I use Project Euler #10: The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. 2 Find the sum of all the primes below two million. My Cython ...
15
votes
3answers
1k views

Duplicate like a weapon, arrays like heaven

Challenge: Find the duplicated entry. Specifications: Your program should accept as its first argument a path to a filename. Each line in this file is one test case. Each line ...
2
votes
2answers
42 views

Premium palindromic primes

Challenge: Write a program which determines the largest prime palindrome less than 1000. The answer is 929, and my program correctly finds and prints this, but actually ended up being more complex ...
2
votes
1answer
97 views

“Team formation” challenge

I'm trying to solve this problem but am getting a timeout. Can someone help me to improve? ...
1
vote
2answers
103 views

100 doors exercise code using C#

Can you please check my code if it is correct for the problem 100 doors? This is the problem: You have 100 doors in a row that are all initially closed. You make 100 passes by the doors. ...
7
votes
1answer
493 views

An Army of Ones

I've been practicing using recursion lately and thought this was a case where it would prove really useful, is this good use or is there some superior non-recursive way to go about it? Challenge: ...
5
votes
4answers
377 views

Digital root recursive function

Haven't any experience writing recursive functions.(Generally tend to avoid them - not sure if that's a negative). What do you think about the following? This is also my first time using JUnit, I'd ...
11
votes
2answers
262 views

LOL'ing-Up Project Euler One

It's been a while since I last wrote some lolcode, so I felt like tackling Project Euler #1. If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum ...
0
votes
1answer
56 views

Join 2 arrays together

There are 2 arrays. One that consists of Categories and one of Products. Each product pertains to its specific category. I want ...
8
votes
1answer
119 views

The finest integers are palindromes

Challenge: Reverse the digits of a number and add it to the original until the number is a palindrome Specifications: Your program should accept as its first argument a path to a filename. ...
3
votes
2answers
76 views

Project Euler Retreat

Now I am doing Project Euler number 1: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all ...
3
votes
2answers
173 views

Hacker Rank - Lonely Integer

This is the problem statement for Lonely Integer. There are N integers in an array A. All but one integer occur in pairs. Your task is to find out the number that occurs only once. Input Format ...
4
votes
1answer
49 views

Multiplying Lists

Challenge: Given 2 lists of positive integers. Write a program which multiplies corresponding elements in these lists Specifications: Your program should accept as its first argument a ...
4
votes
4answers
123 views

Finding Lottery odds - Topcoder #268

I have implemented the question #268 from Topcoder. The question is that there are 4 conditions for a lottery ticket: CHOICES - numbers available (10 ≤ CHOICES ≤ 100) BLANKS - number of numbers that ...
6
votes
1answer
96 views

HackerRank - Insertion Sort - Part 2

This is the problem statement for Insertion Sort - Part 2. In Insertion Sort Part 1, you sorted one element into an array. Using the same approach repeatedly, can you sort an entire unsorted array? ...
1
vote
2answers
32 views

Solution to Project Euler #1 - multiples of 3 and 5

I have been programming for about ~2 years, and mostly wrote OOP and structural code. Recently, I have decided to pick up a functional programming language, and Haskell being too alien for me, looked ...
5
votes
1answer
60 views

Project Euler #10 in Java

Project Euler #10: The sum of the primes below 10 is \$2 + 3 + 5 + 7 = 17\$. Find the sum of all the primes below two million. My solution: ...
3
votes
3answers
93 views

Project Euler 35: Circular primes below 1 million

I'm doing another Project Euler problem, number 35, and I need help improving my code speed: The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, ...
3
votes
2answers
55 views

Project Euler #7 in Java

Project Euler #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? Here is my solution: ...
4
votes
2answers
53 views

Timus Online Judge Problem 1001 - “Reverse Root”

The problem statement can be found here. Description (short): Input The input stream contains a set of integer numbers \$A_i\$ (\$0 \le A_i \le 10^{18}\$). The numbers are separated by any number ...
4
votes
3answers
80 views

Project Euler #6 in Java

Project Euler #6: The sum of the squares of the first ten natural numbers is, \$1^2+2^2+ ... + 10^2 = 385\$ The square of the sum of the first ten natural numbers is, \$(1+2+ ... + ...
3
votes
4answers
406 views

Project Euler #5 in Java

Project Euler #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 number that is evenly divisible by ...
4
votes
7answers
2k views

Project Euler #10 — Summation of primes takes forever

I have resolved the Problem presented in Project Euler #10: The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. But this code takes too ...
6
votes
1answer
121 views

Cash Register Challenge

Challenge: Design a cash register program Specifications: Your register currently has the following bills/coins within it: 'PENNY': .01, 'NICKEL': .05, 'DIME': .10, 'QUARTER': .25, ...
1
vote
1answer
63 views

Time limit exceeded for Sherlock and Queries Hackerrank challenge

Here is my C solution for Sherlock and Queries @ Hackerrank. Watson gives to Sherlock an array: \$A_1, A_2, ..., A_N\$. He also gives to Sherlock two other arrays: \$B_1, B_2, ..., B_M\$ and ...
3
votes
2answers
351 views

Project Euler #14 solution takes quite a long time

Can anybody give me suggestions for making it faster? (Project Euler #14) ...
3
votes
1answer
73 views

“Sharing CANDY” on SPOJ

How can I improve it and its running time efficiency? Problem (SPOJ/CANDY) Jennifer is a teacher in the first year of a primary school. She has gone for a trip with her class today. She has ...
3
votes
1answer
58 views

FizzBuzz from a file

This was found on CodeEval. Challenge: Write a program that prints out the final series of numbers where those divisible by X, Y and both are replaced by “F” for fizz, “B” for buzz and “FB” for fizz ...
2
votes
1answer
64 views

Accessing list elements when counting the number of rectilinear paths

I am trying to solve the RIVALS problem on SPOJ: Starting from (0, 0), how many paths are there to reach point (X, Y), only taking one-unit steps moving to the right or up? Constraints: 0 ≤ X ≤ 106, ...
3
votes
4answers
166 views

Java vs C++ (JAVAC)

Here's the problem for Java vs C++ (JAVAC): Java and C++ use different naming conventions. In Java a multiword identifier is constructed in the following manner: The first word is written ...
2
votes
2answers
69 views

Four fours to get any number

I decided to solve a problem from Code Golf called the four fours. Problem description: The Four fours puzzle is a popular recreational mathematical puzzle that involves using exactly four 4s ...
5
votes
2answers
109 views

Project Euler #7: 10001st prime

This is my implementation of Project Euler #7. Have I overdone it again? Is there anything else I should or should not do? It runs in 9 milliseconds on my computer. What is the 10001st prime ...
5
votes
2answers
72 views

Project Euler Attack #2

This is my implementation of Project Euler #2 in C#. It takes 0 milliseconds to run, and I believe it is correct - I have seen nothing to indicate otherwise! By considering the terms in the ...
4
votes
1answer
58 views

Converting to Roman Numeral with Recursive Algorithm

Summary I'm getting ready to dive back into a "more proper" project, so I wanted to take a moment to get my TDD hat on before doing so. I decided to tackle this Roman Numeral Kata for practice. The ...
8
votes
3answers
352 views

Project Euler #2 (Fibonacci Sequence)

Challenge: 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, 55, 89. Consider a ...
1
vote
4answers
118 views

Project Euler #1 - JavaScript

I'm new to JavaScript, and decided to learn the language by running through as many of the Project Euler problems as I have time to do. I just finished the first one, and am looking for some feedback, ...
1
vote
1answer
99 views

Summation of Arithmetic Progression Modulo Series

Here is the link to the problem: Aladin on Kattis.com Problem Aladin was walking down the path one day when he found the strangest thing: N empty boxes right next to a weird alien machine. ...
5
votes
2answers
97 views

Project Euler #5 (LCM 1 - 20) Follow up

I'm actually spending time on it, unlike the first time and going through, understanding and implementing the several suggestions I've landed on two different approaches. Approach 1: Employing Java 8 ...
3
votes
0answers
55 views

Evaluating Fibonacci-sequence-based recurrence relation (SPOJ Flibonakki)

I have a function fib2 which returning two values as Tuple but I want to print the product of tuples returned by function fib2. I am new to Haskell so please ...
5
votes
4answers
556 views

Project Euler #5 (LCM of 1-20)

Challenge: 2520 is the smallest number divisible by 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by 1-20? Solution: ...
5
votes
1answer
96 views

Optimizing a dynamic programming solution for “Oil Well”

I'm trying to solve the Oil Well problem on Hackerrank using dynamic programming and it works. However, it times out for some of the test cases. I wanted to know how this program can be improved so ...
4
votes
3answers
122 views

Project Euler Problem #10

I've read other solutions about solving the 10th problem for Project Euler (finding the sum of all prime numbers under 2,000,000) but I wanted to try it on my own using the Sieve of Eratosthenes ...
4
votes
1answer
147 views

Project Euler Problem #6 - sum square difference

The sum of the squares of the first ten natural numbers is: \$1^2 + 2^2 + ... + 10^2 = 385\$ The square of the sum of the first ten natural numbers is: \$(1 + 2 + ... + 10)^2 = 55^2 ...
3
votes
1answer
66 views

Project Euler #16 in Swift - Power digit sum

I just finished Project Euler #16 in Swift, and since there is not any version yet on Code Review, I would like to have some comments on what I did to try to improve it. 2^15 = 32768 and the sum ...
1
vote
2answers
48 views

Project Euler #14 in Swift - Longest Collatz sequence

I just finished Project Euler #14 in Swift, and since there is not any version yet on Code Review, I would like to have some comments on what I did to try to improve it. The following iterative ...