Questions tagged [code-challenge]
A code challenge is a competition for creative ways to solve a programming puzzle with an objective winning criterion not covered by other scoring tags (e.g. code-golf).
17
votes
6answers
3k views
Fake error message
Write a program that prints out the syntax error message of the compiler or interpreter. The error message should be misleading so that code maintainers will take days to find out that the error was ...
17
votes
5answers
2k views
Write Buggy Code [closed]
Now is the time to show off your abilities to write bad code. I am trying out a new sort of programming puzzle, most similar, I think, to the underhanded C contest. The main difference is that this is ...
3
votes
1answer
467 views
Fastest alphabetical list sort given the following limitations:
Your function must have an input that takes in an array containing 10000 random names, and must sort these names in alphabetical order. Names have a random length of up to 128 characters. ISO/IEC 8859-...
64
votes
118answers
12k views
The alphabet in programming languages
Our task is to, for each letter of the (English) alphabet, write a program that prints the alphabet, in a language whose name starts with that letter.
Input: none
Output:
...
4
votes
4answers
1k views
Sum of Fibonacci numbers — speed contest [closed]
Write a program that print sum of as many Fibonacci numbers as possible.
There is a limit in that your program should not run more than 10s on 2GHz single core PC. (equivalents are acceptable, for ...
9
votes
3answers
2k views
Lossy Text Compression
Background
Of the 256 possible characters that a byte can represent, only a few of these are used under most circumstances. Couldn't we somehow take advantage of this, and make our text files smaller ...
4
votes
11answers
1k views
Implement a sorting algorithm with no change. [closed]
In this task, you have to write a program, that reads a string with a length of up to 1024 characters and prints it out sorted. In order to make an interesting task from a boring one, I set a few ...
8
votes
6answers
2k views
Code-Challenge:The Nearest Prime
Challenge
In this task you would be given an
integer N you have to output the
nearest prime to the integer.
If the number is prime itself output the number.
The input N is given in a single ...
6
votes
2answers
1k views
“list comprehension” in php.
PHP has closures, let's play around with them.
I have some arrays similar to, $wannabelist = array (1, 2, 3, 4, 5, 6).
I want to do this: ...
74
votes
14answers
48k views
Generate the longest error message in C++
Write a short program, that would generate the longest possible error message, in a standard C++ compiler (gcc, cl.exe, ...
5
votes
5answers
1k views
Code-Challenge: Farey sequence (II)
Challenge
In this task you would be given an integer N
(less than 10^6), output the number of terms in the Farey
sequence of order N.
The input N < 106 is given in a single line, the inputs ...
37
votes
13answers
5k views
Palindromic palindrome checker [closed]
Write a program to test if a string is palindromic, with the added condition that the program be palindromic itself.
14
votes
17answers
4k views
Shuffle a deck without local variables [closed]
The object of this puzzle is to take a deck of 52 cards and shuffle it so that each card is in a random position.
Given:
An array, deck, of 52 distinct integers ...
8
votes
7answers
1k views
Find all number pairs that sum to 121212 [closed]
This problem is quite easy to do by brute force. In fact, it'll be reasonably fast to brute force as well. But where's the fun in that?
The Problem
Produce a list of all unique 5 digit number ...
10
votes
9answers
4k views
Arbitrary Base Conversion [closed]
Create a routine that takes an array of blocks in one numeric base system, and convert them to an array of blocks in another numeric base system. Both the from and to systems are arbitrary and should ...
10
votes
7answers
780 views
Circles of text
Find a way to make circles of a given radius using characters in a console. Please specify the font name and size. Also, please provide at least one example of the output.
For example:
Input:
...
7
votes
4answers
551 views
Obtain a number from 4 numbers using any combination of mathematical operations [closed]
Given 4 numbers n1, n2, n3, n4, and a goal n5, obtain n5 using n1 through n4 combined with any operations.
Eg. Given four numbers 2,3,4,5 and the goal as 8, output (one of many) is ...
12
votes
1answer
757 views
Break the broken cipher
I have designed a simple random generator that cycles two numbers in a chaotic way using a multiply and modulus method. It works great for that.
If I were to use it as a cipher generator it would ...
14
votes
49answers
7k views
Sum of positive integers. [closed]
Problem:
Given a set of integers, find the sum of all positive integers in it.
Input:
t – number of test cases [t < 1000]
On each of next t lines, an integer N [-1000 ≤ N ≤ 1000]
Output
The ...
13
votes
1answer
1k views
Implement PCRE in your language.
Note: After trying this myself, I soon realized what a mistake this was. Therfore, I am modifying the rules a bit.
The minimum required functionality:
Character classes (...
10
votes
14answers
2k views
Guess the number
Description
Create a fully working "Guess the number" game. The game is played by two players as follows:
player one chooses a number (A) between 1 and N
player two tries to guess A choosing a ...
55
votes
21answers
5k views
Add a feature to a programming language [closed]
Your task is to tack on a feature to a programming language, either by implementing a very clever library, or by processing the input text and/or tweaking the compilation process.
Ideas:
Add PHP-...
4
votes
1answer
1k views
How would you count score in a Scrabble® game? [closed]
Let's say that we are programming a game that lets you play Scrabble®.
We have a board with tiles placed on it, and empty cells are either normal or have multiplier properties (double or triple the ...
3
votes
2answers
210 views
Directories required for creating a folder tree
Say that you have this folder structure on your coumputer:
/a
And you want to have these folders:
/a/b
/a/c
/b/b
You would ...
5
votes
9answers
3k views
Partition of a positive integer N [closed]
Find the number of partitions of a positive integer n. Hope someone uses the explicit finite formula for the partition function defined in Jan Hendrik Brunier and Ken Ono paper here.
...
5
votes
3answers
979 views
->The Tragedy of Macbeth<- [closed]
The Setup
Here you can find the full text of The Tragedy of Macbeth. If you view the source, and save it as text, you will notice it comes out to 206,244 total characters (including the whitespace ...
2
votes
1answer
113 views
Five aligned points and some of the pairwise distances. Infer the relative positions! [closed]
Given five points on a straight line such that their pairwise distances are 1,2,4, ..., 14,18,20 (after ordering), find the respective positions of the five points (relative to the furthest point on ...
12
votes
4answers
4k views
Free a Binary Tree
So before you read some basic computer science concepts.
A binary tree is a dynamically allocated structure (usually used for ordered storage).
Because of its nature traversal of binary trees is ...
11
votes
8answers
6k views
Binary tree encoding
Let's suppose you have a complete binary tree (i.e. each internal node has exactly two non empty descendants). Each node contains a nonzero integer. You are given the task of encoding and decoding the ...
7
votes
2answers
778 views
Project Euler Problem 12: optimize memory usage
I am referring to Project Euler #12. Write the solution in any language you want, but consume the least amount of memory while executing. Running time is not measure in this case.
The sequence of ...
15
votes
2answers
679 views
Quine that takes as input the name of a language and outputs the same thing implemented in the input language
From Quine central:
Write a quine that takes as input the name of a language and outputs the same thing implemented in the input language.
The source article has something you can work from, but as ...
11
votes
2answers
4k views
Decryption by pattern analysis
You are given an encrypted string, encrypted using a very simple substitution cipher.
Problem
You do not know what the cipher is but you do know the ciphertext is English and that the most frequent ...
19
votes
5answers
4k views
Print a random maze
Write a program that generates and prints a random maze using the algorithm of your choice. The maze should be different for multiple runs of the program. Height and width are given as command line ...
6
votes
33answers
3k views
Print largest integer you can with the fewest characters [closed]
Find a way to output a large integer with few characters. Solutions will be scored based on the magnitude of the number and shortness of code.
EDIT: Let's impose a time limit of a minute on sensible ...
4
votes
3answers
244 views
Sharing Inherited Land [closed]
You and your brother have inherited a rectanglar block of land. This block of land's corners are read in from stdio as TLX,TLY,TRX,TRY,BLX,BLY,BRX,BRY (all decimal ...
11
votes
5answers
654 views
Fast Topswops calculation
From AZSPCS:
Suppose you have a deck containing n cards. Each card contains a number from 1 to n, and each number appears on exactly one card. You look at the number on the top card -- let's says it'...
4
votes
7answers
798 views
Find an unknown very large number [closed]
Let's suppose there is a finite unknown number n (n can be very large, does not necessarily fit 64-bits; think of ...
10
votes
4answers
1k views
fizz buzz in TMP
The Fizz Buzz problem is a very basic problem to solve that is used by some to weed out interviewees that don't know how to program. The problem is:
...
29
votes
31answers
13k views
Rand5() to Rand7() [closed]
You are provided with a function Rand5(). This function returns perfectly random (equal distribution) integers between 1 and 5.
Provide the function Rand7(), which uses Rand5() to produce perfectly ...
9
votes
4answers
2k views
N-Queens problem [closed]
In chess, a queen can move as far as as the board extends horizontally, vertically, or diagonally.
Given a NxN sized chessboard, print out how many possible positions N queens can be placed on the ...