Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- )
- func test(direction string, amount int, currentPos int) [2]int{
- numOfZeros := 0
- newPos := 0
- switch direction {
- case "R":
- newPos = (currentPos + amount) % 100
- numOfZeros += (currentPos + amount) / 100
- case "L":
- multiplier := -((currentPos - amount) / 100) + 1
- newPos = (currentPos - amount + 100*multiplier) % 100
- if currentPos-amount <= 0 && currentPos != 0 {
- numOfZeros ++
- }
- numOfZeros -= (currentPos - amount) / 100
- }
- return [2]int{newPos, numOfZeros}
- }
- func true(direction string, amount int, currentPos int) [2]int{
- numOfZeros := 0
- newPos := currentPos
- for ; amount > 0; amount--{
- if direction == "R"{
- newPos ++
- if newPos == 100{
- newPos = 0
- numOfZeros++
- }
- }else {
- newPos --
- if newPos == 0{
- numOfZeros ++
- }
- if newPos < 0{
- newPos += 100
- }
- }
- }
- return [2]int{newPos, numOfZeros}
- }
- func main() {
- directions := [2]string{"L", "R"}
- for i := 0; i < 100; i ++{
- for j := 1; j < 2000; j++{
- for k := 0; k < 2; k ++{
- x:= test(directions[k], j, i)
- y:= true(directions[k], j, i)
- if x != y{
- printMovement(directions[k], j,x[0], x[1])
- printMovement(directions[k], j, y[0], y[1])
- }
- }
- }
- }
- }
- func printMovement(direction string, amount int, newPos int, numOfZeros int) {
- fmt.Println("The dial is rotated", direction, amount, "to point at", newPos, "pointing at zero a total of", numOfZeros, "times")
- }
Advertisement
Add Comment
Please, Sign In to add comment