adventofcode/2016/day08-add/main.go
2016-12-16 16:21:15 -06:00

659 lines
14 KiB
Go

package main
import (
"fmt"
"os"
"strconv"
"strings"
)
/* This program generates instructions to display words
* on the screen from day 8
* It assumes the screen size is 50x6
*/
func main() {
if len(os.Args) < 2 {
fmt.Println("Expected argument with word to convert.")
os.Exit(1)
}
wrd := strings.ToUpper(os.Args[1])
for i := len(wrd) - 1; i >= 0; i-- {
printInst(runeToInst(rune(wrd[i])))
if i > 0 {
printInst(shiftCols(2))
}
}
}
func printInst(i []string) {
for j := range i {
fmt.Println(i[j])
}
}
func runeToInst(r rune) []string {
var ret []string
switch r {
case 'A':
/*
##
# #
# #
####
# #
# #
*/
ret = append(ret, "rect 1x5")
ret = append(ret, "rotate column x=0 by 1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 3")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 3")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x5")
ret = append(ret, "rotate column x=0 by 1")
case 'B':
/*
###
# #
###
# #
# #
###
*/
ret = append(ret, "rect 1x2")
ret = append(ret, "rotate column x=0 by 2")
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 3")
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 2")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 3")
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 2")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x6")
case 'C':
/*
##
# #
#
#
# #
##
*/
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 3")
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 5")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 5")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x4")
ret = append(ret, "rotate column x=0 by 1")
case 'D':
/*
###
# #
# #
# #
# #
###
*/
ret = append(ret, "rect 1x4")
ret = append(ret, "rotate column x=0 by 1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 5")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 5")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x6")
case 'E':
/*
####
#
###
#
#
####
*/
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 5")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 3")
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 2")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 3")
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 2")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x6")
case 'F':
/*
####
#
###
#
#
#
*/
ret = append(ret, shiftCols(5)...)
ret = append(ret, "rect 3x1")
ret = append(ret, "rotate column x=2 by 2")
ret = append(ret, "rotate column x=1 by 2")
ret = append(ret, "rotate column x=0 by 2")
ret = append(ret, "rect 4x1")
ret = append(ret, "rect 1x6")
case 'G':
/*
###
#
# ##
# #
# #
##
*/
ret = append(ret, "rect 1x3")
ret = append(ret, "rotate column x=0 by 2")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 3")
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 2")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 5")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x4")
ret = append(ret, "rotate column x=0 by 1")
case 'H':
/*
# #
# #
####
# #
# #
# #
*/
ret = append(ret, "rect 1x6")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 2")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 2")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x6")
case 'I':
/*
###
#
#
#
#
###
*/
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 5")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x6")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 5")
ret = append(ret, "rect 1x1")
case 'J':
/*
#
#
#
# #
# #
##
*/
ret = append(ret, "rect 1x5")
ret = append(ret, shiftCols(2)...)
ret = append(ret, "rect 2x1")
ret = append(ret, "rotate column x=1 by 5")
ret = append(ret, "rotate column x=0 by 5")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x2")
ret = append(ret, "rotate column x=0 by 3")
case 'K':
/*
# #
# #
##
# #
# #
# #
*/
ret = append(ret, "rect 1x2")
ret = append(ret, "rotate column x=0 by 4")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 2")
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 2")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x6")
case 'L':
/*
#
#
#
#
#
####
*/
ret = append(ret, shiftCols(3)...)
ret = append(ret, "rect 4x1")
ret = append(ret, "rotate column x=0 by 5")
ret = append(ret, "rotate column x=1 by 5")
ret = append(ret, "rotate column x=2 by 5")
ret = append(ret, "rotate column x=3 by 5")
ret = append(ret, "rect 1x6")
case 'M':
/*
# #
####
####
# #
# #
# #
*/
ret = append(ret, "rect 1x6")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x2")
ret = append(ret, "rotate column x=0 by 1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x2")
ret = append(ret, "rotate column x=0 by 1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x6")
case 'N':
/*
# #
## #
# ##
# ##
# #
# #
*/
ret = append(ret, "rect 1x6")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x2")
ret = append(ret, "rotate column x=0 by 2")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x6")
case 'O':
/*
##
# #
# #
# #
# #
##
*/
ret = append(ret, "rect 1x4")
ret = append(ret, "rotate column x=0 by 1")
ret = append(ret, shiftCols(2)...)
ret = append(ret, "rect 2x1")
ret = append(ret, "rotate column x=1 by 5")
ret = append(ret, "rotate column x=0 by 5")
ret = append(ret, "rect 2x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x4")
ret = append(ret, "rotate column x=0 by 1")
case 'P':
/*
###
# #
###
#
#
#
*/
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 1")
ret = append(ret, shiftCols(2)...)
ret = append(ret, "rect 2x1")
ret = append(ret, "rotate column x=1 by 2")
ret = append(ret, "rotate column x=0 by 2")
ret = append(ret, "rect 2x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x6")
case 'Q':
/*
##
# #
# #
# #
# ##
###
*/
ret = append(ret, "rect 1x5")
ret = append(ret, "rotate column x=0 by 1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x2")
ret = append(ret, "rotate column x=0 by 4")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 5")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x4")
ret = append(ret, "rotate column x=0 by 1")
case 'R':
/*
###
# #
# #
###
# #
# #
*/
ret = append(ret, "rect 1x2")
ret = append(ret, "rotate column x=0 by 3")
ret = append(ret, "rect 1x2")
ret = append(ret, "rotate column x=0 by 1")
ret = append(ret, shiftCols(2)...)
ret = append(ret, "rect 2x1")
ret = append(ret, "rotate column x=1 by 3")
ret = append(ret, "rotate column x=0 by 3")
ret = append(ret, "rect 2x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x6")
case 'S':
/*
###
#
#
##
#
###
*/
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 4")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 2")
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 3")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 2")
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 3")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x2")
ret = append(ret, "rotate column x=0 by 1")
case 'T':
/*
####
#
#
#
#
#
*/
ret = append(ret, shiftCols(2)...)
ret = append(ret, "rect 3x1")
ret = append(ret, "rect 1x6")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
case 'U':
/*
# #
# #
# #
# #
# #
##
*/
ret = append(ret, "rect 1x5")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 5")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 5")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x5")
case 'V':
/*
# #
# #
# #
##
##
##
*/
ret = append(ret, "rect 1x3")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x3")
ret = append(ret, "rotate column x=0 by 3")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x3")
ret = append(ret, "rotate column x=0 by 3")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x3")
case 'W':
/*
# #
# #
# #
####
####
# #
*/
ret = append(ret, "rect 1x6")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x2")
ret = append(ret, "rotate column x=0 by 3")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x2")
ret = append(ret, "rotate column x=0 by 3")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x6")
case 'X':
/*
# #
# #
##
##
# #
# #
*/
ret = append(ret, "rect 1x2")
ret = append(ret, "rotate column x=0 by 4")
ret = append(ret, "rect 1x2")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x2")
ret = append(ret, "rotate column x=0 by 2")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x2")
ret = append(ret, "rotate column x=0 by 2")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x2")
ret = append(ret, "rotate column x=0 by 4")
ret = append(ret, "rect 1x2")
case 'Y':
/*
# #
# #
###
#
#
##
*/
ret = append(ret, "rect 1x5")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 3")
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 2")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 3")
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 2")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x2")
case 'Z':
/*
####
# #
#
#
# #
####
*/
ret = append(ret, "rect 1x2")
ret = append(ret, "rotate column x=0 by 4")
ret = append(ret, "rect 1x2")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 3")
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 2")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 2")
ret = append(ret, "rect 1x1")
ret = append(ret, "rotate column x=0 by 3")
ret = append(ret, "rect 1x1")
ret = append(ret, shiftCols(1)...)
ret = append(ret, "rect 1x2")
ret = append(ret, "rotate column x=0 by 4")
ret = append(ret, "rect 1x2")
case ' ':
ret = append(ret, shiftCols(4)...)
default:
ret = append(ret, shiftCols(4)...)
ret = append(ret, "rect 4x1")
ret = append(ret, "rotate column x=3 by 2")
ret = append(ret, "rotate column x=2 by 2")
ret = append(ret, "rotate column x=1 by 2")
ret = append(ret, "rotate column x=0 by 2")
}
return ret
}
func shiftCols(dist int) []string {
var ret []string
for i := 0; i < 6; i++ {
ret = append(ret, "rotate row y="+itoa(i)+" by "+itoa(dist))
}
return ret
}
func shiftRows(dist int) []string {
var ret []string
for i := 0; i < 50; i++ {
ret = append(ret, "rotate col x="+itoa(i)+" by "+itoa(dist))
}
return ret
}
func itoa(i int) string {
return strconv.Itoa(i)
}