Programming challenges are off-site challenges meant to offer programmers educational experiences while testing their abilities.
5
votes
1answer
48 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
137 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
267 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 ...
0
votes
2answers
241 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 ...
4
votes
0answers
56 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 ...
11
votes
2answers
150 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
95 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
63 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
49 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
48 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
300 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
54 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
181 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
121 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
30 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
47 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
56 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
378 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
59 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
43 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
112 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
45 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
58 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
115 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
66 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
21 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
776 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
99 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
330 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
48 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
86 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
39 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
91 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
37 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
72 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
138 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
120 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
495 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
417 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
267 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 ...
10
votes
2answers
170 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
79 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
430 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
59 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
136 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 ...