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

learn more… | top users | synonyms (2)

3
votes
5answers
37 views

Project Euler #5 optimization

I was trying to solve problem 5 of Project Euler, and this was I needed to do: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. ...
5
votes
2answers
69 views

Quadratic Primes - Project Euler 27

Project Euler Problem 27 Euler discovered the remarkable quadratic formula: \$n^2 + n + 41\$ It turns out that the formula will produce \$40\$ primes for the consecutive values \$n = ...
6
votes
2answers
99 views

Generating 'Decent' numbers

While solving a problem from HackerRank, though it's aneasy one, I wrote this big program. Not sure if recursion is applicable and hold good but to me it looked like it isn't. However when I run the ...
1
vote
2answers
40 views

“The Love Letter Mystery” - storing and comparison of strings

The problem goes like this. Change the strings provided by user to form palindromes. To do this, 2 rules are: (a) Reduce the value of a letter, e.g. Change 'd' to 'c', but cannot change ...
4
votes
1answer
116 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 ...
2
votes
2answers
62 views

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

Working on some python koans and got one which states: ...
9
votes
1answer
673 views

Memory-Test for Soldiers

I am solving the following problem on code chef: \$N\$ Soldiers are lined up for a memory test. They are numbered from 0 to N-1 from left to right. In the test, there are \$M\$ rounds. In each ...
0
votes
1answer
31 views

Finding Largest Integer Palindrome within a Set

I've "solved" Project Euler Question 4 and I was wondering if I could make my answer more efficient (I'm using Project Euler to help me learn Haskell). The problem reads: Find the largest ...
2
votes
2answers
222 views

Project Euler #3 Efficiency

I'd like to reduce the complexity of my code Problem : The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of a given number N? Solution : ...
6
votes
2answers
242 views

Project Euler #2 Efficiency

I'd like to reduce the complexity of my code. 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 terms will ...
4
votes
1answer
42 views

Effeciency 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 of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. Could ...
4
votes
2answers
224 views

How do I decrease compile time and execution time of following program?

How can I decrease the running time and compile time of the following code? Given three integers A, B and ...
8
votes
5answers
682 views

Project Euler #1 efficiency

I've started solving Project Euler problems. Is the code completely optimized? Question: 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 ...
3
votes
5answers
196 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, ...
5
votes
4answers
528 views

Arranging words in sentences alphabetically

For an online contest whose problem is here, I wrote some code. In this problem the input will consist of a number of lines of English text consisting of the letters of the English alphabet, the ...
11
votes
2answers
162 views

CodeEval's SkyScrapers challenge

This is a solution to CodeEval's SkyScrapers challenge. You are given a list of triples \$(l, h, r)\$. Each triple represents an axis-aligned rectangle, with top-left corner at \$(l, h)\$ and ...
2
votes
2answers
112 views

Max path sum algorithm

This is for Project Euler question 18 and I'm looking for feedback on whether my algorithm is incorrect or whether I've just implemented it wrong (which I don't think is the case after some testing). ...
11
votes
5answers
871 views

Finding longest word in a string

I was working on a problem from Coderbyte. The challenge was to write a function that takes in a string and returns the longest word in the string. If two words are the same size then it asks to ...
3
votes
2answers
54 views

Project Euler Problem 57 in Haskell

I'm very new to Haskell, and I would like some feedback on my coding style. Is there anything here that could be made more elegant or concise? This is my solution to Project Euler Problem 57. It ...
4
votes
1answer
419 views

Maximizing XOR HackerRank challenge

I know that there are combinatoric libraries for this kind of thing. However, with me being new to C# and coding in general I found that I couldn't understand the code well enough to implement it in ...
4
votes
1answer
82 views

CodeEval Sequence Transformation

I've been working on this challenge for a week: There are two sequences. The first sequence consists of digits "0" and "1", the second one consists of letters "A" and "B". The challenge is to ...
2
votes
3answers
98 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): ...
1
vote
2answers
110 views

Project Euler #3 solution

I'm trying to solve Project Euler problem #3, which asks: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? Can you please review ...
4
votes
2answers
234 views

Project Euler #48 in C++

This question is similar to Project Euler #48 but constraints are different: $$N < 2000000$$ Just in case the link is unavailable, here is the problem statement: We've to print $$\left( ...
5
votes
3answers
348 views

Project Euler #8 - “largest product in a series”

