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
3
votes
2answers
972 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
735 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
548 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
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 ...
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
828 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
378 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
574 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
498 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
762 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 ...
9
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 ...
3
votes
1answer
3k views

Output strings from a set in lexicographical order

Puzzle Description: You are given 'n' strings w1, w2, ......, wn. Let Si denote the set of strings formed by considering all unique substrings of the string wi. A substring is defined as a ...
4
votes
2answers
935 views

k_diff challenge in Java

Puzzle Description Given \$N\$ numbers, \$N <= 10^5\$, count the total pairs of numbers \$(N_i, N_j)\$ that have a difference of \$K = N_i - N_j\$ where \$0 < K < 10^9\$. Input ...
6
votes
3answers
3k views

Calculating sum of similarities of strings

Puzzle: For two strings A and B, we define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of strings "abc" and "abd" ...
3
votes
2answers
3k views

Rot -n algorithm in Java

This is a rot-n (rotate n times) encrypt/decrypt algorithm, where n can be any integer (+/-). It's written to encrypt/decrypt all the alphabets (upper/lower case) and leaving behind all non-alphas. ...
5
votes
3answers
601 views

Optimizing word counter

I took the Python class at Google code today, and this is what I made for the problem about building a word counter. Please take a look and suggest any improvements that can be done. Please do point ...
7
votes
1answer
1k views

Optimizing string match algorithm

I was trying to solve this problem. I thought of any possible relation between the number of matches among subsequent substrings, but could not find one. So, the probably naive solution that I ...
3
votes
4answers
2k views

Sieve of Eratosthenes: making it quicker

I was thinking about doing problem 23 of Project Euler. It includes the difficulty where you have to factorize primes. I had already done that in problems I solved earlier, but it was only necessary ...
8
votes
2answers
1k views

Pangrams CodeEval challenge

I took a challenge on CodeEval. Although the code seems to work for the examples taken from the site, I feel it is not really pretty and must be more complicated than it should be. Description: ...
5
votes
2answers
6k views

Finding the next palindrome of a number string

Here is the problem: A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. For a given positive ...
5
votes
1answer
6k views

Time Limit Exceeds [HS11DIVS] - How to make it faster?

Here is the question. From SPOJ [HS11DIVS]. Now , the problem is that my code works perfectly for small numbers. But when it comes to Large numbers , the time limit exceeds. I am not getting any hint ...
10
votes
2answers
241 views

Project Euler problem 1 in Factor

I'm a complete beginner of Factor, but I just managed to solved Euler Problem #1 using it, and would love to have the code reviewed. Anything that can be improved? In particular I'm wondering if there ...
3
votes
2answers
2k views

Google Code Jam (Milkshakes) solution

For practice, I am working through some Google Code Jam problems. The code below is for the Milkshakes problem, which is located here. Problem You own a milkshake shop. There are N different ...
2
votes
6answers
4k views

Quadrant Queries challenge

Running the same test 10,000 times with cProfile tells me that most of the damage happens in the count() function. This is my attempt at a solution to the Quadrant Queries challenge from ...
4
votes
1answer
153 views

How can I get this R code to pass the “1 minute” test for this Project Euler question?

I am attempting to learn R programming by going through the questions in Project Euler. The code below is my solution to problem 5 which asks for the smallest number that is evenly divisible by 1 ...
6
votes
3answers
362 views

Finding the sum of the digits appearing in the leaves via in-order traversal

The following text is an in-order traversal of a binary tree with 1023 nodes. What is the sum of the digits appearing in the leaves? How can I improve this Clojure code? It looks strange to me to ...
3
votes
2answers
403 views

Searching for repeated characters in a sequence of characters

The following code solves this problem: The 3072 characters below contain a sequence of 5 characters which is repeated. However, there is a twist: one of the sequences has a typo. To be ...
5
votes
2answers
363 views

BestApproximationDiv2 problem in Haskell

The task is to write a function findFraction maxDen number to find a short but good rational approximation to a decimal representation of a number — problem ...
7
votes
1answer
4k views

Yahtzee Code Kata in Python

I tried a Yahtzee kata in Python the other day. I'm not particularly experienced in Python (C# is my main language) so I'd be interested in any feedback as to how I could have done things better. In ...
3
votes
3answers
504 views

Alien Numbers - how Scala-ish is my solution?

I'm trying to solve an old GCJ. It's a very simple puzzle, but I'm trying to sharpen my Scala-fu. Basically, you're getting a list of triple ...
1
vote
1answer
224 views

Compute e using Euler's expansion

Given the following task: Exercise 1.38. In 1737, the Swiss mathematician Leonhard Euler published a memoir De Fractionibus Continuis, which included a continued fraction expansion for e - ...
6
votes
2answers
623 views

“File Fix-it” challenge

I'm learning Python and have found this problem from Google Code Jam: How many mkdir commands does it take to construct a given directory tree: Input ...
7
votes
1answer
6k views

Hypothetical SalesTax challenge

I have a small solution to the following hypothetical problem: Basic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical products that are exempt. Import duty ...
22
votes
2answers
3k views

Ruby Koans' Greed Task

Having coded in Java and C# for quite some years, I'm currently learning Ruby. I'm working my way through the Ruby Koans tutorial. At some point, you are to implement a method that calculates the game-...
23
votes
3answers
2k views

Project Euler Problem 2 in Clojure

I am in the process of learning Clojure. I am fairly new to functional programming and would like to know if my code smells or if there are any performance implications with my approach. ...
57
votes
10answers
4k views

Using separate functions for Project Euler 1

I started programming with Java and C++, so I'm used to having a 'main' function that calls other functions that do the actual work. At university I was always told that doing actual computation in ...
53
votes
9answers
12k views

Project Euler problem 1 in Python - Multiples of 3 and 5

I'd like suggestions for optimizing this brute force solution to problem 1. The algorithm currently checks every integer between 3 and 1000. I'd like to cut as many unnecessary calls to ...