Questions tagged [programming-challenge]

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

Filter by
Sorted by
Tagged with
5
votes
2answers
1k views

Golang solution to Project Euler #81 (min path through a matrix)

Project Euler problem 81 asks: In the 5 by 5 matrix below, ...
7
votes
3answers
414 views

Keeping Linq's readability (e.g. over goto statements) without sacrificing performance

I'm doing Project Euler problem 5 as a kata, focussing on TDD and code readability. The challenge is: What is the smallest positive number that is evenly divisible by all of the numbers from 1 to ...
3
votes
2answers
3k views

“The Trip” challenge from Programming Challenges [closed]

Here is a problem from the book Programming Challenges by Skiena and Revilla: The Trip A number of students are members of a club that travels annually to exotic locations. Their ...
3
votes
2answers
806 views

Google Code Jam - Alien Language

I've successfully solved the Alien Languages problem for Google Code Jam in Haskell: The algorithm is trivial - turn the patterns into regular expressions and see how many of the known words match ...
2
votes
1answer
3k views

CodeIgniter nav/menu insecurities

I more or less asked the same questions on stackoverflow.com, but maybe this is more for this forum. I have a hard time getting to grips with how to implement a top navigation (common for the whole ...
2
votes
1answer
155 views

Counting the ways to pick increasing sequences from sorted arrays

Preamble I am trying to learn JavaScript by writing code and looking up documentation, one problem at a time. I am already familiar with several "dynamic" languages, so I'm hoping to be productive ...
3
votes
1answer
1k views

Decoding binary string message

I am trying to learn some Java on my own, and I am tackling some "programming challenge" problems to practice the little I have learnt so far. Could anybody constructively critique this beginner's ...
1
vote
2answers
1k views

Array absurdity challenge

This is a CodeEval challenge taken from here: Challenge description: Imagine we have an immutable array of size N which we know to be filled with integers ranging from 0 to N-2, inclusive. ...
6
votes
2answers
3k views

Efficient implementation of a Dynamic Programming challenge

I wrote the following code for a Dynamic Programming problem but the online judge gives me a 'Time Limit Exceeded' error. How can I optimize this code to make it more efficient, especially the part ...
6
votes
2answers
274 views

Solving Project Euler problem #48 in Scala

I'm trying to learn some Scala and decided to try to tackle some Project Euler problems. For problem #48, coming from a Python background, my solution is the following one-liner: ...
5
votes
1answer
424 views

Project Euler #9 in haskell

I am trying to teach myself haskell by means of project Euler i sovled problem #9 by means of this code which is on the brute force side I was wondering if there is a more elegant/haskell/efficient ...
2
votes
2answers
898 views

Python Code Review - Project Euler #12

I just figured out Project Euler problem #12. This the first one I've done in Python, so I'm putting my code out there to hopefully get some constructive criticism. If anyone is interested, would ...
11
votes
1answer
380 views

Help me make my Python code clearer

Here's my solution to Project Euler problem 40. ...
4
votes
2answers
297 views

Devise an algorithm of complexity O(N) finding No of 1's from a 2 dimensional matrix[N][N] containing 1's and 0's

Assume a 2D [n][n] matrix of 1's and 0's. All the 1's in any row should come before 0's. The number of 1's in any row I should be at least the number of 1's row (i+1). Find a method and write a C ...
5
votes
1answer
2k views

Optimizing Code for Project Euler Problem 14

For Project Euler problem 14 I wrote code that runs for longer than a minute to give the answer. After I studied about memoization, I wrote this code which runs for nearly 10 seconds on Cpython and ...
5
votes
2answers
2k views

Finding the largest product of four consecutive numbers in a grid

Project Euler #11 asks to find the largest product of four numbers of a grid, where the four numbers occur consecutive to each other vertically, horizontally, or diagonally. Here is my solution in ...
3
votes
2answers
840 views

A little scheme programming challenge

I am learning scheme to get something new from a programming language and this code below is the solution to Project Euler question 21 but the code runs 10x slower than the listed Python code when I ...
3
votes
1answer
287 views

Isn't this dynamic programming?

I was solving problem 18 and 67 on Project Euler and came up with an algorithm that actually goes through almost all the possibilities to find the answer in O(n) time. However, ProjecEuler claims ...
2
votes
1answer
1k views

Median solving from Interview street in Python

Any suggestions to improve the performance of the following code? This code is exceeding the time limit for the last four cases. This is a solution to the problem https://www.interviewstreet.com/...
13
votes
5answers
20k views

Smallest Multiple

I just recently learned about Project Euler and have started doing the problems on there. I cleared problem 1 and 2, had no idea how to do 3 and 4, and started to do 5. I've seen the post regarding ...
2
votes
1answer
219 views

Spotify Best Before puzzle

I thought to spent my free time by solving a puzzle: Best Before Spotify Puzzle. I coded in Java, and yeah I did not clean up my code (just a rough work) and I have yet to optimize... so I did check ...
2
votes
1answer
181 views

How do I add memoization to this problem? [closed]

Problem Starting in the top left corner of a 22 grid, there are 6 routes (without backtracking) to the bottom right corner. How many routes are there through a 2020 grid? Solution Here is my ...
5
votes
1answer
1k views

Path sum - Dijkstra's algorithm in F#

I'm learning F# and I've decided to solve Project Euler's Problem #81 with Dijkstra's algorithm. In the 5 by 5 matrix below, the minimal path sum from the top left to the bottom right, by only ...
4
votes
2answers
330 views

Improving runtime of prime generation

I just answered the question on project euler about finding circular primes below 1 million using python. My solution is below. I was able to reduce the running time of the solution from 9 seconds to ...
3
votes
1answer
274 views

Euler 2 : Simple Fibonacci

I'm just starting to experiment with F# (from a C# background). I think I'm starting to get into the right way of thinking, but this code still seems pretty awkward. Is there a better (more terse) ...
3
votes
2answers
956 views

Shuttle Puzzle solver

How can I make this piece of code better? The problem to be solved is in the topmost comment. ...
1
vote
1answer
2k views

Connect graph from 2D array

I just completed Project Euler problem 18 which is a dynamic programming question through a graph of a triangle of numbers. The goal is to find the path from top to bottom of the triangle that has the ...
4
votes
2answers
216 views

Python vs. Java Runtime on Euler 22 - Name Scores

I want to know why Java is accepted over Python when it comes to runtime. On performing the following Euler problem, Python takes up less lines and runs faster (Python ~0.05s, Java ~0.3s on my machine)...
2
votes
4answers
734 views

“Recycled numbers” challenge

I wrote this program for the Google Code Jam problem, "Recycled numbers." It took around 2 and half minutes to solve the small input set on my dual core, 1GB RAM system. But for the large input set ...
3
votes
2answers
231 views

Product of all ints in array besides that an index i

I'm looking for a better implementation of the algorithm. ...
3
votes
1answer
1k views

ByteLandian challenge from CodeChef

I am trying to go through the problems on CodeChef and came across this problem: In Byteland they have a very strange monetary system. Each Bytelandian gold coin has an integer number written on ...
4
votes
1answer
2k views

More optimal “Making Change” Problem: Knapsack challenge

The problem description is: You are given n types of coin denominations of values v(1) < v(2) < ... < v(n) (all integers). Assume v(1) = 1, so you can always make change for any ...
7
votes
2answers
2k views

Canonical Python symmetric cryptography example

Python Cryptography Example Last weekend I wrote some code to help people use PyCrypto in a canonical fashion to symmetrically encrypt and decrypt strings and files. By canonical I mean I've followed ...
4
votes
1answer
198 views

Binary numbers challenge

I don't know if this is exactly refactoring but I recently completed a programming challenge to learn more about Ruby's iterators. However, I feel that the code is extremely "un-Ruby like". Would ...
40
votes
1answer
2k views

Finding minimum scalar product using ST Monad

Inspired by a Stack Overflow question, I decided to practice my Haskell by taking a crack at the Google Code Jam's Minimum Scalar Product problem: Given two vectors \$\mathbf{v_1}=(x_1,x_2,\ldots,...
4
votes
2answers
547 views

Calculation of the distance to the next space station

I've made a solution for this problem: Task: Write a program for calculation of the distance to the next space station. Algorithm: First base is located at the distance equal to ...
6
votes
1answer
261 views

“Best before” puzzle

I'm new To C++ and decided to have a go at the Spotify challenges on their website. I have now finished but I get the feeling my code is just terrible. I'm guessing it would be very hard for someone ...
11
votes
4answers
21k views

Python Solution for Project Euler #2 (Fibonacci Sums)

I'm a fairly new programmer (just started yesterday!). I decided to tackle Project Euler #2 today, as I did #1 yesterday without many problems. I came up with what seems to me to be a working solution,...
1
vote
6answers
2k views

The Next Palindrome - reducing total execution time

I tried to solve one SPOJ problem. I wrote one program in Python, however, it got accepted by the SPOJ judges, but its total execution time is 2.88s. The same algorithm used in C language having ...
2
votes
1answer
430 views

Changing bits in given big strings

I came up with this question. Let A and B be two N bit numbers. You are given initial values for A and B, and you should write a program which processes three kinds of queries: set_a idx x: ...
5
votes
2answers
827 views

Count Scorecards challenge problem related to partition number theory

I am having a challenge problem. I have solved the problem but my solution is slow. The problem is basically the distribution of scores among players. e.g for a 2 player game the possible scorecards ...
3
votes
1answer
375 views

“Picking Cards” challenge

I recently tried my hand at CodeSprint2 through Interview Street. Having not coded in quite some time, I wasn't surprised that I had difficulty writing optimized code, but on one problem in ...
6
votes
2answers
561 views

Euler 35 - python solution taking too long

Here is my solution for Project Euler 35. (Find the number of circular primes below 1,000,000. Circular meaning all rotations of the digits are prime, i.e. 197, <...
4
votes
1answer
497 views

Project Euler question 2 in CoffeeScript

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. ...
7
votes
4answers
761 views

Finding the sum of all the multiples of 3 or 5 below 1000, using list comprehension

I'm trying to compare my own implementation with another solution of Project Euler problem #1, which uses a list comprehension: ...
3
votes
2answers
485 views

Project Euler, #4: Incorrect Results on 7-digit numbers

I've got my answer working (up until a 7-digit answer is requested, anyway), and would like some help returning the correct answer speeding up the results I was thinking of storing the values of ...
7
votes
4answers
1k views

Project Euler #14 - Longest Collatz sequence

I'm attempting some Project Euler problems in an attempt to learn Python. While I can get the correct answer quite easily, my programs are quite slow. Project Euler, if doing it correctly, specifies ...
8
votes
6answers
3k views

Determining numeric palindromes

I am working on bettering my C# skills, and recently wrote this program to solve a projecteuler.net problem: A palindromic number reads the same both ways. The largest palindrome made from the ...