Skip to content

Commit 2dfbcfe

Browse files
committed
Add the "pangram-grep" hole
Updates #3
1 parent 31d18c8 commit 2dfbcfe

File tree

5 files changed

+57
-9
lines changed

5 files changed

+57
-9
lines changed

routes/hole.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var preambles = map[string]string{
1616
"fizz-buzz": `<h1>Fizz Buzz</h1><p>Print the numbers from <b>1</b> to <b>100</b> inclusive, each on their own line.</p><p>If, however, the number is a multiple of <b>three</b> then print <b>Fizz</b> instead, and if the number is a multiple of <b>five</b> then print <b>Buzz</b>.</p><p>For numbers which are multiples of <b>both three and five</b> then print <b>FizzBuzz</b>.</p>`,
1717
"happy-numbers": `<h1>Happy Numbers</h1><p>A happy number is defined by the following sequence: Starting with any positive integer, replace the number by the sum of the squares of its digits in base-ten, and repeat the process until the number either equals 1 (where it will stay), or it loops endlessly in a cycle that does not include 1. Those numbers for which this process ends in 1 are happy numbers, while those that do not end in 1 are sad numbers.<p>For example, 19 is happy, as the associated sequence is:</p><dl><dd>1<sup>2</sup> + 9<sup>2</sup> = 82<dd>8<sup>2</sup> + 2<sup>2</sup> = 68<dd>6<sup>2</sup> + 8<sup>2</sup> = 100<dd>1<sup>2</sup> + 0<sup>2</sup> + 0<sup>2</sup> = 1.</dl><p>Print all the happy numbers from <b>1</b> to <b>200</b> inclusive, each on their own line.</p>`,
1818
"odious-numbers": `<h1>Odious Numbers</h1><p>An odious number is a non-negative number that has an odd number of 1s in its binary expansion.<p>Print all the odious numbers from <b>0</b> to <b>50</b> inclusive, each on their own line.<p>Numbers that are not odious are called <a href=evil-numbers>evil numbers</a>.</p>`,
19+
"pangram-grep": `<h1>Pangram Grep</h1><p>A pangram is a sentence that uses every letter of a given alphabet.<p>Write a program that will receive various sentences as arguments and print those that are valid pangrams.</p>`,
1920
"pascals-triangle": `<h1>Pascal's Triangle</h1><p>Print the first <b>20 rows</b> of Pascal's triangle.</p>`,
2021
"pernicious-numbers": `<h1>Pernicious Numbers</h1><p>A pernicious number is a positive number where the sum of its binary expansion is a <a href=prime-numbers>prime number</a>.<p>For example, <b>5</b> is a pernicious number since <b>5 = 101<sub>2</sub></b> and <b>1 + 1 = 2</b>, which is prime.<p>Print all the pernicious numbers from <b>0</b> to <b>50</b> inclusive, each on their own line.</p>`,
2122
"prime-numbers": `<h1>Prime Numbers</h1><p>Print all the prime numbers from <b>1</b> to <b>100</b> inclusive, each on their own line.</p>`,

routes/home.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,16 @@ func home(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
6464
WHEN 'prime-numbers' THEN 8
6565
WHEN 'quine' THEN 9
6666
WHEN '99-bottles-of-beer' THEN 10
67-
WHEN 'seven-segment' THEN 11
68-
WHEN 'sierpiński-triangle' THEN 12
69-
WHEN 'π' THEN 13
70-
WHEN 'φ' THEN 14
71-
WHEN '𝑒' THEN 15
72-
WHEN 'τ' THEN 16
73-
WHEN 'arabic-to-roman' THEN 17
74-
WHEN 'roman-to-arabic' THEN 18
75-
WHEN 'spelling-numbers' THEN 19
67+
WHEN 'pangram-grep' THEN 11
68+
WHEN 'seven-segment' THEN 12
69+
WHEN 'sierpiński-triangle' THEN 13
70+
WHEN 'π' THEN 14
71+
WHEN 'φ' THEN 15
72+
WHEN '𝑒' THEN 16
73+
WHEN 'τ' THEN 17
74+
WHEN 'arabic-to-roman' THEN 18
75+
WHEN 'roman-to-arabic' THEN 19
76+
WHEN 'spelling-numbers' THEN 20
7677
END, row_number`,
7778
printHeader(w, r, 200),
7879
)
@@ -144,6 +145,8 @@ func home(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
144145
w.Write([]byte(`Fast><a href=happy-numbers>Happy Numbers`))
145146
case "odious-numbers":
146147
w.Write([]byte(`Fast><a href=odious-numbers>Odious Numbers`))
148+
case "pangram-grep":
149+
w.Write([]byte(`Medium><a href=pangram-grep>Pangram Grep`))
147150
case "pascals-triangle":
148151
w.Write([]byte(`Fast><a href=pascals-triangle>Pascal's Triangle`))
149152
case "pernicious-numbers":

routes/pangram-grep.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package routes
2+
3+
import "math/rand"
4+
5+
func pangramGrep() (args []string, out string) {
6+
all := [][]string{
7+
{"1", "A large fawn jumped quickly over white zinc boxes."},
8+
{"1", "A wizard’s job is to vex chumps quickly in fog."},
9+
{"1", "Bright vixens jump; dozy fowl quack."},
10+
{"0", "Five or six big jet planes zoomed past the tower."},
11+
{"1", "Fix problem quickly with galvanized jets."},
12+
{"1", "Go, lazy fat vixen; be shrewd, jump quick."},
13+
{"1", "Jumpy halfling dwarves pick quartz box."},
14+
{"0", "My ex pub quiz crowd gave happy thanks."},
15+
{"1", "Pack my box with five dozen liquor jugs."},
16+
{"1", "The five boxing wizards jump quickly."},
17+
{"1", "The jay, pig, fox, zebra and my wolves quack!"},
18+
{"0", "The quick brown fox jumps over a lazy cat."},
19+
{"1", "Waxy and quivering, jocks fumble the pizza."},
20+
{"1", "When zombies arrive, quickly fax judge Pat."},
21+
}
22+
23+
// Shuffle the whole set.
24+
for i := range all {
25+
j := rand.Intn(i + 1)
26+
all[i], all[j] = all[j], all[i]
27+
}
28+
29+
for _, v := range all {
30+
args = append(args, v[1])
31+
32+
if v[0] == "1" {
33+
out += v[1] + "\n"
34+
}
35+
}
36+
37+
// Drop the trailing newline.
38+
out = out[:len(out)-1]
39+
40+
return
41+
}

routes/scores.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var holes = [][]string{
1818
{"fizz-buzz", "Fizz Buzz"},
1919
{"happy-numbers", "Happy Numbers"},
2020
{"odious-numbers", "Odious Numbers"},
21+
{"pangram-grep", "Pangram Grep"},
2122
{"pascals-triangle", "Pascal's Triangle"},
2223
{"pernicious-numbers", "Pernicious Numbers"},
2324
{"prime-numbers", "Prime Numbers"},

routes/solution.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ func solution(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
5151

5252
// Drop the trailing newline.
5353
out.Exp = out.Exp[:len(out.Exp)-1]
54+
case "pangram-grep":
55+
args, out.Exp = pangramGrep()
5456
case "quine":
5557
out.Exp = in.Code
5658
case "roman-to-arabic":

0 commit comments

Comments
 (0)