This code works when compiled on gcc 4.8.2. I would appreciate any comments on my style and the readability of my code, and any improvements that I could make to make the code more readable and/or ...
4
votes
2answers
145 views

“Utopian Tree” challenge optimization

Problem statement The Utopian tree goes through 2 cycles of growth every year. The first growth cycle occurs during the monsoon, when it doubles in height. The second growth cycle occurs during the ...
2
votes
2answers
81 views

Random walk terrain generator

I was messing around with Javascript in Khanacademy the other day and this "monstrosity" was born. It's a terrain generator that uses a simplified version of the random walk method. ...
1
vote
1answer
71 views

“Cool Guys” CodeChef challenge

I was trying to solve a question on CodeChef. My code works perfectly fine in my IDE (Visual Studio here) but when I submit my code at CodeChef, it says "Time Limit Exceeded". Here is my code: What ...
6
votes
1answer
51 views

Project Euler #11“numbers in a grid” in Rust

To learn more about Rust, I implemented Project Euler #11 "Numbers in a grid". Contrary to some people, I prefer not having the actual data grid in my code, so I put it in a file, which I read in the ...
7
votes
2answers
150 views

Two Fragments in Landscape Mode Challenge

I did the following code challenge for a job interview. They apparently didn't care for my solution and I'm not sure why. What could I have done better? Here is the challenge: Create a small ...
14
votes
3answers
938 views

Project Euler #1 in PHP

The code below works & as far as I can tell the result is correct. Would you please review and let me know what I could have done better? I tried to use variables as much as possible, that way it ...
0
votes
0answers
9 views

Matrix Game SPOJ [migrated]

I solved this problem on spoj: Two players A and B play the following game. First, a matrix M of size N*M is chosen, and filled with non-zero numbers. Player A starts the game and ...
11
votes
1answer
140 views

Utopian tree life cycles

Simple algorithm based HackerRank challenge. The Utopian tree goes through 2 cycles of growth every year. The first growth cycle of the tree occurs during the monsoon, when it doubles in ...
0
votes
1answer
73 views

Full counting sort on HackerRank [closed]

This is the full counting sort (CountingSort4) challenge on HackerRank. I've gotten it to the point where it passes every test case except the final one. I believe my algorithm is timing out due to ...
4
votes
2answers
74 views

“Vaishnav and Pizzas” challenge

I am trying to solve the below mentioned problem from HackerEarth. Although the results are fine, the code takes extraordinarily long time to run execute. I am pretty sure the problem is because of ...
5
votes
2answers
104 views

Project Euler #17

Project Euler presents problem 17: If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total. If all the ...
2
votes
1answer
70 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 ...
3
votes
1answer
51 views

Finding palindromic numbers most efficiently

After reading why is my project euler #4 program not working?, I was contemplating the most efficient way to approach this (finding the target palindrome as early as possible). Is this snippet about ...
5
votes
1answer
81 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 ...
4
votes
3answers
240 views

Solution to Hackerrank challenge “Sherlock and Queries”

First, here is the full challenge description: 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 \$C_1, C_2, ..., ...
2
votes
1answer
154 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: ...
2
votes
2answers
132 views

“Nice Angles” - Code Eval challenge

Out of fun, I solved "Nice Angles" challenge on CodeEval in C# 4.0: CHALLENGE DESCRIPTION: Write a program that outputs the value of angle, reducing its fractional part to minutes and ...
3
votes
2answers
78 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 ...
5
votes
1answer
99 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 ...
2
votes
3answers
125 views

CodeChef Matrix Rotation

I am new to C# and have tried to solve a problem statement from CodeChef: Problem statement You are given an array A of N integers. You are to fulfill M queries. Each query has one of the ...
2
votes
1answer
83 views

Decreasing the runtime of this non-abundant sums solution

I have written a solution to problem 23 of Project Euler, and after doing some testing and editing, I've managed to get the run time down from 1.7443 seconds to 1.56616 seconds. The problem is ...
4
votes
1answer
110 views
3
votes
1answer
116 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 ...
1
vote
3answers
796 views

“Fun with Rotation” - Codechef September Challenge

Can you please help me in reducing the complexity of the below code? The problem statement can be found here. You are given an array A of N integers. You are to fulfill M queries. Each query ...
8
votes
1answer
100 views

Project Euler #2 - Sum of even Fibonacci numbers to 4,000,000

This particular problem has already been posted here before, but the community is ok with me to post it again, so I can have feedback on my own implementation. I tried to keep things simple, with ...