csaboka

Untitled

Jun 24th, 2017
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.01 KB | None | 0 0
  1. -- The function get_name() should return a single string that is the name of the puzzle.
  2. --
  3. function get_name()
  4.     return "DIVISIBILITY BY ELEVEN"
  5. end
  6.  
  7. -- The function get_description() should return an array of strings, where each string is
  8. -- a line of description for the puzzle. Surrounding text with asterisks will cause it to
  9. -- be rendered in bold, something we use when mentioning a signal by name.
  10. --
  11. -- By using the syntax that we use in our puzzle descriptions, you can also create tables:
  12. --
  13. --       "| This is a table. | This is a second column. | This is a column with "
  14. --       "|                  |                          | multiple line of text."
  15. --       "----------------------------------------------------------------------"
  16. --       "| This is a second |                          | More text here!       "
  17. --       "| table row.       |                          |                       "
  18. --
  19. -- Puzzle descriptions are not automatically paginated, so you can use the string "<PAGE>"
  20. -- to start a new page of text. If you don't it will overflow and make Zach sad.
  21. --
  22. function get_description()
  23.     return {
  24.         "Given an XBus input *rand*, output to *out* high if the input is divisible by eleven.",
  25.     }
  26. end
  27.  
  28. -- The function get_board() allows you to specify an 18x7 "ASCII art" grid to customize
  29. -- the layout of the board and the placement of the input and output terminals. Generally
  30. -- speaking, inputs are placed on the left of boards, while outputs are placed on the right.
  31. --
  32. -- For empty space, use the '.' character.
  33. -- For buildable board space, use the '#' character.
  34. -- For an input or output terminal, use characters '0' through '9' no more than once each.
  35. -- For the bottom-left corner of the radio, use the 'R' character.
  36. -- For the bottom-left corners of dials, use characters 'A', 'B', and 'C'.
  37. --
  38. function get_board()
  39.     return [[
  40.         ....###########1..
  41.         ....############..
  42.         ...############...
  43.         ...############...
  44.         ...############...
  45.         ..############....
  46.         ..0###########....
  47.     ]]
  48. end
  49.  
  50. -- The function get_data() is called both to establish information about the puzzle (such as what
  51. -- the inputs and outputs are) and to generate the random test cases. Signal levels and XBus data
  52. -- should change from call to call, but information like the names and types of terminals should
  53. -- not change at all.
  54. --
  55. -- To create a standard input or output terminal, call create_terminal(). Valid terminal types are
  56. -- TYPE_SIMPLE, TYPE_XBUS, and TYPE_XBUS_NONBLOCKING. Valid terminal directions are DIR_INPUT and
  57. -- DIR_OUTPUT. Valid data for a simple I/O signal is an array of integers, 0 - 100 inclusive. Valid
  58. -- data for an XBus signal is an array of integer arrays, each with values -999 to 999 inclusive.
  59. --
  60. --       create_terminal(name, board_character, type, direction, data)
  61. --
  62. -- To create a radio (C2S-RF901), call create_radio(). You may only create one radio in each puzzle.
  63. -- Since radios are XBus-only, the only valid data for data_rx and data_tx are arrays of integer arrays,
  64. -- each with values -999 to 999 inclusive. You cannot customize the signal names for a radio.
  65. --
  66. -- By default the radio will be placed in the bottom-left corner of the screen. However, if you use an
  67. -- 'R' character in your board layout, the bottom-left corner of the radio will be placed there instead.
  68. --
  69. --       create_radio(data_rx, data_tx)
  70. --
  71. -- To create a dial (N4DL-1000), call create_dial(). You may create up to three dials in each puzzle.
  72. -- The names of dials should be kept short, as there is not much room to display them visually. A valid
  73. -- value is an integer between 0 and 99, inclusive.
  74. --
  75. -- By default dials will be placed in the bottom-left corner of the screen. However, if you use an
  76. -- 'A', 'B', or 'C' character in your board layout, the bottom-left corners of the first, second, and
  77. -- third dials will be placed there, respectively.
  78. --
  79. --       create_dial(name, value)
  80. --
  81. -- NOTE: To generate random values you should use math.random(). However, you SHOULD NOT seed
  82. --       the random number generator with a new seed value, as that is how the game ensures that
  83. --       the first test run is consistent for all users, and thus something that allows for the
  84. --       comparison of cycle scores.
  85. --
  86. -- NOTE: Fun fact! Arrays in Lua are implemented as tables (dictionaries) with integer keys that
  87. --       start at 1 by convention. Contrast this with nearly every other programming language, in
  88. --       which arrays start with an index of 0. Because of this, the 60 "time slices" that make
  89. --       up a test case are indexed from 1 to 60 inclusive.
  90. --
  91. function get_data()
  92.     rand = {}
  93.     out = {}
  94.     time = 1
  95.     while time <= 60 do
  96.         seed = math.random(0,100)
  97.             rand[time] = seed
  98.         if seed % 11 == 0 then
  99.             out[time] = 100
  100.         else
  101.             out[time] = 0
  102.         end
  103.         time = time + 1
  104.     end
  105.     create_terminal("rand", "0", TYPE_SIMPLE, DIR_INPUT, rand)
  106.     create_terminal("out", "1", TYPE_SIMPLE, DIR_OUTPUT, out)
  107. end
Advertisement
Add Comment
Please, Sign In to add comment