Advertisement
Guest User

Untitled

a guest
Jun 29th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. def circle(chars):
  2. test = """
  3.  
  4. @@@@@@@@@@@@@
  5. @@ @@
  6. @@ @@
  7. @@ @@
  8. @ @
  9. @ @
  10. @ @
  11. @ @
  12. @ @
  13. @ @
  14. @ @
  15. @ @
  16. @ @
  17. @ @
  18. @ @
  19. @ @
  20. @ @
  21. @ @
  22. @ @
  23. @ @
  24. @ @
  25. @@ @@
  26. @@ @@
  27. @@ @@
  28. @@@@@@@@@@@@@
  29.  
  30.  
  31. """
  32.  
  33. #chars = "abcdefghijklmnopqrstuvwxyzABDEFGHIJKLMOPQRSTUVWXYZ1234567890,.<>?;'#:~[]{}$%^&*)(£!|"
  34. chars = chars.replace(" ", "¬")
  35.  
  36. def extract(chars, start, end):
  37. if end > len(chars):
  38. ext = chars[start:len(chars)]
  39. end -= len(chars)
  40. while end >= 0:
  41. ext += chars[:min(len(chars), end)]
  42. end -= len(chars)
  43. return ext
  44. else:
  45. return chars[start:end]
  46.  
  47. ci = 0
  48.  
  49. lines = [x for x in test.split("\n") if x.replace(" ", "") != ""]
  50. result = lines[:]
  51. for index in range(2):
  52. found_top = False
  53. reverse = index == 1
  54. for i, line in enumerate(lines):
  55. if index == 1:
  56. i = -(i+1)
  57. line = lines[i]
  58. front = ""
  59. while len(line) > 0 and line[0] == " ":
  60. front += " "
  61. line = line[1:]
  62. if len(front) == 1:
  63. reverse = (reverse == False)
  64. end = ""
  65. while len(line) > 0 and line[-1] == " ":
  66. end += " "
  67. line = line[:-1]
  68. if " " not in line: # top or bottom
  69. if not found_top: # bottom
  70. if index == 1: # going up
  71. result[i] = front + extract(chars, ci, ci+len(line))[::-1] + end
  72. ci = (ci + len(line)) % len(chars)
  73. elif index == 0: # going down
  74. result[i] = front + extract(chars, ci, ci+len(line)) + end
  75. ci = (ci + len(line)) % len(chars)
  76. found_top = True
  77. else:
  78. spl = [x for x in line.split(" ") if x != ""]
  79. right = spl[0]
  80. left = spl[1]
  81. middle = line[len(right):-len(left)]
  82. if index == 0: # going down
  83. block = extract(chars, ci, ci+len(right))
  84. if reverse:
  85. block = block[::-1]
  86. result[i] = middle + block + end
  87. ci = (ci + len(right)) % len(chars)
  88. else: # going up
  89. block = extract(chars, ci, ci + len(left))
  90. if reverse:
  91. block = block[::-1]
  92. result[i] = front + block + result[i]
  93. ci = (ci + len(left)) % len(chars)
  94.  
  95. return "\n".join(result).replace("¬", " ")
  96.  
  97. result(circle(" ".join(getargs())))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement