Advertisement
simeonshopov

Snake moves

May 29th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. #!/usr/local/bin/python3.7
  2. # -*- coding: utf-8 -*import
  3. from _collections import deque
  4.  
  5. rows, columns = map(int, input().split())
  6.  
  7. snake_string = input()
  8.  
  9. matrix = [[None] * columns for _ in range(rows)]
  10.  
  11. snake = deque(snake_string)
  12.  
  13. for x in range(rows):
  14.     if x % 2 == 0:
  15.         for y in range(columns):
  16.             if not snake:
  17.                 snake = deque(snake_string)
  18.             matrix[x][y] = snake.popleft()
  19.     else:
  20.         for y in range(columns -1, -1, -1):
  21.             if not snake:
  22.                 snake = deque(snake_string)
  23.             matrix[x][y] = snake.popleft()
  24.  
  25. print('\n'.join([''.join([y for y in x]) for x in matrix]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement