Guest User

Untitled

a guest
Dec 4th, 2025
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | Source Code | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. )
  6. func test(direction string, amount int, currentPos int) [2]int{
  7. numOfZeros := 0
  8. newPos := 0
  9. switch direction {
  10. case "R":
  11. newPos = (currentPos + amount) % 100
  12. numOfZeros += (currentPos + amount) / 100
  13. case "L":
  14. multiplier := -((currentPos - amount) / 100) + 1
  15. newPos = (currentPos - amount + 100*multiplier) % 100
  16.  
  17. if currentPos-amount <= 0 && currentPos != 0 {
  18. numOfZeros ++
  19. }
  20. numOfZeros -= (currentPos - amount) / 100
  21. }
  22. return [2]int{newPos, numOfZeros}
  23. }
  24.  
  25. func true(direction string, amount int, currentPos int) [2]int{
  26. numOfZeros := 0
  27. newPos := currentPos
  28. for ; amount > 0; amount--{
  29. if direction == "R"{
  30. newPos ++
  31. if newPos == 100{
  32. newPos = 0
  33. numOfZeros++
  34. }
  35. }else {
  36. newPos --
  37. if newPos == 0{
  38. numOfZeros ++
  39. }
  40. if newPos < 0{
  41. newPos += 100
  42. }
  43. }
  44. }
  45. return [2]int{newPos, numOfZeros}
  46. }
  47.  
  48. func main() {
  49. directions := [2]string{"L", "R"}
  50. for i := 0; i < 100; i ++{
  51. for j := 1; j < 2000; j++{
  52. for k := 0; k < 2; k ++{
  53. x:= test(directions[k], j, i)
  54. y:= true(directions[k], j, i)
  55. if x != y{
  56. printMovement(directions[k], j,x[0], x[1])
  57. printMovement(directions[k], j, y[0], y[1])
  58. }
  59. }
  60. }
  61. }
  62. }
  63.  
  64. func printMovement(direction string, amount int, newPos int, numOfZeros int) {
  65. fmt.Println("The dial is rotated", direction, amount, "to point at", newPos, "pointing at zero a total of", numOfZeros, "times")
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment