Skip to content

Commit

Permalink
Started day 15
Browse files Browse the repository at this point in the history
  • Loading branch information
dwt committed Jan 29, 2019
1 parent ce1adc8 commit e6c167f
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 5 deletions.
61 changes: 56 additions & 5 deletions examples/aoc2018/fluentpy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2201,24 +2201,75 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": []
"source": [
"from pyexpect import expect\n",
"import fluentpy as _\n",
"\n",
"np = _.lib.numpy._"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": []
"source": [
"@_.lib.dataclasses.dataclass._\n",
"class Player:\n",
" type: chr\n",
" x: int\n",
" y: int\n",
" hitpoints: int = 200\n",
" attack_power: int = 3\n",
" \n",
" def round(self, world):\n",
" pass\n",
"\n",
"def tuplify(a_function):\n",
" @_.lib.functools.wraps._(a_function)\n",
" def wrapper(*args, **kwargs):\n",
" return tuple(a_function(*args, **kwargs))\n",
" return wrapper\n",
"\n",
"class Level:\n",
" \n",
" def __init__(self, level_description):\n",
" self.level = np.array(_(level_description).strip().split('\\n').map(tuple)._)\n",
" \n",
" @tuplify\n",
" def parse_players(self):\n",
" for row_number, row in enumerate(self.level):\n",
" for col_number, char in enumerate(row):\n",
" if char in 'GE':\n",
" yield Player(char, x=row_number, y=col_number)\n"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"level = \"\"\"\\\n",
"#######\n",
"#.G.E.#\n",
"#E....#\n",
"#######\n",
"\"\"\"\n",
"expect(Level(level).parse_players()) == (Player('G',1,2), Player('E', 1, 4), Player('E',2,1))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"level = open('input/day15.txt').read()"
]
},
{
"cell_type": "code",
Expand Down
32 changes: 32 additions & 0 deletions examples/aoc2018/input/day15.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
################################
######......###...##..##########
######....#G###G..##.G##########
#####...G##.##.........#########
##....##..#.##...........#######
#....#G.......##.........G.#####
##..##GG....G.................##
##.......G............#.......##
###.....G.....G#......E.......##
##......##....................##
#.....####......G.....#...######
#.#########.G....G....#E.#######
###########...#####......#######
###########..#######..E.......##
###########.#########......#.###
########..#.#########.........##
#######G....#########........###
##.##.#.....#########...EE#..#.#
#...GG......#########.#...##..E#
##...#.......#######..#...#....#
###.##........#####......##...##
###.........................#..#
####.............##........###.#
####............##.........#####
####..##....###.#...#.....######
########....###..............###
########..G...##.###...E...E.###
#########...G.##.###.E....E.####
#########...#.#######.......####
#############..########...######
##############.########.########
################################

0 comments on commit e6c167f

Please sign in to comment.