Skip to content

Commit e7c9e6a

Browse files
committed
Add "Arrows" hole
1 parent 10c7a74 commit e7c9e6a

File tree

5 files changed

+119
-4
lines changed

5 files changed

+119
-4
lines changed

css/hole.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ main .info {
6666
white-space: pre;
6767
}
6868

69+
#arrows code { font-size: 1.5rem }
70+
#arrows td { font-family: 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', Courier, monospace }
71+
#arrows td:first-child { white-space: pre }
72+
#arrows td:last-child { width: 100% }
73+
6974
#chars {
7075
border-bottom: 1px solid var(--color);
7176
font-weight: bold;

db/a-schema.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ CREATE TYPE cheevo AS ENUM (
1313

1414
CREATE TYPE hole AS ENUM (
1515
'12-days-of-christmas', '99-bottles-of-beer', 'abundant-numbers',
16-
'arabic-to-roman', 'brainfuck', 'christmas-trees', 'css-colors', 'cubes',
17-
'diamonds', 'divisors', 'emirp-numbers', 'emojify', 'evil-numbers',
18-
'fibonacci', 'fizz-buzz', 'happy-numbers', 'intersection',
16+
'arabic-to-roman', 'arrows', 'brainfuck', 'christmas-trees', 'css-colors',
17+
'cubes', 'diamonds', 'divisors', 'emirp-numbers', 'emojify',
18+
'evil-numbers', 'fibonacci', 'fizz-buzz', 'happy-numbers', 'intersection',
1919
'kolakoski-constant', 'kolakoski-sequence', 'leap-years',
2020
'levenshtein-distance', 'leyland-numbers', 'look-and-say',
2121
'lucky-tickets', 'morse-decoder', 'morse-encoder', 'niven-numbers',
@@ -48,7 +48,7 @@ CREATE TABLE discord_records (
4848
hole hole NOT NULL,
4949
lang lang NOT NULL,
5050
message text NOT NULL,
51-
PRIMARY KEY(hole, lang)
51+
PRIMARY KEY (hole, lang)
5252
);
5353

5454
CREATE TABLE ideas (

hole/arrows.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package hole
2+
3+
import (
4+
"fmt"
5+
"math/rand"
6+
"strings"
7+
)
8+
9+
var arrowMap = map[string][2]int8{
10+
// U+2190 - U+2199
11+
"←": {-1, 0}, "↑": {0, 1}, "→": {1, 0}, "↓": {0, -1}, "↔": {0, 0},
12+
"↕": {0, 0}, "↖": {-1, 1}, "↗": {1, 1}, "↘": {1, -1}, "↙": {-1, -1},
13+
14+
// U+21B0 - U+21B3
15+
"↰": {-1, 1}, "↱": {1, 1}, "↲": {-1, -1}, "↳": {1, -1},
16+
17+
// U+21D0 - U+21D9
18+
"⇐": {-1, 0}, "⇑": {0, 1}, "⇒": {1, 0}, "⇓": {0, -1}, "⇔": {0, 0},
19+
"⇕": {0, 0}, "⇖": {-1, 1}, "⇗": {1, 1}, "⇘": {1, -1}, "⇙": {-1, -1},
20+
21+
// U+21E6 - U+21E9
22+
"⇦": {-1, 0}, "⇧": {0, 1}, "⇨": {1, 0}, "⇩": {0, -1},
23+
24+
// U+2940 - U+2941
25+
"⥀": {0, 0}, "⥁": {0, 0},
26+
}
27+
28+
func arrows() ([]string, string) {
29+
args := make([]string, 0, 3*len(arrowMap))
30+
pos := [2]int8{}
31+
32+
// 1-3 of each arrow.
33+
for arrow := range arrowMap {
34+
for times := rand.Intn(3); times >= 0; times-- {
35+
args = append(args, arrow)
36+
}
37+
}
38+
39+
// Shuffle the args.
40+
rand.Shuffle(len(args), func(i, j int) {
41+
args[i], args[j] = args[j], args[i]
42+
})
43+
44+
// Calculate the outs from the args.
45+
outs := make([]string, len(args))
46+
for i, arrow := range args {
47+
coord := arrowMap[arrow]
48+
pos[0] += coord[0]
49+
pos[1] += coord[1]
50+
51+
outs[i] = fmt.Sprintf("%d %d", pos[0], pos[1])
52+
}
53+
54+
return args, strings.Join(outs, "\n")
55+
}

hole/play.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ func getAnswer(holeID, code string) (args []string, answer string) {
3535
switch holeID {
3636
case "arabic-to-roman", "roman-to-arabic":
3737
args, answer = arabicToRoman(holeID == "roman-to-arabic")
38+
case "arrows":
39+
args, answer = arrows()
3840
case "brainfuck":
3941
args, answer = brainfuck()
4042
case "css-colors":

holes.toml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,59 @@ preamble = '''
110110
<p>For each Arabic numeral argument print the same number in Roman numerals.
111111
'''
112112

113+
[Arrows]
114+
category = 'Transform'
115+
preamble = '''
116+
<p>
117+
Starting at <b>[0, 0]</b> print the result of applying each of the given
118+
Unicode arrow arguments. The arrows will be a random combination of these:
119+
120+
<table id=arrows>
121+
<thead>
122+
<tr><th>Coord<th>Arrows
123+
<tbody>
124+
<tr><td>[-1,&nbsp;-1]
125+
<td><code>↙</code> U+2199,
126+
<code>↲</code> U+21B2,
127+
<code>⇙</code> U+21D9
128+
<tr><td>[-1,&nbsp; 0]
129+
<td><code>←</code> U+2190,
130+
<code>⇐</code> U+21D0,
131+
<code>⇦</code> U+21E6
132+
<tr><td>[-1,&nbsp; 1]
133+
<td><code>↖</code> U+2196,
134+
<code>↰</code> U+21B0,
135+
<code>⇖</code> U+21D6
136+
<tr><td>[ 0,&nbsp;-1]
137+
<td><code>↓</code> U+2193,
138+
<code>⇓</code> U+21D3,
139+
<code>⇩</code> U+21E9
140+
<tr><td>[ 0,&nbsp; 0]
141+
<td><code>↔</code> U+2194,
142+
<code>↕</code> U+2195,
143+
<code>⇔</code> U+21D4,
144+
<code>⇕</code> U+21D5,
145+
<code>⥀</code> U+2940,
146+
<code>⥁</code> U+2941
147+
<tr><td>[ 0,&nbsp; 1]
148+
<td><code>↑</code> U+2191,
149+
<code>⇑</code> U+21D1,
150+
<code>⇧</code> U+21E7
151+
<tr><td>[ 1,&nbsp;-1]
152+
<td><code>↘</code> U+2198,
153+
<code>↳</code> U+21B3,
154+
<code>⇘</code> U+21D8
155+
<tr><td>[ 1,&nbsp; 0]
156+
<td><code>→</code> U+2192,
157+
<code>⇒</code> U+21D2,
158+
<code>⇨</code> U+21E8
159+
<tr><td>[ 1,&nbsp; 1]
160+
<td><code>↗</code> U+2197,
161+
<code>↱</code> U+21B1,
162+
<code>⇗</code> U+21D7
163+
</table>
164+
'''
165+
113166
[brainfuck]
114167
category = 'Computing'
115168
links = [

0 commit comments

Comments
 (0)