diff --git a/day08-add/day08-add b/day08-add/day08-add new file mode 100755 index 0000000..a74fcb5 Binary files /dev/null and b/day08-add/day08-add differ diff --git a/day08-add/main.go b/day08-add/main.go new file mode 100644 index 0000000..54de65c --- /dev/null +++ b/day08-add/main.go @@ -0,0 +1,658 @@ +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) +} diff --git a/day08/day08 b/day08/day08 index 37d5a4f..16de78d 100755 Binary files a/day08/day08 and b/day08/day08 differ diff --git a/day08/main.go b/day08/main.go index ebc1baa..2c6b533 100644 --- a/day08/main.go +++ b/day08/main.go @@ -11,26 +11,24 @@ import ( "time" ) -// First guess: 95 (too low) - func main() { - if len(os.Args) < 3 { - fmt.Println("Expected Display Width & Height as Arguments") + width := 50 + height := 6 + if len(os.Args) >= 2 { + width = atoi(os.Args[1]) + } + if len(os.Args) >= 3 { + height = atoi(os.Args[2]) } input := stdinToStringSlice() - // Test Display: - // d := CreateDisplay(7, 3) - // Prod Display: - // d := CreateDisplay(50, 6) - width := atoi(os.Args[1]) - height := atoi(os.Args[2]) + d := CreateDisplay(width, height) for idx, ins := range input { fmt.Println(idx, ins) d.ClearScreen() d.ProcInstruction(ins) d.PrintScreen() - time.Sleep(time.Millisecond * 75) + time.Sleep(time.Millisecond * 25) } fmt.Println("Voltage Used: ", d.GetVoltage()) }