Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 46 lines (33 sloc) 1.906 kb
5c7ded3 @martinrehfeld add README
authored
1 # Today's Kata: The Countdown Game
2
34235e3 @martinrehfeld fix typo in README
authored
3 I stumbled across this [little challenge on Stack Overflow](http://stackoverflow.com/questions/4586814/code-golf-countdown-number-game) and wanted to try it in Erlang.
5c7ded3 @martinrehfeld add README
authored
4
5 The task is inspired by the well-known British TV game show Countdown.
6
f7ce3e3 @martinrehfeld fix README formatting
authored
7 If you fancy seeing a clip of this game in action, check out this [YouTube clip](http://www.youtube.com/watch?v=pfa3MHLLSWI). It features the wonderful late Richard Whitely in 1997.
5c7ded3 @martinrehfeld add README
authored
8
9 You are given 6 numbers, chosen at random from the set {1, 2, 3, 4, 5, 6, 8, 9,
10 10, 25, 50, 75, 100}, and a random target number between 100 and 999. The aim
11 is to use the six given numbers and the four common arithmetic operations
12 (addition, subtraction, multiplication, division; all over the rational
13 numbers) to generate the target - or as close as possible either side. Each
14 number may only be used once at most, while each arithmetic operator may be
15 used any number of times (including zero.) Note that it does not matter how
16 many numbers are used.
17
18 Write a function that takes the target number and set of 6 numbers (can be
19 represented as list/collection/array/sequence) and returns the solution in any
20 standard numerical notation (e.g. infix, prefix, postfix). The function must
21 always return the closest-possible result to the target, and must run in at
22 most 1 minute on a standard PC. Note that in the case where more than one
23 solution exists, any single solution is sufficient.
24
f7ce3e3 @martinrehfeld fix README formatting
authored
25 {50, 100, 4, 2, 2, 4}, target 203
26 e.g. 100 * 2 + 2 + (4 / 4) (exact)
27 e.g. (100 + 50) * 4 * 2 / (4 + 2) (exact)
5c7ded3 @martinrehfeld add README
authored
28
29 ## Erlang Solution
30
31 Run the code:
32
33 ```erlang
34 cd_solver:solutions(203, [ 50, 100, 4, 2, 2, 4 ]).
35 ```
36
37 With timings:
38
39 ```erlang
40 %% run once
41 cd_benchmark:run(fun cd_solver:solutions/2, [203, [ 50, 100, 4, 2, 2, 4 ]]).
42
43 %% repeat 10 times and average
44 cd_benchmark:run(10, fun cd_solver:solutions/2, [203, [ 50, 100, 4, 2, 2, 4 ]]).
45 ```
Something went wrong with that request. Please try again.