Advertisement
Sorceress

Advent Warmup Generator

Nov 27th, 2017
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. TYPE Pt
  2. x AS INTEGER
  3. y AS INTEGER
  4. v AS INTEGER
  5. END TYPE
  6. DIM Pt(1000) AS Pt
  7.  
  8. SCREEN 13
  9.  
  10. 'Puzzle Generator
  11. 'walk in a square with some random element. more interesting than a random blob.
  12. seed = 0
  13. RANDOMIZE seed
  14. OPEN "c:\warmup.txt" FOR BINARY AS #1
  15. c = 250 'number of square walking steps to take
  16. FOR i = 1 TO 1999
  17. IF (1999 - i) * RND < c THEN 'uniformly distributed square-walking steps
  18. d = INT(i / 500) 'this walks us in a square
  19. c = c - 1
  20. ELSE
  21. d = INT(RND * 5) 'this steps us randomly (or drops markers)
  22. END IF
  23. IF d = 0 THEN a$ = "Up, "
  24. IF d = 1 THEN a$ = "Left, "
  25. IF d = 2 THEN a$ = "Down, "
  26. IF d = 3 THEN a$ = "Right, "
  27. IF d = 4 THEN
  28. IF RND < .5 THEN a$ = "A, " ELSE a$ = "B, "
  29. END IF
  30. PUT #1, , a$
  31. NEXT
  32. a$ = "Start" 'don't forget to terminate!
  33. PUT #1, , a$
  34. CLOSE #1
  35. PRINT "generation complete"
  36. SLEEP
  37.  
  38. 'Puzzle Solver
  39. OPEN "c:\warmup.txt" FOR INPUT AS #1
  40. c = 0
  41. WHILE NOT EOF(1)
  42. INPUT #1, r$: c = c + 1
  43. LOCATE 1, 1: PRINT c; r$; " "
  44. col = 8
  45. IF r$ = "Up" THEN y = y + 1
  46. IF r$ = "Down" THEN y = y - 1
  47. IF r$ = "Left" THEN x = x - 1
  48. IF r$ = "Right" THEN x = x + 1
  49. 'build up arrays of A and B markers
  50. IF r$ = "A" THEN col = 12: p = p + 1: Pt(p).x = x: Pt(p).y = y: Pt(p).v = 0
  51. IF r$ = "B" THEN col = 10: p = p + 1: Pt(p).x = x: Pt(p).y = y: Pt(p).v = 1
  52. PSET (160 + x, 100 + y), col
  53. WEND
  54. CLOSE #1
  55. PRINT p
  56. SLEEP
  57.  
  58. 'Part 1
  59. FOR i = 1 TO p
  60. dx = Pt(i).x
  61. dy = Pt(i).y
  62. d = ABS(dx) + ABS(dy)
  63. IF d > dmax THEN dmax = d: i0 = i
  64. NEXT
  65. PRINT dmax
  66. CIRCLE (160, 100), 5, 15
  67. CIRCLE (160 + Pt(i0).x, 100 + Pt(i0).y), 5, 15
  68. SLEEP
  69.  
  70. 'Part 2
  71. 'small enough set for O[n^2] search. would use spatial partitioning otherwise.
  72. dmax = 0
  73. FOR i = 1 TO p - 1
  74. FOR j = i + 1 TO p
  75. dx = Pt(i).x - Pt(j).x
  76. dy = Pt(i).y - Pt(j).y
  77. d = ABS(dx) + ABS(dy)
  78. IF d > dmax AND Pt(i).v <> Pt(j).v THEN dmax = d: i0 = i: j0 = j
  79. NEXT
  80. NEXT
  81. PRINT dmax
  82. CIRCLE (160 + Pt(i0).x, 100 + Pt(i0).y), 5, 12
  83. CIRCLE (160 + Pt(j0).x, 100 + Pt(j0).y), 5, 10
  84. SLEEP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement