Skip to content

Commit 3e971cc

Browse files
committed
Add "CSS Colors" hole
1 parent 56ea813 commit 3e971cc

File tree

6 files changed

+569
-18
lines changed

6 files changed

+569
-18
lines changed

assets/common.css

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,34 @@ thead th {
490490

491491
#run > span { margin: 1rem }
492492

493-
#morse, #states { columns: 4 }
494-
@media (max-width: 54rem) { #morse, #states { columns: 2 } }
495-
@media (max-width: 30rem) { #morse, #states { columns: 1 } }
493+
/* TODO Generalise the hole mapping table CSS, lose the specific IDs. */
496494

497-
#morse table, #states table { break-inside: avoid-column }
495+
#colors, #morse, #states { columns: 4 }
496+
@media (max-width: 54rem) { #colors, #morse, #states { columns: 2 } }
497+
@media (max-width: 30rem) { #colors, #morse, #states { columns: 1 } }
498498

499-
#morse td:last-child, #states td:first-child { width: 100% }
499+
#colors svg {
500+
align-self: center;
501+
border: 1px solid var(--color);
502+
height: 1rem;
503+
margin-right: .5rem;
504+
width: 1rem;
505+
}
506+
507+
#colors table, #morse table, #states table { break-inside: avoid-column }
508+
509+
#colors td:first-child { display: flex }
510+
511+
#colors td:last-child {
512+
text-align-last: justify;
513+
text-justify: inter-character;
514+
}
515+
516+
#colors th:first-child,
517+
#morse td:last-child,
518+
#states td:first-child {
519+
width: 100%;
520+
}
500521

501522
#stats { grid-template-columns: repeat(4, 1fr) }
502523

assets/hole.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ aside > div {
2525
border: 1px solid var(--color);
2626
border-left: 0;
2727
font-family: emoji, 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', Courier, monospace;
28+
font-variant-ligatures: none;
2829
height: 140px;
2930
overflow: auto;
3031
padding: 5px;

db/0.schema.sql

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ CREATE EXTENSION citext;
22

33
CREATE TYPE hole AS ENUM (
44
'12-days-of-christmas', '99-bottles-of-beer', 'abundant-numbers',
5-
'arabic-to-roman', 'brainfuck', 'christmas-trees', 'cubes', 'diamonds',
6-
'divisors', 'emirp-numbers', 'evil-numbers', 'fibonacci', 'fizz-buzz',
7-
'happy-numbers', 'leap-years', 'lucky-tickets', 'morse-decoder',
8-
'morse-encoder', 'niven-numbers', 'odious-numbers', 'ordinal-numbers',
9-
'pangram-grep', 'pascals-triangle', 'pernicious-numbers', 'poker',
10-
'prime-numbers', 'quine', 'rock-paper-scissors-spock-lizard',
11-
'roman-to-arabic', 'rule-110', 'seven-segment', 'sierpiński-triangle',
12-
'spelling-numbers', 'sudoku', 'ten-pin-bowling', 'united-states', 'λ',
13-
'π', 'τ', 'φ', '√2', '𝑒'
5+
'arabic-to-roman', 'brainfuck', 'christmas-trees', 'css-colors', 'cubes',
6+
'diamonds', 'divisors', 'emirp-numbers', 'evil-numbers', 'fibonacci',
7+
'fizz-buzz', 'happy-numbers', 'leap-years', 'lucky-tickets',
8+
'morse-decoder', 'morse-encoder', 'niven-numbers', 'odious-numbers',
9+
'ordinal-numbers', 'pangram-grep', 'pascals-triangle',
10+
'pernicious-numbers', 'poker', 'prime-numbers', 'quine',
11+
'rock-paper-scissors-spock-lizard', 'roman-to-arabic', 'rule-110',
12+
'seven-segment', 'sierpiński-triangle', 'spelling-numbers', 'sudoku',
13+
'ten-pin-bowling', 'united-states', 'λ', 'π', 'τ', 'φ', '√2', '𝑒'
1414
);
1515

1616
CREATE TYPE lang AS ENUM (
17-
'bash', 'brainfuck', 'c', 'c-sharp', 'f-sharp', 'fortran', 'go', 'haskell',
18-
'j', 'java', 'javascript', 'julia', 'lisp', 'lua', 'nim', 'perl', 'php',
19-
'powershell', 'python', 'raku', 'ruby', 'rust', 'swift'
17+
'bash', 'brainfuck', 'c', 'c-sharp', 'f-sharp', 'fortran', 'go',
18+
'haskell', 'j', 'java', 'javascript', 'julia', 'lisp', 'lua', 'nim',
19+
'perl', 'php', 'powershell', 'python', 'raku', 'ruby', 'rust', 'swift'
2020
);
2121

2222
CREATE TYPE trophy AS ENUM (

hole/css-colors.go

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
package hole
2+
3+
import (
4+
"math/rand"
5+
"strings"
6+
)
7+
8+
var cssColorArgs, cssColorOuts []string
9+
10+
// I'm open to a better way to lay these out in sync but create two arrays.
11+
// A sufficiently smart compiler would elide the non-escaping map. Go is not.
12+
func init() {
13+
colors := map[string]string{
14+
"AliceBlue": "#f0f8ff",
15+
"AntiqueWhite": "#faebd7",
16+
"Aqua": "#00ffff",
17+
"Aquamarine": "#7fffd4",
18+
"Azure": "#f0ffff",
19+
"Beige": "#f5f5dc",
20+
"Bisque": "#ffe4c4",
21+
"Black": "#000000",
22+
"BlanchedAlmond": "#ffebcd",
23+
"Blue": "#0000ff",
24+
"BlueViolet": "#8a2be2",
25+
"Brown": "#a52a2a",
26+
"Burlywood": "#deb887",
27+
"CadetBlue": "#5f9ea0",
28+
"Chartreuse": "#7fff00",
29+
"Chocolate": "#d2691e",
30+
"Coral": "#ff7f50",
31+
"CornflowerBlue": "#6495ed",
32+
"Cornsilk": "#fff8dc",
33+
"Crimson": "#dc143c",
34+
"Cyan": "#00ffff",
35+
"DarkBlue": "#00008b",
36+
"DarkCyan": "#008b8b",
37+
"DarkGoldenRod": "#b8860b",
38+
"DarkGray": "#a9a9a9",
39+
"DarkGreen": "#006400",
40+
"DarkGrey": "#a9a9a9",
41+
"DarkKhaki": "#bdb76b",
42+
"DarkMagenta": "#8b008b",
43+
"DarkOliveGreen": "#556b2f",
44+
"DarkOrange": "#ff8c00",
45+
"DarkOrchid": "#9932cc",
46+
"DarkRed": "#8b0000",
47+
"DarkSalmon": "#e9967a",
48+
"DarkSeaGreen": "#8fbc8f",
49+
"DarkSlateBlue": "#483d8b",
50+
"DarkSlateGray": "#2f4f4f",
51+
"DarkSlateGrey": "#2f4f4f",
52+
"DarkTurquoise": "#00ced1",
53+
"DarkViolet": "#9400d3",
54+
"DeepPink": "#ff1493",
55+
"DeepSkyBlue": "#00bfff",
56+
"DimGray": "#696969",
57+
"DimGrey": "#696969",
58+
"DodgerBlue": "#1e90ff",
59+
"FireBrick": "#b22222",
60+
"FloralWhite": "#fffaf0",
61+
"ForestGreen": "#228b22",
62+
"Fuchsia": "#ff00ff",
63+
"Gainsboro": "#dcdcdc",
64+
"GhostWhite": "#f8f8ff",
65+
"Gold": "#ffd700",
66+
"GoldenRod": "#daa520",
67+
"Gray": "#808080",
68+
"Green": "#008000",
69+
"GreenYellow": "#adff2f",
70+
"Grey": "#808080",
71+
"Honeydew": "#f0fff0",
72+
"HotPink": "#ff69b4",
73+
"IndianRed": "#cd5c5c",
74+
"Indigo": "#4b0082",
75+
"Ivory": "#fffff0",
76+
"Khaki": "#f0e68c",
77+
"Lavender": "#e6e6fa",
78+
"LavenderBlush": "#fff0f5",
79+
"LawnGreen": "#7cfc00",
80+
"LemonChiffon": "#fffacd",
81+
"LightBlue": "#add8e6",
82+
"LightCoral": "#f08080",
83+
"LightCyan": "#e0ffff",
84+
"LightGoldenRodYellow": "#fafad2",
85+
"LightGray": "#d3d3d3",
86+
"LightGreen": "#90ee90",
87+
"LightGrey": "#d3d3d3",
88+
"LightPink": "#ffb6c1",
89+
"LightSalmon": "#ffa07a",
90+
"LightSeaGreen": "#20b2aa",
91+
"LightSkyBlue": "#87cefa",
92+
"LightSlateGray": "#778899",
93+
"LightSlateGrey": "#778899",
94+
"LightSteelBlue": "#b0c4de",
95+
"LightYellow": "#ffffe0",
96+
"Lime": "#00ff00",
97+
"LimeGreen": "#32cd32",
98+
"Linen": "#faf0e6",
99+
"Magenta": "#ff00ff",
100+
"Maroon": "#800000",
101+
"MediumAquamarine": "#66cdaa",
102+
"MediumBlue": "#0000cd",
103+
"MediumOrchid": "#ba55d3",
104+
"MediumPurple": "#9370db",
105+
"MediumSeaGreen": "#3cb371",
106+
"MediumSlateBlue": "#7b68ee",
107+
"MediumSpringGreen": "#00fa9a",
108+
"MediumTurquoise": "#48d1cc",
109+
"MediumVioletRed": "#c71585",
110+
"MidnightBlue": "#191970",
111+
"MintCream": "#f5fffa",
112+
"MistyRose": "#ffe4e1",
113+
"Moccasin": "#ffe4b5",
114+
"NavajoWhite": "#ffdead",
115+
"Navy": "#000080",
116+
"OldLace": "#fdf5e6",
117+
"Olive": "#808000",
118+
"OliveDrab": "#6b8e23",
119+
"Orange": "#ffa500",
120+
"OrangeRed": "#ff4500",
121+
"Orchid": "#da70d6",
122+
"PaleGoldenRod": "#eee8aa",
123+
"PaleGreen": "#98fb98",
124+
"PaleTurquoise": "#afeeee",
125+
"PaleVioletRed": "#db7093",
126+
"PapayaWhip": "#ffefd5",
127+
"PeachPuff": "#ffdab9",
128+
"Peru": "#cd853f",
129+
"Pink": "#ffc0cb",
130+
"Plum": "#dda0dd",
131+
"PowderBlue": "#b0e0e6",
132+
"Purple": "#800080",
133+
"RebeccaPurple": "#663399",
134+
"Red": "#ff0000",
135+
"RosyBrown": "#bc8f8f",
136+
"RoyalBlue": "#4169e1",
137+
"SaddleBrown": "#8b4513",
138+
"Salmon": "#fa8072",
139+
"SandyBrown": "#f4a460",
140+
"SeaGreen": "#2e8b57",
141+
"SeaShell": "#fff5ee",
142+
"Sienna": "#a0522d",
143+
"Silver": "#c0c0c0",
144+
"SkyBlue": "#87ceeb",
145+
"SlateBlue": "#6a5acd",
146+
"SlateGray": "#708090",
147+
"SlateGrey": "#708090",
148+
"Snow": "#fffafa",
149+
"SpringGreen": "#00ff7f",
150+
"SteelBlue": "#4682b4",
151+
"Tan": "#d2b48c",
152+
"Teal": "#008080",
153+
"Thistle": "#d8bfd8",
154+
"Tomato": "#ff6347",
155+
"Turquoise": "#40e0d0",
156+
"Violet": "#ee82ee",
157+
"Wheat": "#f5deb3",
158+
"White": "#ffffff",
159+
"WhiteSmoke": "#f5f5f5",
160+
"Yellow": "#ffff00",
161+
"YellowGreen": "#9acd32",
162+
}
163+
164+
cssColorArgs = make([]string, 0, len(colors))
165+
cssColorOuts = make([]string, 0, len(colors))
166+
167+
for arg, out := range colors {
168+
cssColorArgs = append(cssColorArgs, arg)
169+
cssColorOuts = append(cssColorOuts, out)
170+
}
171+
}
172+
173+
func cssColors() ([]string, string) {
174+
args := make([]string, len(cssColorArgs))
175+
outs := make([]string, len(cssColorOuts))
176+
177+
copy(args, cssColorArgs)
178+
copy(outs, cssColorOuts)
179+
180+
rand.Shuffle(len(args), func(i, j int) {
181+
args[i], args[j] = args[j], args[i]
182+
outs[i], outs[j] = outs[j], outs[i]
183+
})
184+
185+
return args, strings.Join(outs, "\n")
186+
}

hole/hole.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func getAnswer(holeID, code string) ([]string, string) {
3030
args, answer = arabicToRoman(holeID == "roman-to-arabic")
3131
case "brainfuck":
3232
args, answer = brainfuck()
33+
case "css-colors":
34+
args, answer = cssColors()
3335
case "lucky-tickets":
3436
args, answer = luckyTickets()
3537
case "morse-decoder", "morse-encoder":
@@ -169,7 +171,14 @@ func Play(ctx context.Context, holeID, langID, code string) (score Scorecard) {
169171
score.Stdout = bytes.Replace(score.Stdout, []byte("Ⅿ"), []byte("M"), -1)
170172
}
171173

172-
score.Pass = score.Answer == string(score.Stdout) && len(score.Stdout) != 0
174+
if len(score.Stdout) != 0 {
175+
// TODO Generalise a case insensitve flag, should it apply to others?
176+
if holeID == "css-colors" {
177+
score.Pass = strings.EqualFold(score.Answer, string(score.Stdout))
178+
} else {
179+
score.Pass = score.Answer == string(score.Stdout)
180+
}
181+
}
173182

174183
return
175184
}

0 commit comments

Comments
 (0)