Skip to content

Instantly share code, notes, and snippets.

@bacher
Created May 17, 2017 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bacher/32d10d050d716d861f077497bb2f184c to your computer and use it in GitHub Desktop.
Save bacher/32d10d050d716d861f077497bb2f184c to your computer and use it in GitHub Desktop.
IBM Challenge May 2017 (CABACB)
package main
import (
"os"
)
const (
CHARS_COUNT = 20
LEN = CHARS_COUNT*2 + 1
)
var str = make([]int, LEN)
var symbols = make([]bool, CHARS_COUNT+1)
var dash = false
func main() {
run(0)
}
func run(index int) {
if index == LEN {
printResult()
return
}
if str[index] != 0 {
run(index + 1)
return
}
for i := 1; i <= CHARS_COUNT; i++ {
if index+i+1 >= LEN {
break
}
if symbols[i] == false && str[index+i+1] == 0 {
symbols[i] = true
str[index] = i
str[index+i+1] = i
run(index + 1)
symbols[i] = false
str[index] = 0
str[index+i+1] = 0
}
}
if dash == false && index > 0 {
str[index] = 45
dash = true
run(index + 1)
str[index] = 0
dash = false
}
}
func printResult() {
for _, char := range str {
if char != 45 {
char += 64
}
os.Stdout.WriteString(string(char))
}
os.Stdout.WriteString("\n")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment