Skip to content

Commit edd2828

Browse files
committed
Add "Poker" hole
Updates #3 Needs a lot more random, but it'll do for now.
1 parent 36c01b1 commit edd2828

File tree

7 files changed

+76
-5
lines changed

7 files changed

+76
-5
lines changed

assets/hole.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ h3 {
8383
margin-top: 10px;
8484
}
8585

86+
.red { color: red }
87+
8688
.term-fg31 { color: #c00 } /* red */
8789
.term-fg32 { color: #490 } /* green */
8890
.term-fg33 { color: #ca0 } /* yellow */

db.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ CREATE TYPE public.hole AS ENUM (
5252
'pangram-grep',
5353
'pascals-triangle',
5454
'pernicious-numbers',
55+
'poker',
5556
'prime-numbers',
5657
'quine',
5758
'roman-to-arabic',

routes/home.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,10 @@ func home(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
125125
WHEN 'τ' THEN 25
126126
WHEN 'arabic-to-roman' THEN 26
127127
WHEN 'brainfuck' THEN 27
128-
WHEN 'roman-to-arabic' THEN 28
129-
WHEN 'rule-110' THEN 29
130-
WHEN 'spelling-numbers' THEN 30
128+
WHEN 'poker' THEN 28
129+
WHEN 'roman-to-arabic' THEN 29
130+
WHEN 'rule-110' THEN 30
131+
WHEN 'spelling-numbers' THEN 31
131132
END, row_number`,
132133
userID,
133134
)

routes/pangram-grep.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func pangramGrep() (args []string, out string) {
1919
{"1", "Waxy and quivering, jocks fumble the pizza."},
2020
{"1", "When zombies arrive, quickly fax judge Pat."},
2121
}
22-
22+
2323
// Add some autogenerated cases.
2424
for c := 0; c < 6; c++ {
2525
perm := rand.Perm(26)

routes/poker.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package routes
2+
3+
import "math/rand"
4+
5+
var handTypes = []string{
6+
"High Card",
7+
"Pair",
8+
"Two Pair",
9+
"Three of a Kind",
10+
"Straight",
11+
"Flush",
12+
"Full House",
13+
"Four of a Kind",
14+
"Straight Flush",
15+
"Royal Flush",
16+
}
17+
18+
func poker() (args []string, out string) {
19+
hands := []struct {
20+
Type uint8
21+
Cards []rune
22+
}{
23+
// All the royal flushes.
24+
{9, []rune{'🂪', '🂫', '🂭', '🂮', '🂡'}},
25+
{9, []rune{'🂺', '🂻', '🂽', '🂾', '🂱'}},
26+
{9, []rune{'🃊', '🃋', '🃍', '🃎', '🃁'}},
27+
{9, []rune{'🃚', '🃛', '🃝', '🃞', '🃑'}},
28+
// TODO Needs more random.
29+
{8, []rune{'🃘', '🃗', '🃖', '🃕', '🃔'}},
30+
{7, []rune{'🂻', '🃋', '🂫', '🃛', '🃇'}},
31+
{6, []rune{'🂺', '🃊', '🂪', '🃙', '🃉'}},
32+
{5, []rune{'🂤', '🂫', '🂨', '🂢', '🂩'}},
33+
{4, []rune{'🃙', '🃈', '🂧', '🃆', '🂵'}},
34+
{3, []rune{'🃗', '🃇', '🂧', '🃞', '🃃'}},
35+
{2, []rune{'🃔', '🂤', '🃓', '🃃', '🃝'}},
36+
{1, []rune{'🂱', '🃁', '🃘', '🂤', '🂷'}},
37+
{0, []rune{'🃃', '🃛', '🂨', '🂴', '🂢'}},
38+
}
39+
40+
// Shuffle the hands.
41+
for i := range hands {
42+
j := rand.Intn(i + 1)
43+
hands[i], hands[j] = hands[j], hands[i]
44+
}
45+
46+
for _, hand := range hands {
47+
// Shuffle the cards in the hand.
48+
for i := range hand.Cards {
49+
j := rand.Intn(i + 1)
50+
hand.Cards[i], hand.Cards[j] = hand.Cards[j], hand.Cards[i]
51+
}
52+
53+
args = append(args, string(hand.Cards))
54+
55+
out += handTypes[hand.Type] + "\n"
56+
}
57+
58+
// Drop the trailing newline.
59+
out = out[:len(out)-1]
60+
61+
return
62+
}

routes/solution.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func solution(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
2424

2525
type Out struct {
2626
Arg, Diff, Err, Exp, Out string
27-
Argv []string
27+
Argv []string
2828
}
2929

3030
var in In
@@ -48,6 +48,8 @@ func solution(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
4848
args, out.Exp = morse(in.Hole == "morse-decoder")
4949
case "pangram-grep":
5050
args, out.Exp = pangramGrep()
51+
case "poker":
52+
args, out.Exp = poker()
5153
case "quine":
5254
out.Exp = in.Code
5355
case "roman-to-arabic":

routes/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ A Partridge in a Pear Tree.</blockquote>`,
129129
}, {
130130
"quine", "Quine", "Fast",
131131
"A <b>quine</b> is a non-empty computer program which takes no input and produces a copy of its own source code as its only output, produce such a program.<p>Trailing whitespace is <b>NOT</b> stripped from the output for this hole.</p>",
132+
}, {
133+
"poker", "Poker", "Slow",
134+
"Given various poker hands as arguments, print what type of hand each argument is.<p>The list of hands in ranking order are as follows:<table><tr><th>Royal Flush<td class=red>🃁🃎🃍🃋🃊<tr><th>Straight Flush<td>🃛🃚🃙🃘🃗<tr><th>Four of a Kind<td>🃕<span class=red>🃅🂵</span>🂥<span class=red>🃂</span><tr><th>Full House<td>🂦<span class=red>🂶🃆</span>🃞<span class=red>🂾</span><tr><th>Flush<td class=red>🃋🃉🃈🃄🃃<tr><th>Straight<td><span class=red>🃊</span>🂩<span class=red>🂸🃇</span>🃖<tr><th>Three of a Kind<td>🃝🂭<span class=red>🂽🂹</span>🂢<tr><th>Two Pair<td><span class=red>🂻</span>🂫🃓🂣<span class=red>🂲</span><tr><th>Pair<td>🂪<span class=red>🂺</span>🂨<span class=red>🂷</span>🃔<tr><th>High Card<td><span class=red>🃎🃍</span>🂧🂤<span class=red>🂳</span></table>",
132135
}, {
133136
"roman-to-arabic", "Roman to Arabic", "Slow",
134137
"For each roman numeral argument print the same number in arabic numerals.</p>",

0 commit comments

Comments
 (0)