Skip to content

Commit

Permalink
Add "Rock-paper-scissors-Spock-lizard" hole
Browse files Browse the repository at this point in the history
  • Loading branch information
JRaspass committed Jun 17, 2019
1 parent 3459bfb commit de9369a
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 10 deletions.
14 changes: 13 additions & 1 deletion assets/build
Expand Up @@ -26,7 +26,7 @@ GO

my ( %data, %paths );

for (<assets/*.{css,ico,js}>) {
for ( (my $w = 'assets/twemoji.woff2'), <assets/*.{css,ico,js}> ) {
say;

my $data = slurp($_);
Expand All @@ -45,11 +45,23 @@ GO

next;
}
elsif ( $_ eq 'twemoji.woff2' ) {
$data{$name} = $data;
my $path = $paths{$name} = '/assets/' . md5_base64($data) =~ y|+/|-_|r;

print $fh <<GO;
case "$path":
w.Write($name)
GO

next;
}

$data =~ s|/\* include ([^ ]+) +\*/|slurp("assets/includes/$1")|eg;

if (/\.css$/) {
$data =~ s|svg\(([^#]+)(.+)\)|svg($1, $2)|eg;
$data =~ s|twemojiWoff2|$paths{twemojiWoff2}|;

$data = run($data, 'csso');
}
Expand Down
13 changes: 11 additions & 2 deletions assets/common.css
@@ -1,5 +1,11 @@
@font-face {
font-family: emoji;
src: url('twemojiWoff2');
unicode-range: U+2702, U+1F48E, U+1F4C4, U+1F596, U+1F98E;
}

body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
font-family: emoji, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
font-size: 16px;
margin: 50px 0 0;
}
Expand Down Expand Up @@ -108,7 +114,7 @@ header nav img {
pre,
.CodeMirror,
#hole table {
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
font-family: emoji, 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
}

select {
Expand Down Expand Up @@ -272,7 +278,10 @@ tr.me { background: #5cf }
color: #fff;
display: block;
font-size: 26px;
overflow: hidden;
padding: 10px;
text-overflow: ellipsis;
white-space: nowrap;
}

#home div > a:last-child {
Expand Down
7 changes: 4 additions & 3 deletions assets/hole.css
Expand Up @@ -10,7 +10,7 @@ aside > div {
background: #fff;
border: 2px solid #369;
border-left: 0;
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
font-family: emoji, 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
height: 140px;
overflow: auto;
padding: 5px;
Expand Down Expand Up @@ -208,7 +208,8 @@ main nav a:nth-child(3):before {
text-align: center;
}

#alert a {
#alert a,
#preamble a {
text-decoration: underline;
}

Expand All @@ -223,7 +224,7 @@ main nav a:nth-child(3):before {
#arg span {
background: #ddd;
border-radius: 10px;
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
font-family: emoji, 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
line-height: 30px;
padding: 3px 7px;
white-space: pre;
Expand Down
1 change: 0 additions & 1 deletion assets/includes/codemirror.css
Expand Up @@ -2,7 +2,6 @@

.CodeMirror {
/* Set height, width, borders, and global font properties here */
font-family: monospace;
height: 300px;
color: black;
direction: ltr;
Expand Down
Binary file added assets/twemoji.woff2
Binary file not shown.
1 change: 1 addition & 0 deletions db.sql
Expand Up @@ -44,6 +44,7 @@ CREATE TYPE public.hole AS ENUM (
'poker',
'prime-numbers',
'quine',
'rock-paper-scissors-spock-lizard',
'roman-to-arabic',
'rule-110',
'seven-segment',
Expand Down
1 change: 1 addition & 0 deletions holes.md
Expand Up @@ -20,6 +20,7 @@ Gaming
======

* Poker
* Rock-paper-scissors-Spock-lizard
* Sudoku
* Ten-pin Bowling

Expand Down
1 change: 1 addition & 0 deletions routes/render.go
Expand Up @@ -82,6 +82,7 @@ func Render(w http.ResponseWriter, r *http.Request, code int, name string, data
"connect-src 'self';" +
"default-src 'none';" +
"form-action 'none';" +
"font-src 'self';" +
"frame-ancestors 'none';" +
"img-src 'self' data: avatars.githubusercontent.com;" +
"script-src 'self';" +
Expand Down
53 changes: 53 additions & 0 deletions routes/rock-paper-scissors-spock-lizard.go
@@ -0,0 +1,53 @@
package routes

import (
"math/rand"
"strings"
)

var rockPaperScissorsSpockLizardGames = [...][2]string{
{"💎💎", "Tie"},
{"💎📄", "📄 covers 💎"},
{"💎✂", "💎 crushes ✂"},
{"💎🖖", "🖖 vaporizes 💎"},
{"💎🦎", "💎 crushes 🦎"},
{"📄💎", "📄 covers 💎"},
{"📄📄", "Tie"},
{"📄✂", "✂ cuts 📄"},
{"📄🖖", "📄 disproves 🖖"},
{"📄🦎", "🦎 eats 📄"},
{"✂💎", "💎 crushes ✂"},
{"✂📄", "✂ cuts 📄"},
{"✂✂", "Tie"},
{"✂🖖", "🖖 smashes ✂"},
{"✂🦎", "✂ decapitates 🦎"},
{"🖖💎", "🖖 vaporizes 💎"},
{"🖖📄", "📄 disproves 🖖"},
{"🖖✂", "🖖 smashes ✂"},
{"🖖🖖", "Tie"},
{"🖖🦎", "🦎 poisons 🖖"},
{"🦎💎", "💎 crushes 🦎"},
{"🦎📄", "🦎 eats 📄"},
{"🦎✂", "✂ decapitates 🦎"},
{"🦎🖖", "🦎 poisons 🖖"},
{"🦎🦎", "Tie"},
}

func rockPaperScissorsSpockLizard() ([]string, string) {
args := make([]string, len(rockPaperScissorsSpockLizardGames))
outs := make([]string, len(rockPaperScissorsSpockLizardGames))

for i, game := range rockPaperScissorsSpockLizardGames {
args[i] = game[0]
outs[i] = game[1]
}

// Shuffle
for i := range args {
j := rand.Intn(i + 1)
args[i], args[j] = args[j], args[i]
outs[i], outs[j] = outs[j], outs[i]
}

return args, strings.Join(outs, "\n")
}
2 changes: 2 additions & 0 deletions routes/solution.go
Expand Up @@ -50,6 +50,8 @@ func solution(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
args, out.Exp = poker()
case "quine":
out.Exp = in.Code
case "rock-paper-scissors-spock-lizard":
args, out.Exp = rockPaperScissorsSpockLizard()
case "seven-segment":
args = make([]string, 1)
args[0], out.Exp = sevenSegment()
Expand Down
4 changes: 4 additions & 0 deletions routes/types.go
Expand Up @@ -272,6 +272,10 @@ A Partridge in a Pear Tree.</blockquote>`,
"", "",
"quine", "Quine", "Fast",
"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>",
}, {
"", "",
"rock-paper-scissors-spock-lizard", "Rock-paper-scissors-Spock-lizard", "Slow",
"✂ cuts 📄 covers 💎 crushes 🦎 poisons 🖖 smashes ✂ decapitates 🦎 eats 📄 disproves 🖖 vaporizes 💎 crushes ✂.</p><p><a href=http://www.samkass.com/theories/RPSSL.html>http://www.samkass.com/theories/RPSSL.html</a></p><ul><li>Rock is represented by <a href=//emojipedia.org/gem-stone/>“💎” (U+1F48E Gem Stone)</a>, though may be replaced by <a href=//emojipedia.org/rock/>“Rock” when Unicode 13.0 ships in 2020</a>.<li>Paper is represented by <a href=//emojipedia.org/page-facing-up/>“📄” (U+1F4C4 Page Facing Up)</a>.<li>Scissors are represented by <a href=//emojipedia.org/black-scissors/>“✂” (U+2702 Black Scissors)</a>, note <b>without</b> the U+FE0F variation selector.<li>Spock is represented by <a href=//emojipedia.org/raised-hand-with-part-between-middle-and-ring-fingers/>“🖖” (U+1F596 Raised Hand With Part Between Middle and Ring Fingers)</a>.<li>Lizard is represented by <a href=//emojipedia.org/lizard/>“🦎” (U+1F98E Lizard)</a>.</ul>",
}, {
"", "",
"roman-to-arabic", "Roman to Arabic", "Slow",
Expand Down
4 changes: 2 additions & 2 deletions views/about.html
Expand Up @@ -36,8 +36,8 @@ <h2>Frequently Asked Questions</h2>
<dt>How Are Solutions Scored?
<dd>
The score of your solution is the count of the Unicode characters
in your source code. This means both "A" (U+0041 Latin Capital
Letter A) and "😉" (U+1F609 Winking Face) cost the same despite
in your source code. This means both “A” (U+0041 Latin Capital
Letter A) and “😉” (U+1F609 Winking Face) cost the same despite
the 1:4 ratio in byte count in UTF-8.

<dt>How Is My Overall Score Computed?
Expand Down
2 changes: 1 addition & 1 deletion views/hole.html
Expand Up @@ -20,7 +20,7 @@
<a href={{ .Data.Hole.Next }}>Next Hole</a>
</nav>
<h1>{{ .Data.Hole.Name }}</h1>
<div>
<div id=preamble>
<p>{{ .Data.Hole.Preamble }}
</div>
<div id=tabs>
Expand Down

0 comments on commit de9369a

Please sign in to comment.