The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
4
votes
2answers
930 views

“Find the Min” challenge on Facebook Hacker Cup

I was solving the "Find the Min" problem on Facebook Hacker Cup. The code below works fine for the sample inputs given there, but for input size as big as 109, this takes hours to return the solution....
1
vote
1answer
6k views

SPOJ Problem 2 - Prime Generator

I'm trying to solve this problem. After a couple of tries, this is what I pulled off: ...
1
vote
3answers
117 views

Tips on projecteuler code optimization

I am working on projecteuler # 14, http://projecteuler.net/problem=14 and my code takes too long to run. Any tips, or hints for a beginner? Code: ...
2
votes
3answers
648 views

Mimicking T9 cell messaging

Today I solved a question from Google Code Jam: mimicking a cell phone keypad messaging. Here is the program, with goto statements. I know it is an unstructured ...
2
votes
4answers
9k views

Faster way to determine largest prime factor

Project Euler problem 3 asks: What is the largest prime factor of the number 600851475143? The first step I took is to determine the highest value number I should be looking at as a possibility (...
2
votes
2answers
3k views

Enormous Input Test - reducing program runtime

This is my solution to SPOJ Problem 442. How can I make this code run faster? What are some techniques that can be used to make this faster? I am getting a Time Limit Exceed Error here. ...
3
votes
3answers
313 views

Project Euler 10 - Summation of primes

I'm currently attempting to learn OCaml, and I'm working thought the Project Euler problems to do so. Here's some code I knocked together for problem 10. I am looking for idiomatic feedback rather ...
4
votes
3answers
339 views

Project Euler #35 in Common Lisp

To start with Common Lisp I am doing Project Euler using this language. Usually I manage to solve problems but I am quite sure that my code is not as efficient as it could be in Common Lisp. That is ...
2
votes
1answer
1k views

optimizing project euler #83 solution

Project Euler problem 83 asks: In the 5 by 5 matrix below, ...
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
415 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
807 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
157 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
275 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
431 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
906 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
381 views

Help me make my Python code clearer

Here's my solution to Project Euler problem 40. ...
4
votes
2answers
298 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
3k 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 ...
4
votes
2answers
843 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
289 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
222 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
182 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
332 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
279 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
988 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
218 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
745 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
232 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
199 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
552 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
262 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
22k 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 ...