Skip to content

Commit bee913e

Browse files
FilipFilip
Filip
authored and
Filip
committed
golang secrethandshake solution
1 parent 25640f9 commit bee913e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package secret
2+
3+
var steps = []string{"wink", "double blink", "close your eyes", "jump"}
4+
5+
func Handshake(n uint) []string {
6+
var handshake = make([]string, 0)
7+
8+
if n <= 0 {
9+
return handshake
10+
11+
}
12+
13+
for s, step := range steps {
14+
if (1<<uint(s))&n > 0 {
15+
handshake = append(handshake, step)
16+
}
17+
}
18+
if (1<<uint(len(steps)))&n > 0 {
19+
reverse(handshake)
20+
21+
}
22+
return handshake
23+
}
24+
25+
func reverse(strings []string) {
26+
for i, j := 0, len(strings)-1; i < j; i, j = i+1, j-1 {
27+
strings[i], strings[j] = strings[j], strings[i]
28+
}
29+
30+
}

0 commit comments

Comments
 (0)