Skip to content

Commit 5348743

Browse files
committed
Add "Ten-pin Bowling" hole
Needs a description, but it works!
1 parent 68f871c commit 5348743

File tree

6 files changed

+78
-10
lines changed

6 files changed

+78
-10
lines changed

assets/hole.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ main nav a:nth-child(3):before {
223223
#arg span {
224224
background: #ddd;
225225
border-radius: 10px;
226+
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
226227
line-height: 30px;
227228
padding: 3px 7px;
228-
white-space: nowrap;
229229
}
230230

231231
#status {

db.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ CREATE TYPE public.hole AS ENUM (
5050
'sierpiński-triangle',
5151
'spelling-numbers',
5252
'sudoku',
53+
'ten-pin-bowling',
5354
'λ',
5455
'π',
5556
'τ',

holes.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ Gaming
2121

2222
* Poker
2323
* Sudoku
24-
* Ten-pin Bowling **TODO**
25-
26-
`X 7/ 9- X -8 ⑧/ F6 X X X81` = `167`
27-
28-
`X X X X X X X X X XXX` = `300`
24+
* Ten-pin Bowling
2925

3026
Math
3127
====

routes/solution.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ func solution(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
3838
}
3939

4040
switch in.Hole {
41-
case "arabic-to-roman":
42-
args, out.Exp = arabicToRoman(false)
41+
case "arabic-to-roman", "roman-to-arabic":
42+
args, out.Exp = arabicToRoman(in.Hole == "roman-to-arabic")
4343
case "brainfuck":
4444
args, out.Exp = brainfuck()
4545
case "morse-decoder", "morse-encoder":
@@ -50,15 +50,15 @@ func solution(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
5050
args, out.Exp = poker()
5151
case "quine":
5252
out.Exp = in.Code
53-
case "roman-to-arabic":
54-
args, out.Exp = arabicToRoman(true)
5553
case "seven-segment":
5654
args = make([]string, 1)
5755
args[0], out.Exp = sevenSegment()
5856
case "spelling-numbers":
5957
args, out.Exp = spellingNumbers()
6058
case "sudoku":
6159
args, out.Exp = sudoku()
60+
case "ten-pin-bowling":
61+
args, out.Exp = tenPinBowling()
6262
default:
6363
out.Exp = answers[in.Hole]
6464
}

routes/ten-pin-bowling.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package routes
2+
3+
import (
4+
"math/rand"
5+
"strings"
6+
)
7+
8+
var games = [...]struct {
9+
frames []rune
10+
score string
11+
}{
12+
{[]rune(" X X X X X X X X X XXX"), "300"},
13+
{[]rune(" X 17 36 63 4- X 61 7- 6- -- "), "85"},
14+
{[]rune(" X 7/ 9- X -8 8/ -6 X X X81"), "167"},
15+
{[]rune(" X 8- 51 X 35 36 7- 9- X 8- "), "109"},
16+
{[]rune("-- -- -- -- -- -- -- -- -- -- "), "0"},
17+
{[]rune("-9 5- 35 31 61 43 6- 63 6- 71 "), "69"},
18+
{[]rune("32 3/ X X X X 43 33 33 36 "), "154"},
19+
{[]rune("43 44 56 45 X X X X 43 23 "), "148"},
20+
{[]rune("53 33 34 X X X 53 3/ X X43"), "163"},
21+
{[]rune("7/ 4- 36 81 8- 54 44 53 31 8- "), "81"},
22+
{[]rune("71 33 45 45 X X X X 5/ 23 "), "154"},
23+
{[]rune("71 7- 72 8- 81 51 8- X 6- 81 "), "86"},
24+
{[]rune("72 9- 81 X 9- 8/ X X X 9- "), "162"},
25+
{[]rune("81 16 8/ 33 X 7- -7 9- 8- -- "), "83"},
26+
{[]rune("9- -2 35 X X X X 62 22 62 "), "143"},
27+
}
28+
29+
func tenPinBowling() ([]string, string) {
30+
args := make([]string, len(games))
31+
outs := make([]string, len(games))
32+
33+
for i, game := range games {
34+
frames := make([]rune, len(game.frames))
35+
copy(frames, game.frames)
36+
37+
// Randomly create splits and fouls to make it more interesting.
38+
for j, char := range frames {
39+
var replacement rune
40+
41+
switch char {
42+
case '-':
43+
replacement = 'F'
44+
case '5', '6', '7', '8':
45+
replacement = '①' - '1' + char
46+
default:
47+
continue
48+
}
49+
50+
if rand.Intn(2) == 0 {
51+
frames[j] = replacement
52+
}
53+
}
54+
55+
args[i] = string(frames)
56+
outs[i] = game.score
57+
}
58+
59+
// Shuffle
60+
for i := range args {
61+
j := rand.Intn(i + 1)
62+
args[i], args[j] = args[j], args[i]
63+
outs[i], outs[j] = outs[j], outs[i]
64+
}
65+
66+
return args, strings.Join(outs, "\n")
67+
}

routes/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,10 @@ A Partridge in a Pear Tree.</blockquote>`,
340340
┠───┼───┼───╂───┼───┼───╂───┼───┼───┨
341341
┃ 1 │ 8 │ 2 ┃ 5 │ 7 │ 9 ┃ 3 │ 4 │ 6 ┃
342342
┗━━━┷━━━┷━━━┻━━━┷━━━┷━━━┻━━━┷━━━┷━━━┛</pre>`,
343+
}, {
344+
"", "",
345+
"ten-pin-bowling", "Ten-pin Bowling", "Slow",
346+
"WIP Writing descriptions is hard, patches very welcome!",
343347
}, {
344348
"", "",
345349
"λ", "λ", "Medium",

0 commit comments

Comments
 (0)