You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

#### 58 lines 789 B Raw Permalink Blame History

 ```package day12 ``` ``` ``` ```import ( ``` ``` "log" ``` ```) ``` ``` ``` ```type State struct { ``` ``` Dir, North, East int ``` ```} ``` ``` ``` ```func Solve1() { ``` ``` state := State{Dir: 90, North: 0, East: 0} ``` ``` ``` ``` for _, row := range rows { ``` ``` switch row.Char { ``` ``` case "N": ``` ``` state.North += row.Arg ``` ``` ``` ``` case "S": ``` ``` state.North -= row.Arg ``` ``` ``` ``` case "E": ``` ``` state.East += row.Arg ``` ``` ``` ``` case "W": ``` ``` state.East -= row.Arg ``` ``` ``` ``` case "R": ``` ``` state.Dir += row.Arg ``` ``` ``` ``` case "L": ``` ``` state.Dir += 360 - row.Arg ``` ``` ``` ``` case "F": ``` ``` switch state.Dir % 360 { ``` ``` case 0: ``` ``` state.North += row.Arg ``` ``` case 90: ``` ``` state.East += row.Arg ``` ``` case 180: ``` ``` state.North -= row.Arg ``` ``` case 270: ``` ``` state.East -= row.Arg ``` ``` } ``` ``` } ``` ``` } ``` ``` ``` ``` if state.East < 0 { ``` ``` state.East *= -1 ``` ``` } ``` ``` ``` ``` if state.North < 0 { ``` ``` state.North *= -1 ``` ``` } ``` ``` ``` ``` log.Printf("2020-12-12.01: Answer: %d\n", state.North+state.East) ``` ```} ```