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
69 views

Project Euler 25 - 1000-digit Fibonacci Number

I have recently completed problem 25 from the project Euler site. The Fibonacci sequence is defined by the recurrence relation: Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1. Hence the first 12 ...
5
votes
2answers
445 views

Project Euler 29 - Distinct Powers

I have just completed problem 29 from the Project Euler website: Consider all integer combinations of \$a^b\$ for \$2 \le a \le 5\$ and \$2 \le b \le 5\$: \$2^2=4\$, \$2^3=8\$, \$2^4=16\$, ...
9
votes
1answer
141 views

Series, Powers, and Benches

Project Euler problem 48 The series, \$1^1 + 2^2 + 3^3 + ... + 10^{10} = 10405071317\$. Find the last ten digits of the series, \$1^1 + 2^2 + 3^3 + ... + 1000^{1000}\$. I made two different ...
9
votes
1answer
112 views

The answer to life, the universe, and Project Euler

I've never did a real Project Euler in my life, so I figured it was about to do one. And what better Project Euler to start with than Problem 42? Project description from Project Euler: By ...
9
votes
1answer
211 views

Arranging 8 queens on an 8x8 board

Print all the ways of arranging eight queens on an 8x8 board. Rules: Queens should not share the same row, column, of any diagonal. Any comment on my solution? I didn't write unit tests but I ...
8
votes
2answers
200 views

Finding the Mth to last Element

Challenge: Write a program which determines the Mth to last element in a list. Specifications: The first argument is a path to a file. The file contains series of space delimited ...
7
votes
2answers
234 views

Implementing a stack and using it to print alternate elements in reverse

Challenge: Implement a stack interface. Specifications: The interface should have ‘push’ and ‘pop’ functions. Your task is to ‘push’ a series of integers and then ‘pop’ and print every ...
7
votes
2answers
286 views

The only thing better than being unique

is being first and unique. Challenge: Write a program which finds the first non-repeated character in a string. Specifications: The first argument is a path to a file. The file contains ...
1
vote
1answer
288 views

Number of interesting numbers between two given numbers

Please have a look into this problem: Little Dipu is a small kid and like all the other kids, he likes to play, but he plays with numbers (he is extraordinary you know). Nowadays Dipu has some ...
5
votes
1answer
87 views

Project Euler 8 - Redux

Spurred by this question: Project Euler #8 I decided to try to solve it with as clean code as possible. Here is the problem formulation: The four adjacent digits in the 1000-digit number that ...
12
votes
2answers
168 views

Finding a word within a pre-defined set using a search string with wildcards

The other day I was intrigued by this question (originally from here): Write a program that answers YES/NO search queries containing * placeholders. Example: if the data you have is (hazem, ...
5
votes
3answers
98 views

Project Euler #8

I was doing Project Euler #8, which asks: The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832. ...
5
votes
1answer
66 views

“Laser treatment” SPOJ challenge

I am trying to solve this problem on SPOJ Brazil. I'm trying to approach the problem with a series of logical conditions and my code looks like this and it works perfectly. ...
4
votes
2answers
53 views

Moving chips between cells

Challenge: You are given a line of N cells with positive integers written in them. Initially a chip is placed on the leftmost cell. Each time it can be moved in any direction (to the left or to ...
1
vote
4answers
51 views

Finding the second largest element of large input sets

I have a problem where I need to find the second maximum element of the user inputs. It's an online practice problem and I can't figure out why the server responds back with a Non-Zero Exit Code error ...
3
votes
2answers
313 views

Rotating an NxN matrix

I came up with the following solution for rotating an NxN matrix 90 degrees clockwise, to solve this CodeEval challenge: Input The first argument is a file that contains 2D N×N matrices ...
2
votes
1answer
58 views

Simple sum calculator

I'm looking to optimize a simple sum calculator used in Project Euler+. The premise is simple: Find the sum of all the numbers divisible by 3 or 5 under X. At first I did it like so: ...
3
votes
3answers
185 views

Find the index of the element with maximum absolute deviation

I just completed a Codility test. The question presented was pretty simple but I may have over thought it. Question: Find the element which has the highest absolute deviation from the mean. E.g. ...
5
votes
2answers
124 views

Find the Biggest Traveler

This is from one of those online test sites, so the result had to be contained in a single class. The problem was stated as follows: Your java method will be given a 2-D array ...
1
vote
1answer
33 views

Beauty and the Strings in Haskell

I decided to make a solution in Haskell to a problem that I found on another post here at CodeReview (link: The Beauty and the Strings) I would like suggestions on how to improve letterFreqs. I have ...
0
votes
1answer
54 views

Optimizing Diwali Lights problem in C

I was trying to solve the Diwali Lights challenge on HackerRank. Problem Statement On the eve of Diwali, Hari is decorating his house with a serial light bulb set. The serial light bulb set ...
1
vote
3answers
58 views

Counting the frequency of letters in a string slices

While preparing a solution for the CodeChef - magic tricks, an easy question about counting the frequency of given character from the string slice, I came up with the following solution: ...
9
votes
3answers
385 views

The Beauty and the Strings

This originally appeared in Facebook's hacker cup 2013. Solving it was fun, though I find myself looping through similar data quite often. Challenge: Print the maximum beauty of strings. ...
2
votes
1answer
65 views

Time Limit Exceeded for CodeChef Easy problem - STRQ (Chef and Strings)

I was working through a codechef easy problem here. I've got to a solution, but it only passes the Subtask #1. For the other two subtasks, it shows TLE (Time Limit Exceeded - which is 1 second). ...
0
votes
2answers
44 views

Uva Online Judge problem 100, 3n + 1

I am having a tough time submitting this code to UVa Online judge and having it pass. I keep getting the message - Your program used more CPU time than what is allowed for this problem. That means ...
5
votes
1answer
129 views

Minimum number of coins - (dynamic programming solution - topdown approach)

This is a problem from topcoder tutorials Given a list of N coins, their values (V1, V2, ... , VN), and the total sum S. Find the minimum number of coins the sum of which is S (we can use as many ...
2
votes
1answer
47 views

Binary convert to string in Ruby

This was a challenge for reddit #202 Easy /u/learnprogramming ...I wish that someone reviews my code and let me know your opinion about my way of thinking beacause I am a total beginner in Ruby: ...
1
vote
5answers
62 views

CCC Rövarspråket (Pig Latin) translator

I have a challenge: In Sweden, there is a simple child's game similar to Pig Latin called Rövarspråket (Robbers Language). In the CCC version of Rövarspråket, every consonant is replaced by ...
12
votes
1answer
123 views

Project Euler #54 - Poker Streams

This challenge posted by Durron597 intrigued me, and inspired me to answer his question, and also to determine whether a more functional approach was available for poker hand ranking. The problem ...
4
votes
1answer
72 views

Project Euler #54 Solution Follow-up

This is my second solution to Project Euler #54.. You can find the original post here. Brief problem summary: The file, poker.txt, contains one-thousand random hands dealt to two players. Each ...
0
votes
1answer
25 views

Bridge Transport - contest practice

I'm practicing for a contest by doing some of the older problems, and I was wondering if there are more efficient ways of doing this or if I'm not following any coding conventions. Most importantly, I ...
10
votes
2answers
784 views

Project Euler #54 Solution

This is not the latest question in iterative code review of this program. You can find the latest answer here. Here's my solution to Project Euler #54. Click the link for the full project ...
6
votes
3answers
102 views

Sieve of Sundaram for Project Euler 7

This is a sequel to my previous question: Sieve of Sundaram for Project Euler 7: Python implementation slower than C++ and R I am trying to implement the Sieve of Sundaram in various languages to ...
8
votes
3answers
332 views

Two sets came to an intersection

Challenge: Print set intersections. Specifications: Your program should accept as its first argument a path to a filename. Each line in the file is a test case. Each test case contain ...
2
votes
1answer
52 views

HackerEarth Crazy kangaroo challenge

I want to find the lowest hop count from source to destination. The challenge, in summary: The first line contains the number of test cases T, 1 ≤ T ≤ 100000. The next T lines each contains ...
2
votes
2answers
92 views

Project Euler - Smallest multiple

Here's Problem 5 - Smallest multiple 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 ...
1
vote
1answer
40 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
59 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: ...
8
votes
3answers
86 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
3answers
93 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
71 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 ...
3
votes
1answer
38 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
4answers
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 ...
3
votes
2answers
75 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
143 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
125 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
497 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
428 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
270 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
62 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 ...