This is an ai-player challenge. Your goal is to reach the number 2011 as quickly as possible, or to get as close to it as you can.
Rules:
- A "hole" consists of a rectangular grid of digits (0-9).
- Your total starts at 0.
- You may start at any digit on the grid. This is your first "stroke."
- For each subsequent stroke, you may move to any immediately adjacent digit (up, left, down, right). However, you may not move to a digit that you have used before.
- With each stroke, you will use your current total and the digit at your current position as operands (the total is always the first operand), and apply one of the four basic arithmetic operations (+ - * /). The result will become your new total.
- If your total becomes 2011, your score for the course is the number of strokes.
- If you have no more valid moves, your score is your current number of strokes + your total's distance from 2011.
- You may also choose at any time to stop, and your score will be your current number of strokes + your total's distance from 2011.
Input:
- You will read in a file containing data for each "hole." Alternatively, you may accept the input through stdin or an equivalent.
- Each hole will consist of H rows of W digits, for a grid of size WxH. H and W may vary per hole.
- The holes will be separated by a single blank line.
- In the spirit of golf, the competition will consist of 18 holes, but your program should be able to handle any number of them.
Output:
- For each hole, your program should output the position of the starting digit. The position should be given as
(row, col)
where the top-left is(0, 0)
. - For each stroke, your program should output the chosen operation, the current digit, and the resulting total.
- At the end of each hole, whether you reach 2011 or not, your program should output your number of strokes and your score for the hole (usually the same as the number of strokes).
- For testing purposes, you may also find it helpful to output your path on each board indicating which digits were used. However, you will not be required to provide this output for the competition.
Notes:
- For any given hole, your program should always start at the same position and choose the same route (i.e., no random choices). The starting position does not need to be the same for every hole.
- The total is not limited to the integers. That is, if you divide 4023 by 2, your total would become 2011.5, and you would still be .5 away from the goal.
- Your program should run in a "reasonable" amount of time.
- For purposes of verifiability, your program should be runnable on an online interpreter such as ideone.com.
- The winner is the program that has the lowest overall score for the entire course. If there is a tie, the tying programs will play a new course, hole-for-hole, with the lowest scorers advancing until there is only one winner. If there is still a tie after the tiebreaker course, the program submitted first will win.
Deadline:
- The current deadline for this competition is September 10, 2011. This deadline may be extended, depending on interest.
Sample input:
14932875921047
60438969014654
56398659108239
90862084187569
94876198569386
14897356029523
Sample output:
Start: (3, 7)
+4=4
*9=36
*9=324
*6=1944
+9=1953
+8=1961
+8=1969
+9=1978
+6=1984
+8=1992
+8=2000
+8=2008
+4=2012
-1=2011
Strokes: 14
Score: 14
14932875921047
6043....014654
563..65.108239
90..208.187569
94.76198569386
...97356029523
Sample output (compact):
Start: (3, 7)
+4=4 *9=36 *9=324 *6=1944 +9=1953 +8=1961 +8=1969 +9=1978 +6=1984 +8=1992 +8=2000 +8=2008 +4=2012 -1=2011
Strokes: 14 Score: 14
Sample input:
0346092836
1986249812
3568086343
5509828197
4612486355
3025745681
7685047124
2098745313
Sample output:
Start: (4, 7)
+3=3
*6=18
*5=90
+7=97
*5=485
*4=1940
+7=1947
+8=1955
+9=1964
+8=1972
+6=1978
+7=1985
+3=1988
+4=1992
+5=1997
+5=2002
+5=2007
+3=2010
+1=2011
Strokes: 19
Score: 19
0346092836
.986249812
..68086343
..09828197
.61248..55
.02574.681
...504.124
20.....313
Sample input:
9876
5432
1098
7654
3210
Sample output:
Start: (2, 2)
+9=9
*8=72
*4=288
*5=1440
+6=1446
+7=1453
+3=1456
+2=1458
+1=1459
Strokes: 9
Score: 561
9876
5432
10..
....
....
Sample input:
39857205
74493859
02175092
54239112
39209358
34568905
Sample output:
Start: (0, 0)
+3=3
*7=21
*4=84
*4=336
-1=335
*2=670
/3=(670/3)
*9=2010
+1=2011
.9857205
...93859
02.75092
54....12
39209358
34568905
Results
Unfortunately, there were only two contestants, but I'll post the results.
#1 - Howard (1881)
#2 - Gareth (5442)
The first half of the course consisted of roughly "normal" holes, generated mostly randomly. The second half was more challenging, as the holes contained more "sand traps" (sections deliberately filled with low numbers, especially 0s).
**Howard**
01) 5 - 5
02) 5 - 5
03) 6 - 6
04) 6 - 7
05) 6 - 7
06) 6 - 6
07) 5 - 5
08) 5 - 5
09) 6 - 6
10) 9 - 10
11) 5 - 8
12) 8 - 8
13) 6 - 7
14) 8 - 9
15) 7 - 12
16) 20 - 1665
17) 29 - 66
18) 30 - 44
Front 9) 52
Back 9) 1829
Full 18) 1881
**Gareth**
01) 9 - 10
02) 33 - 173
03) 8 - 8
04) 11 - 16
05) 7 - 84
06) 17 - 17
07) 9 - 10
08) 8 - 8
09) 15 - 15
10) 16 - 16
11) 12 - 32
12) 18 - 164
13) 34 - 335
14) 10 - 10
15) 26 - 447
16) 78 - 78
17) 1 - 2010
18) 1 - 2009
Front 9) 341
Back 9) 5101
Full 18) 5442
The course used can be found on pastebin.
@Howard: I ran your program with the lower number of paths due to limits on ideone. If your full version gives significantly different results, let me know the scores and the relative running time of the program.