Created
December 21, 2016 14:36
-
-
Save markoo/923efa51c64ed4ce9761a6d450a4e4c6 to your computer and use it in GitHub Desktop.
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
package taxicab | |
import ( | |
"fmt" | |
"strconv" | |
"strings" | |
) | |
func main() { | |
si := "" | |
y := 0 | |
dirX := 0 | |
dirY := 1 | |
direction := "N" | |
directions := strings.Split("L3, R2, L5, R1, L1, L2, L2, R1, R5, R1, L1, L2, R2, R4, L4, L3, L3, R5, L1, R3, L5, L2, R4, L5, R4, R2, L2, L1, R1, L3, L3, R2, R1, L4, L1, L1, R4, R5, R1, L2, L1, R188, R4, L3, R54, L4, R4, R74, R2, L4, R185, R1, R3, R5, L2, L3, R1, L1, L3, R3, R2, L3, L4, R1, L3, L5, L2, R2, L1, R2, R1, L4, R5, R4, L5, L5, L4, R5, R4, L5, L3, R4, R1, L5, L4, L3, R5, L5, L2, L4, R4, R4, R2, L1, L3, L2, R5, R4, L5, R1, R2, R5, L2, R4, R5, L2, L3, R3, L4, R3, L2, R1, R4, L5, R1, L5, L3, R4, L2, L2, L5, L5, R5, R2, L5, R1, L3, L2, L2, R3, L3, L4, R2, R3, L1, R2, L5, L3, R4, L4, R4, R3, L3, R1, L3, R5, L5, R1, R5, R3, L1", ",") | |
for i := 0; i < len(directions); i++ { | |
if i == 0 { | |
if strings.Index(directions[i], "L") > -1 { | |
dirX = -1 | |
dirY = 0 | |
si = strings.TrimPrefix(directions[i], "L") | |
x, err := strconv.Atoi(si) | |
if err != nil { | |
fmt.Println("strconv didn't work") | |
} else { | |
x = x * dirX | |
} | |
} | |
} else { | |
switch direction { | |
case "N": | |
if strings.Index(directions[i], "L") > -1 { | |
direction = "W" | |
} else { | |
direction = "E" | |
} | |
case "E": | |
if strings.Index(directions[i], "L") > -1 { | |
direction = "N" | |
} else { | |
direction = "S" | |
} | |
case "S": | |
if strings.Index(directions[i], "L") > -1 { | |
direction = "E" | |
} else { | |
direction = "W" | |
} | |
case "W": | |
if strings.Index(directions[i], "L") > -1 { | |
direction = "S" | |
} else { | |
direction = "N" | |
} | |
} | |
if strings.Index(directions[i], "R") > -1 { | |
} else { | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment