Created
December 8, 2015 10:01
-
-
Save madmoose/706d9fcd24c25c942805 to your computer and use it in GitHub Desktop.
Advent of Code 2015 day 7 scanf parsing example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
scanner := bufio.NewScanner(os.Stdin) | |
for scanner.Scan() { | |
line := scanner.Text() | |
var ( | |
mnemonic Mnemonic | |
src1, src2, dst string | |
) | |
if n, _ := fmt.Sscanf(line, "%s -> %s\n", &src1, &dst); n == 2 { | |
mnemonic = MOV | |
} else if n, _ := fmt.Sscanf(line, "%s AND %s -> %s\n", &src1, &src2, &dst); n == 3 { | |
mnemonic = AND | |
} else if n, _ := fmt.Sscanf(line, "%s OR %s -> %s\n", &src1, &src2, &dst); n == 3 { | |
mnemonic = OR | |
} else if n, _ := fmt.Sscanf(line, "%s RSHIFT %s -> %s\n", &src1, &src2, &dst); n == 3 { | |
mnemonic = RSHIFT | |
} else if n, _ := fmt.Sscanf(line, "%s LSHIFT %s -> %s\n", &src1, &src2, &dst); n == 3 { | |
mnemonic = LSHIFT | |
} else if n, _ := fmt.Sscanf(line, "NOT %s -> %s\n", &src1, &dst); n == 2 { | |
mnemonic = NOT | |
} else { | |
panic(line) | |
} | |
wires[dst] = Wire{mnemonic, src1, src2} | |
} | |
fmt.Println(value("a")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment