mirror of
https://github.com/KevinMidboe/knowit_julekalender-2017.git
synced 2025-10-29 17:50:18 +00:00
Solution for 19 using PIL and drawing a image.
This commit is contained in:
43
luke_19/engler.py
Executable file
43
luke_19/engler.py
Executable file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python3.6
|
||||
import os
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
def readFile():
|
||||
with open(os.path.dirname(__file__) + '/path.txt', 'r') as f:
|
||||
return [line.split(", ") for line in f.read().splitlines()]
|
||||
|
||||
def plotRectangle(i, j, board, fill='red'):
|
||||
board.rectangle(((100+(10*j), 200+(10*i)), 100+(10*j+10), 200+(10*i+10)), fill=fill, outline="black")
|
||||
return board
|
||||
|
||||
def main():
|
||||
path = readFile()
|
||||
boardImg = Image.new('RGB', (400, 300), (255,255,255))
|
||||
board = ImageDraw.Draw(boardImg)
|
||||
x, y = [0,0]
|
||||
plotRectangle(x,y,board, 'green')
|
||||
|
||||
for step, direction in path:
|
||||
if (direction == 'north'):
|
||||
for n in range(int(step)):
|
||||
x -= 1
|
||||
board = plotRectangle(x, y, board)
|
||||
elif (direction == 'east'):
|
||||
for n in range(int(step)):
|
||||
print(y)
|
||||
y += 1
|
||||
board = plotRectangle(x, y, board)
|
||||
elif (direction == 'south'):
|
||||
for n in range(int(step)):
|
||||
x += 1
|
||||
board = plotRectangle(x, y, board)
|
||||
elif (direction == 'west'):
|
||||
for n in range(int(step)):
|
||||
y -= 1
|
||||
board = plotRectangle(x, y, board)
|
||||
|
||||
return 'batman'
|
||||
boardImg.show()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
148
luke_19/path.txt
Normal file
148
luke_19/path.txt
Normal file
@@ -0,0 +1,148 @@
|
||||
10, east
|
||||
1, west
|
||||
1, north
|
||||
4, east
|
||||
1, north
|
||||
2, east
|
||||
1, north
|
||||
2, east
|
||||
1, north
|
||||
1, east
|
||||
1, north
|
||||
1, east
|
||||
2, north
|
||||
1, east
|
||||
6, north
|
||||
1, west
|
||||
2, north
|
||||
1, west
|
||||
1, north
|
||||
1, west
|
||||
1, north
|
||||
2, west
|
||||
1, north
|
||||
2, west
|
||||
1, north
|
||||
3, west
|
||||
1, north
|
||||
10, west
|
||||
1, south
|
||||
3, west
|
||||
1, south
|
||||
2, west
|
||||
1, south
|
||||
2, west
|
||||
1, south
|
||||
1, west
|
||||
1, south
|
||||
1, west
|
||||
2, south
|
||||
1, west
|
||||
6, south
|
||||
1, east
|
||||
2, south
|
||||
1, east
|
||||
1, south
|
||||
1, east
|
||||
1, south
|
||||
2, east
|
||||
1, south
|
||||
2, east
|
||||
1, south
|
||||
4, east
|
||||
4, west
|
||||
1, north
|
||||
2, west
|
||||
2, north
|
||||
1, east
|
||||
1, west
|
||||
2, north
|
||||
2, west
|
||||
1, north
|
||||
3, east
|
||||
1, north
|
||||
4, west
|
||||
19, east
|
||||
1, south
|
||||
12, west
|
||||
1, east
|
||||
2, south
|
||||
2, north
|
||||
10, east
|
||||
2, south
|
||||
2, north
|
||||
3, west
|
||||
1, south
|
||||
4, west
|
||||
1, east
|
||||
1, south
|
||||
2, east
|
||||
1, west
|
||||
2, south
|
||||
5, north
|
||||
13, east
|
||||
1, west
|
||||
1, south
|
||||
3, west
|
||||
1, east
|
||||
1, south
|
||||
2, east
|
||||
2, west
|
||||
2, south
|
||||
1, west
|
||||
1, east
|
||||
5, north
|
||||
3, east
|
||||
26, west
|
||||
1, north
|
||||
26, east
|
||||
1, north
|
||||
26, west
|
||||
1, north
|
||||
26, east
|
||||
1, west
|
||||
1, north
|
||||
6, west
|
||||
1, east
|
||||
1, north
|
||||
5, east
|
||||
2, west
|
||||
1, north
|
||||
3, west
|
||||
1, north
|
||||
1, east
|
||||
1, west
|
||||
1, north
|
||||
1, west
|
||||
1, east
|
||||
5, south
|
||||
4, west
|
||||
1, north
|
||||
6, west
|
||||
1, east
|
||||
1, north
|
||||
4, east
|
||||
1, north
|
||||
4, west
|
||||
1, north
|
||||
4, east
|
||||
1, north
|
||||
4, west
|
||||
1, north
|
||||
1, south
|
||||
4, east
|
||||
1, north
|
||||
6, south
|
||||
8, west
|
||||
1, north
|
||||
6, west
|
||||
1, north
|
||||
5, east
|
||||
1, north
|
||||
3, west
|
||||
3, east
|
||||
1, north
|
||||
1, west
|
||||
1, east
|
||||
1, north
|
||||
1, east
|
||||
@@ -1,2 +1,4 @@
|
||||
from luke_19.engler import main
|
||||
|
||||
def test_answer():
|
||||
assert False
|
||||
assert main() == 'batman'
|
||||
|
||||
Reference in New Issue
Block a user