Advertisement
Guest User

TIS-100 Level: Number Base Converter

a guest
Jul 6th, 2015
929
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 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 "NUMBER BASE CONVERTER"
  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. The text you return from get_description() will
  9. -- be automatically formatted and wrapped to fit inside the puzzle information box.
  10. --
  11. function get_description()
  12. return { "READ BASE 10 NUMBER FROM IN.A",
  13. "READ BASE FROM IN.B",
  14. "CONVERT NUMBER TO PROVIDED BASE",
  15. "WRITE CONVERTED NUMBER TO OUT"}
  16. end
  17.  
  18. -- The function get_streams() should return an array of streams. Each stream is described
  19. -- by an array with exactly four values: a STREAM_* value, a name, a position, and an array
  20. -- of integer values between -999 and 999 inclusive.
  21. --
  22. -- STREAM_INPUT: An input stream containing up to 39 numerical values.
  23. -- STREAM_OUTPUT: An output stream containing up to 39 numerical values.
  24. -- STREAM_IMAGE: An image output stream, containing exactly 30*18 numerical values between 0
  25. -- and 4, representing the full set of "pixels" for the target image.
  26. --
  27. -- NOTE: Arrays in Lua are implemented as tables (dictionaries) with integer keys that start
  28. -- at 1 by convention. The sample code below creates an input array of 39 random values
  29. -- and an output array that doubles all of the input values.
  30. --
  31. -- NOTE: To generate random values you should use math.random(). However, you SHOULD NOT seed
  32. -- the random number generator with a new seed value, as that is how TIS-100 ensures that
  33. -- the first test run is consistent for all users, and thus something that allows for the
  34. -- comparison of cycle scores.
  35. --
  36. -- NOTE: Position values for streams should be between 0 and 3, which correspond to the far
  37. -- left and far right of the TIS-100 segment grid. Input streams will be automatically
  38. -- placed on the top, while output and image streams will be placed on the bottom.
  39. --
  40. function get_streams()
  41. input_vals = {}
  42. input_bases = {}
  43. output = {}
  44.  
  45. for i = 1,39 do
  46. input_bases[i] = math.random(2, 10)
  47. -- max val below based on highest displayable in this number base
  48. input_vals[i] = math.random(1, (input_bases[i] ^ 3) - 1)
  49.  
  50. -- convert random number to provided base
  51. out_string = ""
  52. num = input_vals[i]
  53. base = input_bases[i]
  54. while num ~= 0 do
  55. remainder = tostring(num % base)
  56. num = math.floor(num / base)
  57. out_string = remainder .. out_string
  58. end
  59. output[i] = tonumber(out_string)
  60. end
  61. return {
  62. { STREAM_INPUT, "IN.A", 1, input_vals },
  63. { STREAM_INPUT, "IN.B", 2, input_bases },
  64. { STREAM_OUTPUT, "OUT", 2, output },
  65. }
  66. end
  67.  
  68. -- The function get_layout() should return an array of exactly 12 TILE_* values, which
  69. -- describe the layout and type of tiles found in the puzzle.
  70. --
  71. -- TILE_COMPUTE: A basic execution node (node type T21).
  72. -- TILE_MEMORY: A stack memory node (node type T30).
  73. -- TILE_DAMAGED: A damaged execution node, which acts as an obstacle.
  74. --
  75. function get_layout()
  76. return {
  77. TILE_COMPUTE, TILE_COMPUTE, TILE_COMPUTE, TILE_COMPUTE,
  78. TILE_COMPUTE, TILE_COMPUTE, TILE_COMPUTE, TILE_COMPUTE,
  79. TILE_COMPUTE, TILE_COMPUTE, TILE_COMPUTE, TILE_COMPUTE,
  80. }
  81. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement