Guest User

Untitled

a guest
Dec 13th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. ########################################################################
  2. #
  3. # Process input data to return the appropriate records or data format.
  4. #
  5. # For this puzzle, the input data will be a 4-item tuple:
  6. # `(tracks, carts, next_turns, width, height)`
  7. # - `tracks` holds the tracks of the puzzle as a single string (with the
  8. # first `width` characters holding the first row of the puzzle, etc).
  9. # Any place in the original puzzle input which held a cart is replaced
  10. # by the track that underlies it.
  11. # - `carts` holds the carts from the puzzle in a string the same size as
  12. # `tracks`. Each location of the original puzzle that has a cart will
  13. # have a track in `tracks` and a cart direction (^/v/>/<) in `carts`;
  14. # all other locations will have the original puzzle content in `tracks`
  15. # and a space in `carts`.
  16. # - `next_turns` holds the next turn direction for each cart in `carts`,
  17. # with each cart starting out with a next turn of `1`. Any location in
  18. # `carts` which does not hold a cart will have a space in `next_turns`.
  19. # - `width` and `height` are the number of columns and number of rows,
  20. # respectively, in the input data.
  21.  
  22. process_input_data = lambda input_data: (
  23. input_data
  24. .replace('\n', '')
  25. .replace('<', '-')
  26. .replace('>', '-')
  27. .replace('^', '|')
  28. .replace('v', '|')
  29. ,
  30. input_data
  31. .replace('\n', '')
  32. .replace('-', ' ')
  33. .replace('|', ' ')
  34. .replace('+', ' ')
  35. .replace('\\', ' ')
  36. .replace('/', ' ')
  37. ,
  38. input_data
  39. .replace('\n', '')
  40. .replace('-', ' ')
  41. .replace('|', ' ')
  42. .replace('+', ' ')
  43. .replace('\\', ' ')
  44. .replace('/', ' ')
  45. .replace('<', '1')
  46. .replace('>', '1')
  47. .replace('^', '1')
  48. .replace('v', '1')
  49. ,
  50. len(input_data.split('\n')[0]),
  51. len(input_data.split('\n'))
  52. )
Add Comment
Please, Sign In to add comment