csaboka

Untitled

Jun 24th, 2017
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.22 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 "RECIPROCALS"
  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 *input*, produce the first 3 digits after the decimal point of its reciprocal (truncated), and return it to *output*.",
  25.     "The *input* is not normally distributed - it is based on the distribution 10^*a*+1,       where *a* is a random number in the interval [0,3).",
  26.     }
  27. end
  28.  
  29. -- The function get_board() allows you to specify an 18x7 "ASCII art" grid to customize
  30. -- the layout of the board and the placement of the input and output terminals. Generally
  31. -- speaking, inputs are placed on the left of boards, while outputs are placed on the right.
  32. --
  33. -- For empty space, use the '.' character.
  34. -- For buildable board space, use the '#' character.
  35. -- For an input or output terminal, use characters '0' through '9' no more than once each.
  36. -- For the bottom-left corner of the radio, use the 'R' character.
  37. -- For the bottom-left corners of dials, use characters 'A', 'B', and 'C'.
  38. --
  39. function get_board()
  40.     return [[
  41.         ...#############..
  42.         ...#############..
  43.         .################.
  44.         .#0#############1.
  45.         .################.
  46.         ...#############..
  47.         ...#############..
  48.     ]]
  49. end
  50.  
  51. -- The function get_data() is called both to establish information about the puzzle (such as what
  52. -- the inputs and outputs are) and to generate the random test cases. Signal levels and XBus data
  53. -- should change from call to call, but information like the names and types of terminals should
  54. -- not change at all.
  55. --
  56. -- To create a standard input or output terminal, call create_terminal(). Valid terminal types are
  57. -- TYPE_SIMPLE, TYPE_XBUS, and TYPE_XBUS_NONBLOCKING. Valid terminal directions are DIR_INPUT and
  58. -- DIR_OUTPUT. Valid data for a simple I/O signal is an array of integers, 0 - 100 inclusive. Valid
  59. -- data for an XBus signal is an array of integer arrays, each with values -999 to 999 inclusive.
  60. --
  61. --       create_terminal(name, board_character, type, direction, data)
  62. --
  63. -- To create a radio (C2S-RF901), call create_radio(). You may only create one radio in each puzzle.
  64. -- Since radios are XBus-only, the only valid data for data_rx and data_tx are arrays of integer arrays,
  65. -- each with values -999 to 999 inclusive. You cannot customize the signal names for a radio.
  66. --
  67. -- By default the radio will be placed in the bottom-left corner of the screen. However, if you use an
  68. -- 'R' character in your board layout, the bottom-left corner of the radio will be placed there instead.
  69. --
  70. --       create_radio(data_rx, data_tx)
  71. --
  72. -- To create a dial (N4DL-1000), call create_dial(). You may create up to three dials in each puzzle.
  73. -- The names of dials should be kept short, as there is not much room to display them visually. A valid
  74. -- value is an integer between 0 and 99, inclusive.
  75. --
  76. -- By default dials will be placed in the bottom-left corner of the screen. However, if you use an
  77. -- 'A', 'B', or 'C' character in your board layout, the bottom-left corners of the first, second, and
  78. -- third dials will be placed there, respectively.
  79. --
  80. --       create_dial(name, value)
  81. --
  82. -- NOTE: To generate random values you should use math.random(). However, you SHOULD NOT seed
  83. --       the random number generator with a new seed value, as that is how the game ensures that
  84. --       the first test run is consistent for all users, and thus something that allows for the
  85. --       comparison of cycle scores.
  86. --
  87. -- NOTE: Fun fact! Arrays in Lua are implemented as tables (dictionaries) with integer keys that
  88. --       start at 1 by convention. Contrast this with nearly every other programming language, in
  89. --       which arrays start with an index of 0. Because of this, the 60 "time slices" that make
  90. --       up a test case are indexed from 1 to 60 inclusive.
  91. --
  92. function get_data()
  93.     input = {}
  94.     output = {}
  95.     time = 1
  96.     while time <= 60 do
  97.     seed = math.floor(10^(math.random()*3))-1
  98.     if seed == 0 then
  99.         seed = 1
  100.     end
  101.     input[time] = {seed}
  102.     output[time] = {math.floor(1000*((1/seed)%1))}
  103.     time = time + 1
  104.     end
  105.     create_terminal("input", "0", TYPE_XBUS, DIR_INPUT, input)
  106.     create_terminal("output", "1", TYPE_XBUS, DIR_OUTPUT, output)
  107. end
Advertisement
Add Comment
Please, Sign In to add comment