summaryrefslogtreecommitdiff
path: root/go/secret-handshake/secret_handshake.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-08-25 12:34:26 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-08-25 12:34:26 +0200
commitc460ce761cb29d8d04f302dc6fd62fd0c170bfab (patch)
treee9e2d4d01c8cf06d6e0bcb331179e6f2e90bb349 /go/secret-handshake/secret_handshake.go
parentff662e72997f80c940ddb6f08b032a05f8f4f285 (diff)
Handshake
Diffstat (limited to 'go/secret-handshake/secret_handshake.go')
-rw-r--r--go/secret-handshake/secret_handshake.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/go/secret-handshake/secret_handshake.go b/go/secret-handshake/secret_handshake.go
new file mode 100644
index 0000000..8ad5fff
--- /dev/null
+++ b/go/secret-handshake/secret_handshake.go
@@ -0,0 +1,33 @@
+package secret
+
+var sign = map[int]string{
+ 1 << 0: "wink",
+ 1 << 1: "double blink",
+ 1 << 2: "close your eyes",
+ 1 << 3: "jump",
+}
+
+const rev = 1 << 4
+
+func reverse(s []string) []string {
+ for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
+ s[i], s[j] = s[j], s[i]
+ }
+ return s
+}
+
+func Handshake(n int) []string {
+ if n <= 0 {
+ return nil
+ }
+ var s []string
+ for i := 1; i < rev; i <<= 1 {
+ if n&i != 0 {
+ s = append(s, sign[i])
+ }
+ }
+ if n&rev != 0 {
+ s = reverse(s)
+ }
+ return s
+}