Browse Source

Code cleanup...

remove Public status of bitmask constants
	move string slice initialization into function declaration
master
jimi 9 years ago
parent
commit
00b723f275
  1. 33
      secret_handshake.go

33
secret_handshake.go

@ -1,24 +1,23 @@
// Package secret converts an integer value into a secret phrase
// Package secret converts an integer value into a secret phrase.
package secret
// Define friendly names for the bitmasks.
const (
WINK int = 1 << iota // 00001
BLINK // 00010
CLOSE // 00100
JUMP // 01000
REVERSE // 10000
wnk int = 1 << iota // 00001
bli // 00010
clo // 00100
jmp // 01000
rev // 10000
)
// Handshake receives an integer argument and returns a string slice with
// the code words in the proper sequence.
func Handshake(i int) []string {
var h []string
func Handshake(i int) (h []string) {
m := map[int]string{
WINK: "wink",
BLINK: "double blink",
CLOSE: "close your eyes",
JUMP: "jump",
wnk: "wink",
bli: "double blink",
clo: "close your eyes",
jmp: "jump",
}
// Return the original empty slice if the integer is negative.
@ -27,12 +26,12 @@ func Handshake(i int) []string {
}
// Pre-define the ordered key sets.
keys := []int{WINK, BLINK, CLOSE, JUMP}
rev := []int{JUMP, CLOSE, BLINK, WINK}
keys := []int{wnk, bli, clo, jmp}
bkwd := []int{jmp, clo, bli, wnk}
// Use the reversed key set if the REVERSE bit is set.
if i&REVERSE != 0 {
keys = rev
// Use the reversed key set if the 5th bit is set.
if i&rev != 0 {
keys = bkwd
}
// Build the string slice based on the bitmask.

Loading…
Cancel
Save