Add solves for 6,7 & 8

This commit is contained in:
Tabledevil
2024-12-11 23:14:05 +01:00
parent a2ca822c9d
commit 65010487b7
11 changed files with 819691 additions and 0 deletions

805100
6/6.ipynb Normal file

File diff suppressed because one or more lines are too long

787
6/6b.ipynb Normal file
View File

@@ -0,0 +1,787 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 155,
"metadata": {},
"outputs": [],
"source": [
"#import lru cache decorator\n",
"from functools import lru_cache\n",
"from copy import deepcopy\n",
"\n",
"\n",
"def load_map(file_path='testinput'):\n",
" with open(file_path, 'r') as file:\n",
" content = file.readlines()\n",
" return [list(line.strip()) for line in content]\n",
"\n",
"def get_map():\n",
" return deepcopy(load_map())"
]
},
{
"cell_type": "code",
"execution_count": 156,
"metadata": {},
"outputs": [],
"source": [
"emptymap = load_map()\n",
"map = load_map()"
]
},
{
"cell_type": "code",
"execution_count": 157,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Position: (6, 4) facing ^.\n"
]
},
{
"data": {
"text/plain": [
"(6, 4, '^')"
]
},
"execution_count": 157,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def get_start_position(map):\n",
" for x, row in enumerate(map):\n",
" for dir in ['^', '<', '>', 'V']:\n",
" if dir in row:\n",
" y = row.index(dir)\n",
" pos = (x, y, dir)\n",
" print(f\"Position: ({pos[0]}, {pos[1]}) facing {pos[2]}.\")\n",
" return pos\n",
"\n",
" return None\n",
"\n",
"\n",
"get_start_position(map)"
]
},
{
"cell_type": "code",
"execution_count": 158,
"metadata": {},
"outputs": [],
"source": [
"def printmap(map):\n",
" for row in map:\n",
" print(''.join(row))\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 159,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"....#.....\n",
".........#\n",
"..........\n",
"..#.......\n",
".......#..\n",
"..........\n",
".#..^.....\n",
"........#.\n",
"#.........\n",
"......#...\n"
]
}
],
"source": [
"printmap(load_map())"
]
},
{
"cell_type": "code",
"execution_count": 160,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(5, 4)"
]
},
"execution_count": 160,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def calculate_next_position(x, y, dir):\n",
" if dir == '^':\n",
" return (x - 1, y)\n",
" elif dir == '<':\n",
" return (x, y - 1)\n",
" elif dir == '>':\n",
" return (x, y + 1)\n",
" elif dir == 'V':\n",
" return (x + 1, y)\n",
"\n",
"def rotate(dir):\n",
" if dir == '^':\n",
" return '>'\n",
" elif dir == '<':\n",
" return '^'\n",
" elif dir == '>':\n",
" return 'V'\n",
" elif dir == 'V':\n",
" return '<'\n",
"\n",
"def in_bounds(map, x, y):\n",
" return 0 <= x < len(map) and 0 <= y < len(map[0])\n",
"\n",
"calculate_next_position(6, 4, '^')"
]
},
{
"cell_type": "code",
"execution_count": 161,
"metadata": {},
"outputs": [],
"source": [
"class LoopDetected(Exception):\n",
" pass\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 162,
"metadata": {},
"outputs": [],
"source": [
"def move(map, pos=None, visited=None):\n",
" # Initialize visited list if not provided\n",
" if visited is None:\n",
" visited = []\n",
" history = deepcopy(visited)\n",
" # Get the current position and direction if not provided\n",
" if pos is None:\n",
" pos = get_start_position(map)\n",
" \n",
" \n",
" if pos:\n",
" x, y, dir = pos \n",
"\n",
" new_x, new_y = calculate_next_position(*pos)\n",
"\n",
" # Handle obstacles by rotating until an open path is found\n",
" while in_bounds(map, new_x, new_y) and map[new_x][new_y] == '#':\n",
" dir = rotate(dir) # Rotate direction\n",
" new_x, new_y = calculate_next_position(x, y, dir)\n",
"\n",
" # Move to the new position if valid, otherwise return None\n",
" if in_bounds(map, new_x, new_y) and map[new_x][new_y] != '#':\n",
" pos = (new_x,new_y,dir)\n",
" history.append(pos)\n",
" else:\n",
" pos = None\n",
"\n",
" \n",
" # No valid move was possible or guard is out of bounds\n",
" return pos, history\n"
]
},
{
"cell_type": "code",
"execution_count": 163,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"....#.....\n",
".........#\n",
"..........\n",
"..#.......\n",
".......#..\n",
"..........\n",
".#..^.....\n",
"........#.\n",
"#.........\n",
"......#...\n"
]
}
],
"source": [
"printmap(map)"
]
},
{
"cell_type": "code",
"execution_count": 164,
"metadata": {},
"outputs": [],
"source": [
"def merge_element(new,old):\n",
"\n",
" mergetable = {\n",
" # Straight line merges\n",
" ('─', '─'): '─',\n",
" ('│', '│'): '│',\n",
" ('─', '│'): '┼',\n",
" ('│', '─'): '┼',\n",
"\n",
" # Corners with straight lines\n",
" ('─', '┌'): '┬',\n",
" ('─', '┐'): '┬',\n",
" ('─', '└'): '┴',\n",
" ('─', '┘'): '┴',\n",
" ('│', '┌'): '├',\n",
" ('│', '┐'): '┤',\n",
" ('│', '└'): '├',\n",
" ('│', '┘'): '┤',\n",
"\n",
" # Corners with corners\n",
" ('┌', '┐'): '┬',\n",
" ('┌', '└'): '├',\n",
" ('┌', '┘'): '┼',\n",
" ('┐', '└'): '┼',\n",
" ('┐', '┘'): '┤',\n",
" ('└', '┘'): '┴',\n",
"\n",
" # Straight lines with T-junctions\n",
" ('─', '┬'): '┬',\n",
" ('─', '┴'): '┴',\n",
" ('─', '├'): '┼',\n",
" ('─', '┤'): '┼',\n",
" ('│', '┬'): '┼',\n",
" ('│', '┴'): '┼',\n",
" ('│', '├'): '├',\n",
" ('│', '┤'): '┤',\n",
"\n",
" # Corners with T-junctions\n",
" ('┌', '┬'): '┬',\n",
" ('┌', '┴'): '├',\n",
" ('┌', '├'): '├',\n",
" ('┌', '┤'): '┼',\n",
" ('┐', '┬'): '┬',\n",
" ('┐', '┴'): '┤',\n",
" ('┐', '├'): '┼',\n",
" ('┐', '┤'): '┤',\n",
" ('└', '┬'): '├',\n",
" ('└', '┴'): '┴',\n",
" ('└', '├'): '├',\n",
" ('└', '┤'): '┼',\n",
" ('┘', '┬'): '┤',\n",
" ('┘', '┴'): '┴',\n",
" ('┘', '├'): '┼',\n",
" ('┘', '┤'): '┤',\n",
"\n",
" # T-junctions with T-junctions\n",
" ('┬', '┬'): '┬',\n",
" ('┬', '┴'): '┼',\n",
" ('┬', '├'): '┼',\n",
" ('┬', '┤'): '┼',\n",
" ('┴', '┴'): '┴',\n",
" ('┴', '├'): '┼',\n",
" ('┴', '┤'): '┼',\n",
" ('├', '├'): '├',\n",
" ('├', '┤'): '┼',\n",
" ('┤', '┤'): '┤',\n",
"\n",
" # Full crossings\n",
" ('─', '┼'): '┼',\n",
" ('│', '┼'): '┼',\n",
" ('┌', '┼'): '┼',\n",
" ('┐', '┼'): '┼',\n",
" ('└', '┼'): '┼',\n",
" ('┘', '┼'): '┼',\n",
" ('┬', '┼'): '┼',\n",
" ('┴', '┼'): '┼',\n",
" ('├', '┼'): '┼',\n",
" ('┤', '┼'): '┼',\n",
" ('┼', '┼'): '┼',\n",
" }\n",
"\n",
" if old and new:\n",
" if (old,new) in mergetable:\n",
" return mergetable[(old,new)]\n",
" if (new,old) in mergetable:\n",
" return mergetable[(new,old)]\n",
" if new:\n",
" return new\n",
" return old\n",
"\n",
"def get_draw_element(current_dir, new_dir, existing_symbol=None):\n",
" direction_merge = {\n",
" # Straight Movements\n",
" ('^', '^'): '│', # Continue moving up\n",
" ('V', 'V'): '│', # Continue moving down\n",
" ('<', '<'): '─', # Continue moving left\n",
" ('>', '>'): '─', # Continue moving right\n",
"\n",
" # Turns from Up ('^')\n",
" ('^', '>'): '┌', # Turn right from up\n",
" ('^', '<'): '┐', # Turn left from up\n",
"\n",
" # Turns from Down ('v')\n",
" ('V', '>'): '└', # Turn right from down\n",
" ('V', '<'): '┘', # Turn left from down\n",
"\n",
" # Turns from Left ('<')\n",
" ('<', '^'): '└', # Turn up from left\n",
" ('<', 'V'): '┌', # Turn down from left\n",
"\n",
" # Turns from Right ('>')\n",
" ('>', '^'): '┘', # Turn up from right\n",
" ('>', 'V'): '┐', # Turn down from right\n",
"\n",
" # Reverse Movements\n",
" ('^', 'V'): '│', # Reverse direction (up to down)\n",
" ('V', '^'): '│', # Reverse direction (down to up)\n",
" ('<', '>'): '─', # Reverse direction (left to right)\n",
" ('>', '<'): '─', # Reverse direction (right to left)\n",
" }\n",
" return merge_element(direction_merge[(current_dir,new_dir)],existing_symbol)\n",
"\n",
"def drawroute(map,visited):\n",
" temp_map = deepcopy(map)\n",
" for cur,new in zip(visited,visited[1:]):\n",
" if cur is None or new is None:\n",
" raise ValueError(f\"visited had a None entry! cur:{cur} new:{new}\")\n",
" if len(new) <3:\n",
" raise ValueError(f\"visited had a malformed entry : cur:{cur}\")\n",
" x,y,dir = cur\n",
" nx,ny,ndir = new\n",
" temp_map[x][y] = get_draw_element(dir,ndir,temp_map[x][y])\n",
" \n",
" temp_map[nx][ny] = get_draw_element(ndir,ndir) # Mark start point\n",
"\n",
" printmap(temp_map)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 165,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Position: (6, 4) facing ^.\n",
"....#.....\n",
".........#\n",
"..........\n",
"..#.......\n",
".......#..\n",
"..........\n",
".#..^.....\n",
"........#.\n",
"#.........\n",
"......#...\n",
"....#.....\n",
"....┌───┐#\n",
"....│...│.\n",
"..#.│...│.\n",
"..┌─┼─┐#│.\n",
"..│.│.│.│.\n",
".#└───┼─┘.\n",
".┌────┼┐#.\n",
"#└────┘│..\n",
"......#│..\n"
]
}
],
"source": [
"pos,visited = move(map)\n",
"printmap(map)\n",
"\n",
"while pos:\n",
" pos,visited = move(map,pos,visited)\n",
"\n",
"drawroute(map,visited)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 166,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(41, 44)"
]
},
"execution_count": 166,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def count_visited(visited):\n",
" visited = set([(x,y) for x,y,dir in visited]) # Convert list to set to remove duplicates\n",
" return len(visited)\n",
"\n",
"count_visited(visited), len(visited)"
]
},
{
"cell_type": "code",
"execution_count": 99,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[34]"
]
},
"execution_count": 99,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"[idx for idx,(x,y,d) in enumerate(visited) if x == 8 and y ==1]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 100,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"((8, 2, '<'), (8, 1, '<'), 32, 44)"
]
},
"execution_count": 100,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"test_position = 34\n",
"guardposition = visited[test_position-1]\n",
"obsticalposition = visited[test_position]\n",
"\n",
"history = visited[:test_position-2]\n",
"guardposition,obsticalposition, len(history), len(visited)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 101,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"....#.....\n",
".........#\n",
"..........\n",
"..#.......\n",
".......#..\n",
"..........\n",
".#..^.....\n",
"........#.\n",
"##........\n",
"......#...\n",
"....#.....\n",
"....┌───┐#\n",
"....│...│.\n",
"..#.│...│.\n",
"..┌─┼─┐#│.\n",
"..│.│.│.│.\n",
".#└───┼─┘.\n",
"......│.#.\n",
"##..──┘...\n",
"......#...\n"
]
}
],
"source": [
"# create copy of map with additional obstacle at pos\n",
"def add_obstacle(pos):\n",
" # create a copy of the original map\n",
" new_map = get_map()\n",
" # add the obstacle to the new map\n",
" x,y,dir = pos\n",
" new_map[x][y] = '#'\n",
" return new_map\n",
"\n",
"testmap = add_obstacle(obsticalposition)\n",
"printmap(testmap)\n",
"drawroute(testmap,history)\n",
"pos = guardposition"
]
},
{
"cell_type": "code",
"execution_count": 103,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(7, 2, '^')\n"
]
}
],
"source": [
"newpos,newhistory = move(testmap,guardposition,history)\n",
"print(newpos)\n"
]
},
{
"cell_type": "code",
"execution_count": 106,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"....#.....\n",
"....┌───┐#\n",
"....│...│.\n",
"..#.│...│.\n",
"..┌─┼─┐#│.\n",
"..│.│.│.│.\n",
".#└───┼─┘.\n",
"......│.#.\n",
"##..──┘...\n",
"......#...\n"
]
}
],
"source": [
"drawroute(testmap,history)"
]
},
{
"cell_type": "code",
"execution_count": 143,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"....#.....\n",
"....┌───┐#\n",
"....│...│.\n",
"..#.│...│.\n",
"..┌─┼─┐#│.\n",
"..│.│.│.│.\n",
".#├───┼─┘.\n",
"..│...│.#.\n",
"##└─┴─┘...\n",
"......#...\n"
]
}
],
"source": [
"pos,history = move(testmap,pos,history)\n",
"drawroute(testmap,history)\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 168,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Loop detected with obstacle at (4, 4, '^')\n",
"Loop detected with obstacle at (3, 4, '^')\n",
"Loop detected with obstacle at (2, 4, '^')\n",
"Loop detected with obstacle at (1, 4, '^')\n",
"Loop detected with obstacle at (1, 5, '>')\n",
"Loop detected with obstacle at (1, 6, '>')\n",
"Loop detected with obstacle at (1, 7, '>')\n",
"Loop detected with obstacle at (1, 8, '>')\n",
"Loop detected with obstacle at (2, 8, 'V')\n",
"Loop detected with obstacle at (3, 8, 'V')\n",
"Loop detected with obstacle at (4, 8, 'V')\n",
"Loop detected with obstacle at (5, 8, 'V')\n",
"Loop detected with obstacle at (6, 8, 'V')\n",
"Loop detected with obstacle at (6, 7, '<')\n",
"Loop detected with obstacle at (6, 6, '<')\n",
"Loop detected with obstacle at (6, 5, '<')\n",
"Loop detected with obstacle at (6, 4, '<')\n",
"Loop detected with obstacle at (6, 3, '<')\n",
"Loop detected with obstacle at (6, 2, '<')\n",
"Loop detected with obstacle at (5, 2, '^')\n",
"Loop detected with obstacle at (4, 2, '^')\n",
"Loop detected with obstacle at (4, 3, '>')\n",
"Loop detected with obstacle at (4, 4, '>')\n",
"Loop detected with obstacle at (4, 5, '>')\n",
"Loop detected with obstacle at (4, 6, '>')\n",
"Loop detected with obstacle at (5, 6, 'V')\n",
"Loop detected with obstacle at (6, 6, 'V')\n",
"Loop detected with obstacle at (7, 6, 'V')\n",
"Loop detected with obstacle at (8, 6, 'V')\n",
"Loop detected with obstacle at (8, 5, '<')\n",
"Loop detected with obstacle at (8, 4, '<')\n",
"Loop detected with obstacle at (8, 3, '<')\n",
"Loop detected with obstacle at (8, 2, '<')\n",
"Loop detected with obstacle at (8, 1, '<')\n",
"Loop detected with obstacle at (7, 1, '^')\n",
"Loop detected with obstacle at (7, 2, '>')\n",
"Loop detected with obstacle at (7, 3, '>')\n",
"Loop detected with obstacle at (7, 4, '>')\n",
"Loop detected with obstacle at (7, 5, '>')\n",
"Loop detected with obstacle at (7, 6, '>')\n",
"Loop detected with obstacle at (7, 7, '>')\n",
"Loop detected with obstacle at (8, 7, 'V')\n",
"Loop detected with obstacle at (9, 7, 'V')\n",
"Total loop positions: 43\n"
]
},
{
"data": {
"text/plain": [
"[(4, 4, '^'),\n",
" (3, 4, '^'),\n",
" (2, 4, '^'),\n",
" (1, 4, '^'),\n",
" (1, 5, '>'),\n",
" (1, 6, '>'),\n",
" (1, 7, '>'),\n",
" (1, 8, '>'),\n",
" (2, 8, 'V'),\n",
" (3, 8, 'V'),\n",
" (4, 8, 'V'),\n",
" (5, 8, 'V'),\n",
" (6, 8, 'V'),\n",
" (6, 7, '<'),\n",
" (6, 6, '<'),\n",
" (6, 5, '<'),\n",
" (6, 4, '<'),\n",
" (6, 3, '<'),\n",
" (6, 2, '<'),\n",
" (5, 2, '^'),\n",
" (4, 2, '^'),\n",
" (4, 3, '>'),\n",
" (4, 4, '>'),\n",
" (4, 5, '>'),\n",
" (4, 6, '>'),\n",
" (5, 6, 'V'),\n",
" (6, 6, 'V'),\n",
" (7, 6, 'V'),\n",
" (8, 6, 'V'),\n",
" (8, 5, '<'),\n",
" (8, 4, '<'),\n",
" (8, 3, '<'),\n",
" (8, 2, '<'),\n",
" (8, 1, '<'),\n",
" (7, 1, '^'),\n",
" (7, 2, '>'),\n",
" (7, 3, '>'),\n",
" (7, 4, '>'),\n",
" (7, 5, '>'),\n",
" (7, 6, '>'),\n",
" (7, 7, '>'),\n",
" (8, 7, 'V'),\n",
" (9, 7, 'V')]"
]
},
"execution_count": 168,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def find_loops(map, visited):\n",
" loop_positions = [] # Array to store positions leading to loops\n",
" \n",
" for idx, obstacle_position in enumerate(visited[1:]): # Skip the starting position\n",
" # Determine the position before the obstacle\n",
" if idx == 0:\n",
" guard_start_position = visited[0]\n",
" else:\n",
" guard_start_position = visited[idx - 1]\n",
" \n",
" # Create a new map with the obstacle added\n",
" test_map = add_obstacle(obstacle_position)\n",
" \n",
" # Initialize history from the visited list up to the current index\n",
" history = deepcopy(visited[:idx])\n",
" \n",
" # Start simulation\n",
" pos = guard_start_position\n",
" while pos and pos not in history:\n",
" pos, history = move(test_map, pos, history)\n",
" \n",
" # Check if a loop was detected\n",
" if pos and pos in history:\n",
" loop_positions.append(obstacle_position)\n",
" print(f\"Loop detected with obstacle at {obstacle_position}\")\n",
" \n",
" print(f\"Total loop positions: {len(loop_positions)}\")\n",
" return loop_positions\n",
"\n",
"find_loops(map,visited)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

465
6/6c.ipynb Normal file
View File

@@ -0,0 +1,465 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"with open('testinput', 'r') as file:\n",
" content = file.readlines()\n",
"\n",
"map = [list(line.strip()) for line in content]\n"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"def get_start_position(map):\n",
" for i, row in enumerate(map):\n",
" for dir in ['^', '<', '>', 'V']:\n",
" if dir in row:\n",
" return (i, row.index(dir), dir)\n",
" return -1,-1,None\n",
"\n",
"\n",
"start_x,start_y,start_dir = get_start_position(map)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Position: (6, 4) facing ^, sofar visited 0 cells.\n",
"....#.....\n",
".........#\n",
"..........\n",
"..#.......\n",
".......#..\n",
"..........\n",
".#..^.....\n",
"........#.\n",
"#.........\n",
"......#...\n"
]
}
],
"source": [
"def count_visited(map):\n",
" return sum(row.count('X') for row in map)\n",
"\n",
"def printmap(map):\n",
" x, y, dir = get_start_position(map)\n",
" if dir:\n",
" print(f\"Position: ({x}, {y}) facing {dir}, sofar visited {count_visited(map)} cells.\")\n",
" else:\n",
" print(f\"No guard found! Visited {count_visited(map)} cells.\")\n",
" for row in map:\n",
" print(''.join(row))\n",
"\n",
"\n",
"printmap(map)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(5, 4)"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def calculate_next_position(x, y, dir):\n",
" if dir == '^':\n",
" return (x - 1, y)\n",
" elif dir == '<':\n",
" return (x, y - 1)\n",
" elif dir == '>':\n",
" return (x, y + 1)\n",
" elif dir == 'V':\n",
" return (x + 1, y)\n",
"\n",
"def in_bounds(map, x, y):\n",
" return 0 <= x < len(map) and 0 <= y < len(map[0])\n",
"\n",
"calculate_next_position(6, 4, '^')"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"def move(map,pos=None):\n",
" # Get the current position of the robot\n",
" if pos is None:\n",
" x, y, dir = get_start_position(map)\n",
" elif len(pos)==3:\n",
" x,y, dir = pos\n",
" else:\n",
" raise ValueError()\n",
" \n",
" if in_bounds(map,x,y):\n",
" map[x][y] = 'X'\n",
"\n",
" if dir:\n",
" # Determine the next position based on the current direction\n",
" new_x, new_y = calculate_next_position(x, y, dir)\n",
" # while new position is obstacle turn right and recalculate the next position\n",
" while in_bounds(map,new_x,new_y) and map[new_x][new_y] == '#':\n",
" if dir == '^':\n",
" dir = '>'\n",
" elif dir == '<':\n",
" dir = '^'\n",
" elif dir == '>':\n",
" dir = 'V'\n",
" elif dir == 'V':\n",
" dir = '<'\n",
" new_x, new_y = calculate_next_position(x, y, dir)\n",
" # Update the map with the robot's new position and direction\n",
" if in_bounds(map,new_x,new_y):\n",
" map[new_x][new_y] = dir\n",
" return True, (new_x,new_y,dir)\n",
" \n",
" else:\n",
" print(f\"No guard found! Visited {count_visited(map)} cells.\")\n",
" return False, (-1,-1,dir)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Position: (5, 4) facing ^, sofar visited 1 cells.\n",
"....#.....\n",
".........#\n",
"..........\n",
"..#.......\n",
".......#..\n",
"....^.....\n",
".#..X.....\n",
"........#.\n",
"#.........\n",
"......#...\n"
]
},
{
"data": {
"text/plain": [
"(True, (5, 4, '^'))"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result,pos = move(map)\n",
"printmap(map)\n",
"result,pos"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"No guard found! Visited 41 cells.\n",
"....#.....\n",
"....XXXXX#\n",
"....X...X.\n",
"..#.X...X.\n",
"..XXXXX#X.\n",
"..X.X.X.X.\n",
".#XXXXXXX.\n",
".XXXXXXX#.\n",
"#XXXXXXX..\n",
"......#X..\n"
]
}
],
"source": [
"print(result)\n",
"while result:\n",
" result,pos = move(map,pos)\n",
"\n",
"printmap(map)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"No guard found! Visited 41 cells.\n",
"....#.....\n",
"....XXXXX#\n",
"....X...X.\n",
"..#.X...X.\n",
"..XXXXX#X.\n",
"..X.X.X.X.\n",
".#XXXXXXX.\n",
".XXXXXXX#.\n",
"#XXXXXXX..\n",
"......#X..\n",
"Position: (6, 4) facing ^, sofar visited 0 cells.\n",
"....#.....\n",
".........#\n",
"..........\n",
"..#.......\n",
".......#..\n",
"..........\n",
".#..^.....\n",
"........#.\n",
"#.........\n",
"......#...\n"
]
}
],
"source": [
"finished_map = map.copy()\n",
"map = [list(line.strip()) for line in content]\n",
"printmap(finished_map)\n",
"printmap(map)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{(3, 4), (4, 3), (5, 4), (4, 6), (8, 3), (8, 6), (1, 6), (2, 8), (7, 4), (6, 2), (7, 1), (7, 7), (6, 5), (6, 8), (4, 2), (4, 5), (5, 6), (4, 8), (8, 2), (9, 7), (8, 5), (2, 4), (1, 5), (1, 8), (7, 3), (6, 7), (7, 6), (5, 2), (4, 4), (3, 8), (8, 4), (5, 8), (8, 1), (8, 7), (1, 4), (1, 7), (7, 2), (6, 6), (7, 5), (6, 3)}\n"
]
}
],
"source": [
"#Prepare list of possible positions for a obstiacle to force guard into a loop and check if it causes a loop\n",
"def get_visited_positions(map):\n",
" visited = set()\n",
" for i, row in enumerate(map):\n",
" for j, cell in enumerate(row):\n",
" if cell == 'X':\n",
" if (i,j) != (start_x,start_y): #ignore the starting position\n",
" visited.add((i,j))\n",
" return visited\n",
"\n",
"print(get_visited_positions(finished_map))"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"# create copy of map with additional obstacle at pos\n",
"def add_obstacle(map, pos):\n",
" # create a copy of the original map\n",
" new_map = [row[:] for row in map]\n",
" # add the obstacle to the new map\n",
" new_map[pos[0]][pos[1]] = '#'\n",
" return new_map\n",
"\n",
"def check_loop(emptymap,pos):\n",
" #make copy of map\n",
" map = add_obstacle(emptymap,pos)\n",
" # create a set to keep track of visited positions and directions\n",
" visited = set()\n",
" # Get the current position of the robot\n",
" x,y,dir = get_start_position(map)\n",
" while dir and (x,y,dir) not in visited:\n",
" visited.add((x,y,dir))\n",
" # Determine the next position based on the current direction\n",
" result,pos = move(map,(x,y,dir))\n",
" x,y,dir = pos\n",
" \n",
" if dir and (x,y,dir) in visited:\n",
" print(f\"Found loop with {len(visited)} with obstical at {pos}\")\n",
" return True\n",
" else:\n",
" print(f\"No loop found after {len(visited)} visited positions.\")\n",
" return False\n"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Found loop with 24 with obstical at (-1, -1, 'V')\n",
"Loop detected at position (3, 4)\n",
"Found loop with 29 with obstical at (-1, -1, 'V')\n",
"Loop detected at position (4, 3)\n",
"Found loop with 7 with obstical at (-1, -1, '>')\n",
"Loop detected at position (5, 4)\n",
"Found loop with 32 with obstical at (-1, -1, 'V')\n",
"Loop detected at position (4, 6)\n",
"Found loop with 34 with obstical at (6, 4, '^')\n",
"Loop detected at position (8, 3)\n",
"Found loop with 37 with obstical at (-1, -1, '<')\n",
"Loop detected at position (8, 6)\n",
"Found loop with 16 with obstical at (-1, -1, 'V')\n",
"Loop detected at position (1, 6)\n",
"Found loop with 19 with obstical at (-1, -1, '<')\n",
"Loop detected at position (2, 8)\n",
"Found loop with 42 with obstical at (-1, -1, 'V')\n",
"Loop detected at position (7, 4)\n",
"Found loop with 27 with obstical at (-1, -1, '^')\n",
"Loop detected at position (6, 2)\n",
"Found loop with 45 with obstical at (-1, -1, '>')\n",
"Loop detected at position (7, 1)\n",
"Found loop with 42 with obstical at (8, 6, 'V')\n",
"Loop detected at position (7, 7)\n",
"Found loop with 24 with obstical at (-1, -1, '^')\n",
"Loop detected at position (6, 5)\n",
"Found loop with 23 with obstical at (-1, -1, '<')\n",
"Loop detected at position (6, 8)\n",
"Found loop with 30 with obstical at (-1, -1, '>')\n",
"Loop detected at position (4, 2)\n",
"Found loop with 31 with obstical at (-1, -1, 'V')\n",
"Loop detected at position (4, 5)\n",
"Found loop with 34 with obstical at (-1, -1, '<')\n",
"Loop detected at position (5, 6)\n",
"Found loop with 21 with obstical at (-1, -1, '^')\n",
"Loop detected at position (4, 8)\n",
"Found loop with 43 with obstical at (-1, -1, '^')\n",
"Loop detected at position (8, 2)\n",
"Found loop with 45 with obstical at (8, 5, '<')\n",
"Loop detected at position (9, 7)\n",
"Found loop with 40 with obstical at (-1, -1, '^')\n",
"Loop detected at position (8, 5)\n",
"Found loop with 10 with obstical at (-1, -1, '>')\n",
"Loop detected at position (2, 4)\n",
"Found loop with 15 with obstical at (-1, -1, 'V')\n",
"Loop detected at position (1, 5)\n",
"Found loop with 19 with obstical at (-1, -1, '^')\n",
"Loop detected at position (1, 8)\n",
"Found loop with 41 with obstical at (-1, -1, 'V')\n",
"Loop detected at position (7, 3)\n",
"Found loop with 22 with obstical at (-1, -1, '^')\n",
"Loop detected at position (6, 7)\n",
"Found loop with 29 with obstical at (6, 5, '<')\n",
"Loop detected at position (7, 6)\n",
"Found loop with 29 with obstical at (-1, -1, '>')\n",
"Loop detected at position (5, 2)\n",
"Found loop with 8 with obstical at (-1, -1, '>')\n",
"Loop detected at position (4, 4)\n",
"Found loop with 20 with obstical at (-1, -1, '<')\n",
"Loop detected at position (3, 8)\n",
"Found loop with 41 with obstical at (-1, -1, '^')\n",
"Loop detected at position (8, 4)\n",
"Found loop with 18 with obstical at (-1, -1, '^')\n",
"Loop detected at position (5, 8)\n",
"Found loop with 37 with obstical at (5, 2, '^')\n",
"Loop detected at position (8, 1)\n",
"Found loop with 51 with obstical at (-1, -1, '<')\n",
"Loop detected at position (8, 7)\n",
"Found loop with 11 with obstical at (-1, -1, '>')\n",
"Loop detected at position (1, 4)\n",
"Found loop with 30 with obstical at (-1, -1, 'V')\n",
"Loop detected at position (1, 7)\n",
"Found loop with 40 with obstical at (-1, -1, 'V')\n",
"Loop detected at position (7, 2)\n",
"Found loop with 20 with obstical at (-1, -1, '>')\n",
"Loop detected at position (6, 6)\n",
"Found loop with 43 with obstical at (-1, -1, 'V')\n",
"Loop detected at position (7, 5)\n",
"Found loop with 19 with obstical at (5, 4, '^')\n",
"Loop detected at position (6, 3)\n",
"Possible loops: 40\n"
]
}
],
"source": [
"\n",
"#Check if a loop is formed by placing an obstacle in one of the visited positions\n",
"possibles_loops = []\n",
"for pos in get_visited_positions(finished_map):\n",
" if check_loop(map,pos):\n",
" print(f\"Loop detected at position {pos}\")\n",
" possibles_loops.append(pos)\n",
"\n",
"print(f\"Possible loops: {len(possibles_loops)}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"printmap(map)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

11058
6/6classfull.ipynb Normal file

File diff suppressed because it is too large Load Diff

10
6/testinput Normal file
View File

@@ -0,0 +1,10 @@
....#.....
.........#
..........
..#.......
.......#..
..........
.#..^.....
........#.
#.........
......#...

1194
7/7.ipynb Normal file

File diff suppressed because it is too large Load Diff

850
7/input Normal file
View File

@@ -0,0 +1,850 @@
487656: 43 7 54 3 6 28
65816524826: 3 29 7 451 5 64 26 1 1 9
90059295: 900 1 592 92
2109036: 59 8 133 7 83 1 6
191815905829: 7 4 2 7 1 979 9 8 1 638 9
289979206: 49 587 234 9 206
26683869669: 51 654 837 8 69
829027: 827 34 83 85 2 5
1182822246: 41 2 7 40 8 6 839 7 4 8
12212256: 8 4 31 4 1 7 655 4 9 6 8 7
576756972: 599 5 8 6 7 5 43 4 9 11 4
3209617432982: 2 5 9 3 4 2 5 4 6 330 706
11368725: 13 94 9 520 2 13 87
3029408: 3 3 3 41 4 2 6 36 51 18 8
486: 4 59 29
1593: 8 2 4 868 606 98
1104643681: 742 52 44 50 8 5 714 1
8927181334: 941 8 7 94 1 319 16
3250434202409: 861 758 59 6 31 83 5 6
35658010977: 59 43 60 10 974
13458: 5 8 7 4 24 342 3 2 7 8 5 3
8144: 7 68 861 91 984 4 97 3
475875: 45 6 620 4 705
28086984: 5 4 41 79 9 7 3 6 8 3 6 4
97776: 6 3 9 6 57 679
14925208480: 7 4 195 7 64 6 55 5 5 91
57558888: 2 416 7 209 9 3 8 7 1 9
1736849: 4 706 205 11 3 49 7
640579: 59 7 227 420 160
60858: 40 4 918 49 54
7365: 83 4 1 28 64 5
15397: 4 5 69 387 623 5
127899: 5 22 71 66 902 475
8711335855: 8 711 335 85 8
195276861: 5 70 2 84 9 1 5 6 1 519
35544: 19 78 6 345 9
33213952: 81 1 9 5 3 4 5 62 93 38 8
579887: 61 2 65 8 78 76 9
15883: 40 1 356 4 5
202227810: 7 2 8 838 7 3 1 4 22 885
653556: 438 2 239 848 428
8948: 3 9 6 95 320 2 7 847 23
6454: 4 5 7 11 4 770 7
443390739223: 9 332 13 907 39 222
641557432: 63 634 521 7 430
782: 2 68 43 595 74
1331712: 1 7 26 192 204
129463: 4 4 5 97 9 6 4 975 2 24 1
221177258: 168 8 15 525 31 8
15537453: 901 6 3 3 5 3 957 558
12763566858: 1 6 641 895 618 83 6
2074806937: 2 78 7 90 1 6 76 9 5 4 1 7
1069: 4 2 5 2 989
129802: 3 61 7 5 619 41 611
201600485201: 3 800 84 485 1 202
259752: 4 49 8 8 4 67 76 2 8 888
472128: 31 9 4 37 7
3195693: 559 2 70 183 81
49176380250: 9 5 2 7 89 9 873 9 725
982: 3 79 64 293 6 24 356
6478268: 64 734 2 46 6 9
253809852: 64 340 72 4 3 9 94 6
751: 6 44 86 5 71
236658240: 43 28 35 6 936
43192: 42 3 8 9 1
340408: 2 32 10 4 10 1
7686: 2 7 29 30 93 48 6
4243124889: 1 8 133 26 303 9 87 74
856: 9 3 63 87 5 1 8
28033586941: 28 52 4 4 57 98 9 37 6
202380939: 2 559 3 4 6 9 6 5 39 8 2 1
10392264: 2 988 37 94
8032464: 3 56 28 2 455 73 198
622349387: 3 823 6 2 2 4 3 21 9 1 9
1651: 9 7 44 58 1
66060: 364 515 25 45 3
13444: 7 7 9 651 4
15431035: 22 100 4 6 8 3 99 2 2 7
480690: 7 82 51 5 763
29549163: 29 5 49 131 32
17720382: 43 55 71 4 4 382
1059: 2 111 5 9
21045024: 27 7 839 1 2 88 3 91
294336: 98 3 634 80 73 4
6896: 6 3 10 246 6
18821762: 20 1 23 85 389
33401: 93 50 108 7 79 16
4664286286: 9 64 3 2 48 57 6 93
2931104: 76 66 645 7 32
28566: 8 2 9 9 5 3 4 5 708 8 4 9
3198: 8 6 251 87 964 2 422
1040: 3 37 9 38 3
187968: 444 3 808 881 88
362576: 50 9 8 89 4 77 87
4992215: 126 2 5 6 75 7 58 53 39
2006981: 1 9 6 93 774
9793996248: 3 6 5 8 6 83 1 99 4 251
30613341465: 8 1 746 363 305 99 5 7
2137289544: 571 744 3 129 13
107872380: 8 33 5 493 2 8 7 9 5 9 5 9
4373193255: 9 49 911 933 3 235
223250: 4 1 9 190 950
100379: 9 985 1 93 435
53675254: 4 48 4 1 41 3 7 465 68
48870: 664 8 6 2 2 3 2 3 3 440 1
32167: 5 7 919
268259340: 1 50 892 2 9 1 1 527
44339505: 17 46 315 6 18
31750808: 3 16 9 2 13 7 7 6 6 10 91
728057579: 93 12 41 817 3 3 69 77
392: 5 3 1 7 7
638: 7 56 2 4 2
108204960: 770 877 8 983 160
3444301: 73 40 6 5 2 46 1 729 3 1
14229: 21 1 151 22 75 9 51
19262701: 7 3 9 971 182
1672476: 200 3 4 39 71
1618766643: 4 7 3 77 1 87 589 5 7 39
1248218882: 683 97 4 547 4 82
389845651483: 62 3 1 5 4 5 6 8 2 5 1 782
324944: 6 26 4 94 1
1166018: 96 97 118 8 75 6 51 4 1
525: 75 1 7 1
52924: 7 3 3 75 504 4
545733410: 1 3 6 99 9 5 33 337 4 62
8387390987: 7 202 984 59 677 75
2116285: 4 690 2 6 15 31 221 82
36525: 90 69 7 22 5
24147338178: 67 6 45 563 63 6
13: 1 4 6
16360: 2 29 429 51 32 8
97492862: 406 22 24 1 64
146228: 86 17 28
7743: 75 3 1 9 3 9 3
9883297: 7 9 32 57 86 865
973916: 7 9 119 73 7 94 823 55
153506360: 4 5 73 47 569 22 35 1 2
772201: 771 1 187 13
87872992470: 7 53 29 8 4 2 353 3 5 53
7819821990: 965 41 9 9 98 8
496991: 6 20 7 8 43 2
21834361: 6 879 460 3 3
35172: 793 736 23 4 1
875355: 249 37 95 47 9 64
386571: 2 193 5 36 8 7 4 9 3 6 1
23822642473: 76 773 81 5 811 9 8
819963721093: 9 287 26 36 8 82 1 517
88156679373: 881 56 677 2 373
294634: 44 6 124 9 7
412056335: 890 75 61 191 7
250582082: 9 1 3 92 1 6 14 8 20 76 3
30820812: 4 136 1 2 56 8 6 9 7 3 2 3
1159209247: 57 81 840 92 44
93114: 231 67 1 42 6
1427: 76 568 7 502 9 197 68
33487272395: 418 5 909 8 395
21155: 53 906 6 3 1 942 13 11
798093: 7 17 74 41 81 972
35354: 7 1 1 350 733 1 6 1 6 7 5
3290573: 8 9 55 9 3 8 7 5 113 2 5 8
37126311681: 371 26 311 65 4 27
444: 9 6 5 6 90
1494832626631: 2 521 4 68 5 3 7 1 6 26 3
125403: 17 90 1 5 7
7573005: 708 7 90 2 4 3 4 4 73 5
228697: 7 9 67 537 59 45 7 7
26150462601: 20 754 3 354 126
8337405: 81 96 92 8 8 8
10828266: 2 5 82 7 7 5 68
384887472: 3 1 54 3 102 8 6 6 4 823
733: 2 3 82 1 51
218975073: 9 9 218 3 4 9 57 9 50 74
2168082697: 1 2 6 2 6 2 6 68 3 692 2 4
173421503: 20 9 9 791 6 19 14 4
2971254430: 550 1 9 6 71 2 8 8 5 5 5
73191888: 3 161 46 63 154
613824: 5 3 5 2 3 3 2 2 11 1 71 4
1890989: 1 6 83 2 824 3 5 346 99
7440: 1 7 5 2 30 30 6 5 4 8 668
16968: 2 2 8 5 42 194 8 400 1 7
77440: 7 4 38 14 968
3562: 693 992 2 184 7
48049: 7 833 8 4 1 456 940
664: 6 8 317 1 2
1031: 8 8 87 304 55 521
1621533120: 368 412 69 31 5
391002: 87 195 31 4 1 23 2
6318279: 6 6 629 837 2 517 4 80
471816: 9 5 9 397 8 5 4 528 6 3 1
10005410: 8 186 9 2 336
19417: 92 6 18 74 1 4 18
44968: 5 2 3 3 76 7 3 80 2 1 8 7
395093631: 9 8 554 9 9 9 2 8 6 3 84 7
99600: 33 6 503 6
594646: 660 4 1 6 5 1 5 3 8 6 3
133110: 5 9 9 4 549 174
6604888205293: 2 20 89 92 710 8 299
6696448082514: 3 608 29 8 80 825 14
177053: 91 77 58 93 555 8
576: 2 38 14 9 7
162888: 60 12 2 1 905 80 5
7605: 626 122 773 5
11725560820: 72 37 90 44 823
8201356028: 593 461 5 46 5 37 60 6
24278472: 741 12 39 41 7 3 6 404
3208850: 6 7 4 145 100 7 2 4 4 3 5
559921158: 7 2 3 12 11 8 6 56 64 4 1
32011: 31 9 8 11
446283: 3 58 4 84 42 9 9 618 3
86535563: 8 6 535 56 1
21573728: 7 49 8 8 8 2 7 4 272 734
26121816: 2 254 8 44 181 3 1
45950642: 25 4 6 82 498 5 5 84 57
869176: 128 679 1 55
449486: 848 529 64 2 828
1279220996: 9 4 173 133 708 47 65
287825: 3 4 890 244 839 29 5
17180433987: 6 61 91 3 798 37 9 987
29106000: 306 5 64 6 3 8 7 1 77
68117: 97 1 3 1 7
40180569020: 574 70 5 6 450 451 8
2143936: 357 3 6 92 43
4875: 343 13 8 11 397
42041436: 564 4 12 7 37 19 2 2
556416: 9 8 69 8 14
6836490: 98 581 4 64 88 2
84747525: 20 4 56 4 5 345
873095872: 2 2 850 9 4 9 5 3 6 6 8 72
3438425675: 6 50 614 1 25 630 44
491: 80 54 3 7 83
665419100327: 608 965 97 15 751
82080: 9 675 4 5 6
1026: 8 5 67 89 338 5 444
178844: 4 5 9 5 9 3 15 58 57 91
61341: 32 59 674 4
291966364: 81 53 61 7 6 68
9182225: 5 8 2 5 85 6 2 4 56 4 6 17
1147150: 67 868 5 35 3 9 291 9 1
13716: 17 2 25 4 4
11424: 18 10 8 36 51
4816: 35 46 858 412
957272: 3 3 29 2 72
41212589: 5 512 6 7 6 3 763 4 5 86
158464: 76 417 5 4
1899297: 35 6 80 579 153 9 15
4542: 9 36 41
49681112: 496 811 1 1
126875993924: 28 5 97 33 249 7 9 8 9
59432: 82 618 589 3 46
1016349250: 8 741 22 269 635
30395070: 3 5 6 457 739
45556: 361 649 45 9 97
92791573: 4 624 8 2 290 5 56 8 2 1
192370728450: 85 154 835 5 8 2 22 8
5798: 8 8 288 11 12 34 4 5 4
9255060: 8 6 9 1 59 48 4 27 87
44320: 74 617 1 64 95 1
1046885: 993 8 530 76 8
363673109052: 11 62 2 264 9 43 2 618
269281880: 44 8 8 5 48 4 71 25 5
21918616: 2 1 6 7 297 82 258 4
215370680: 3 3 5 153 69 3 343 980
1318736: 996 82 745 4 16
411709059: 71 2 7 6 4 8 6 5 721 5 30
210420: 944 233 927 1 6 7
9776548567374: 618 87 506 593 606 4
19045689: 12 987 67 39 41
1554578: 2 536 69 3 81 7 3 677
1000961176548: 340 8 92 26 3 4 4 545
10871: 1 6 6 86 73
191102: 72 966 79 9 5 19
6448039: 9 912 7 974 65
127875318282: 151 675 17 18 697
67622755305: 88 530 88 868 8 3 18 5
1068000311359: 6 3 4 2 5 60 8 3 1 1 353 5
466005: 1 9 608 87 661
430651: 2 3 8 9 5 5 6 162 404 2 7
1773856371877: 126 7 5 20 7 929 68 4 7
528: 6 1 63 82 5
140593361: 95 522 1 1 9 9 1 35 6
7544102747: 47 4 209 2 3 8 8 3 3 8 5 4
8634559: 85 78 56 479 80
62905: 909 150 59 2 422
292589: 1 2 7 9 386 8 3 3 4 710 7
446: 430 14 2
170800: 5 7 3 8 6 38 13 762 8 1 7
6819: 93 67 485 94 9
76499651: 114 54 69 234 6 3 2 7
31731255: 7 9 524 6 7 751
7715: 952 360 5 546 601 8
307120629: 4 515 7 7 6 973 2 2 628
267: 7 46 80 55 79
2614399: 6 6 298 156 9 478 6 91
1116203161: 890 226 20 31 59
171867043: 2 604 22 86 6 4 90 3
4371039: 125 5 233 4 57 5 6 459
845076971948: 332 3 6 986 418 86
70116840: 13 860 1 7 3 6 1 67 57
951088124811: 444 7 1 13 1 1 6 76 1 51
1373244: 915 42 5 38 3
82513: 9 33 711 4 109
45144: 22 7 170 86 9
61041: 8 8 2 25 8 7 1 469 9 65
378239: 30 58 645 86 6 8
1984785: 5 5 9 7 3 4 33 724 8 204
413932290441: 3 3 88 1 92 83 2 1 2 8 4 1
598070: 847 70 511 9 52
26558: 4 152 6 70 3 1 72 7 1 7 1
24463936: 6 5 128 812
211343: 78 33 1 8 14 445 2 38 5
60353407: 94 2 6 32 638 59 7 702
467747: 4 22 37 8 747
115242958: 38 414 3 956
2230448: 9 5 106 5 5 6 5 39 4 638
58344: 2 53 374 1 17 8
131586: 3 599 5 8 22 1 768 7 33
11867403510: 51 88 520 46 565 9
79235: 22 50 9 8 32
15889035: 45 57 1 98 7 74 849 1
18966: 21 9 629 19 77
8988082: 898 807 8 4
54296660630: 31 5 58 26 8 660 627
6454981800: 7 838 9 872 6 7 9 49 2 9
403020: 875 2 349 8 2 1 2 6
3060222: 30 587 10 523 989
5310339307: 65 6 14 26 831 895 9
17409: 9 47 5 788 9
206: 41 63 88 14
129745960037: 73 3 4 652 5 2 7 907 4 5
4048704: 30 5 746 81 64
30240015: 93 75 25 270 8 2 15
8036956: 8 2 85 1 4 1 82 7 9 1 5 2
5343: 3 89 2 3
123430233768: 974 88 3 436 4 1 3 8 4 6
99212258: 83 4 32 61 2 36 968
57318: 46 2 9 302 3 53 3 5 229
9114: 329 3 309 6 7
1913560: 7 797 7 34 1 40
17631: 12 837 871 43 1
4398351732: 10 93 146 618 69
231244830: 7 217 7 4 28 927 5 1 3 8
299377898546: 8 4 9 44 2 9 9 76 7 4 873
365237: 64 70 891 68 8
21963729363: 3 9 3 8 8 2 52 5 7 293 63
577636309: 736 90 927 86 1 84 24
4701436152: 3 2 61 9 6 5 63 1 7 23 5 5
18319317: 619 52 3 3 569 6 8 917
8517034175: 73 2 7 85 75 2 1 34 177
15873587: 29 42 36 1 2 181 249
3612897: 5 44 4 564 834 3 9
7525784: 8 9 6 1 81 5 163 1 9 37 2
9418627: 269 1 7 5 5 7 5
600805: 81 7 62 4 780 25
3840018: 5 400 6 55 621 41 84 3
14562: 3 88 55 6 36
2245654: 655 3 43 5 82 34 56
211: 4 33 1 79
1397321: 35 3 5 6 789
8765: 6 1 863 7 5 1
147924179: 581 67 22 38 743
11728: 871 301 8
3788177177: 2 5 12 874 3 74 717 7
61232430241: 8 60 89 4 8 2 1 8 550 8 1
1956156160: 244 51 952 8 10
2122390874: 14 7 22 390 874
17888: 80 211 919 6 83
6350878370: 720 7 57 7 89 8 1 2 371
5455889563: 81 9 3 9 7 748 3
102: 7 10 3 82
94821797128: 9 474 4 3 6 834 4 4 4 4 4
5891846934: 4 7 850 9 18 3 9 7 2 936
286026: 9 77 28 5 62 6 13
317614: 6 68 74 92 821 22
468024: 813 80 7 65 3 8
1676819: 159 13 8 97 40 6 256
2683103744: 9 1 78 6 9 8 453 1 2 80 7
3877066: 24 853 39 4
20088: 33 97 3 425 36
216166095: 4 310 2 7 5 2 8 5 23 865
492008: 8 93 76 6 11
19498811: 19 498 6 8 12 9
2029193249: 56 4 3 69 34 38 2 7
10937475010: 6 75 63 60 7 643 10
26303224269: 3 8 9 4 7 57 3 77 2 426 9
73291559: 21 2 7 7 304 3 98 258 3
23451137730: 2 35 2 38 72 394 45
7819504: 99 631 51 94 35 1 69
71057172: 710 564 7 30 6 36
7171080: 223 938 1 772 93 8
8971: 14 9 5 6 1
1447891956: 560 90 57 6 9 84
1419987030: 1 3 35 4 7 83 4 1 8 47 3
1212: 2 7 7 1 240
107: 7 2 35
207204486: 7 8 8 548 9 84 3 80 2 6
176080: 97 7 84 68 20
6853476: 6 7 1 97 449 2 3
15084: 55 600 4 849 7
559994365: 671 4 488 5 4 6 6 5 9 85
5694276: 4 49 642 6 679 6 93 82
604564037: 7 85 14 81 77
485: 12 35 48 1 7 3 6
32095440083: 90 780 381 12 8 3
4710071: 59 61 1 79 8 8
173751142: 16 96 2 413 11 42
97369: 162 1 8 569 70
293653920: 77 696 3 8 7 6 1 265 68
128726254202: 9 7 6 5 9 1 8 8 6 3 40 85
8799: 8 72 7 9
57550: 781 6 3 59 2 21 511 9 2
131405072: 8 6 8 765 2 80 7 4 40 4
131174707: 4 363 7 2 49 30 7 2
183458: 9 33 6 89 468
1406: 1 9 4 21 2 9 6 7 799 84 5
5952266: 49 14 317 5 94
74400042: 86 865 9 9 50 95
510815048: 7 1 3 706 1 436 89 77 8
2196481428: 2 9 3 4 1 5 6 4 75 3 3 428
727: 16 39 4 97 2
46563196: 41 4 471 367 725 19 9
14983776037: 4 994 592 30 36
985376: 6 4 63 37 6 1 4
4031429: 650 31 7 13 2 3
430736587: 7 3 59 36 586
11125343793: 9 9 7 9 288 4 4 9 6 99 95
1274327083900: 576 618 590 26 85
2497: 1 88 80 81 7
280368: 1 2 5 3 9 395 49 5 3 66
265499063: 4 1 5 702 1 6 9 7 7 5 8 68
126364: 1 6 24 7 8 9 8 90 8 76
322259269026: 5 3 75 25 4 517 28 56
1981800309: 16 4 83 912 951
3697416: 260 7 949 5 3 267
5390737515: 9 5 8 28 656 5 16 547 6
7303618: 72 96 7 105 515
1421983140: 4 38 8 67 8 6 1 520 9 6 4
2492: 26 45 2 5 60 81 2 3 1
11194052: 7 6 7 5 8 9 26 67 69 919
114971376580: 934 387 51 87 65 77
83308: 257 40 97 8 292
11903198209: 72 4 2 5 6 33 7 6 9 8 7 71
14816: 6 454 3 8 4
33053: 7 6 5 374 83 517
73001511142704: 338 8 1 7 665 9 96 36 9
180317: 22 5 3 6 317
17683526: 6 4 3 1 6 2 9 4 7 5 9 227
14944227: 45 453 14 3 27
1956: 491 518 4 2 464 476 1
5064: 93 45 196 5 678
28619025776896: 7 8 48 64 8 581 231 2 8
882450: 84 18 814 9 1 954
718755602387: 987 98 75 7 20 851 97
607718: 970 7 3 31 2 2 9 9
10081961: 292 792 93 74 689
72242768: 528 3 27 76 9 6
153305614525: 37 6 5 6 6 661 9 81 6 2 7
16300905: 41 719 8 389 24 69
6956: 1 6 7 49 971 4 2 6 7 709
82397: 7 1 22 93 6 990 5 2 7 7
207456: 2 4 4 8 76 8 76 81 5 6 8
7366: 8 92 6
7382265744: 6 7 5 6 4 5 3 8 54 5 8 438
1867: 3 949 2 877 36
262198: 8 1 9 4 5 30 12 10 3 39 1
2140: 6 8 719 407 928 1 3 68
83351738: 20 8 799 652 58
166375650665: 603 4 5 84 821 6 66
147066357296: 7 35 3 31 784 2 4 9 6 1
19865687: 9 2 1 2 91 8 124 7 499
693281633: 685 7 792 489 633
654: 4 1 43 201 7
27648: 1 6 8 2 108
1544409: 28 8 9 6 4 4 9 3 793 9 7 9
2146603495: 3 68 29 3 9 17 99 1 59 5
5292: 69 4 11 7 9
3949647: 393 3 25 2 67
1300935485058: 71 5 6 62 9 94 800 6 43
605416: 34 9 3 3 3 40 6 6 40 8 8
9567810: 433 969 36 3 454 63
6662189364: 322 19 803 365 226 6
803491510: 44 938 447 1 6 4 46
319315026: 841 7 413 1 437 579
21535377: 655 8 87 286 323
18604826: 4 11 8 5 968 8 340 1 2 9
184274: 5 233 774 32 24 6
91162855: 479 512 289 19 7 656
79: 7 3 8
20469390: 22 4 2 7 8 67 4 2 9 1 849
52122: 81 68 867 3 3 51
114848: 188 63 45 4 97
15043698: 14 7 1 6 189 56 36 9 6 9
1669: 216 491 4 960 1 1
57407652: 389 473 6 52 519 69
283080: 1 599 5 6 7 50 6 5 84
54899: 33 94 154 967 13
968081957: 27 56 386 91 939 9
1824060251: 84 84 25 86 48 200
343504: 80 90 4 63 98 8
9406899360: 162 927 522 3 40
66: 6 1 60
665541148: 64 478 9 91 239
15220546: 1 72 147 695 46
16593192: 29 5 1 342 2 87 16 86 8
266660: 273 120 5 2 335
145411253: 7 24 3 864 52
1488898676: 74 3 4 8 3 4 31 2 46 69 4
204709132: 6 78 81 2 2 3 2 3 616 7 6
13168868667: 155 944 7 63 90
5211084: 94 2 36 16 2 3 15 5 9
239035: 7 6 196 338 697
79918080: 66 9 7 159 523 8 6 86 4
1824702: 2 7 48 28 921 800 701
131560: 5 7 2 46 5
14597440: 87 29 715 8 22
558656: 26 65 33 95 7
573: 9 86 3 2 3
6387481846: 29 57 4 67 20 1 3 9 4 4 8
17042: 5 46 55 462 3 4
44168607: 988 587 2 4 701
273815126: 1 11 8 327 46 31
7921498223: 7 8 98 32 3 6 1 91 1 21 9
2245608984: 249 427 85 9 897 88
36458428589: 958 6 5 9 1 7 8 2 3 6 3 7
24452: 2 5 7 6 75
462268: 17 87 548 709 1
1873904281746: 428 41 89 54 9 9 65 9 6
1518959335687: 1 2 728 644 5 359 2 9 7
3519: 4 7 5 3 5 6 4 901 16 42 6
329767: 916 9 40 7
92006: 9 64 6 3 890 9 79 9 8
623659532: 2 621 659 4 1 30
1158: 4 6 97 8 9
3111: 15 1 2 83 70 17
19719070: 6 1 9 7 750 7 5 8 3 10 7 1
44340: 9 76 512 1 91 727 3
82544: 2 77 67 8 1
8263903262559: 8 5 5 9 8 811 2 2 4 9 27 6
157262143235: 8 5 39 420 714 4 6 7 5
104541876: 9 675 779 1 876
66225758971: 4 2 4 6 7 8 39 82 7 8 9 3
666763201: 5 11 5 54 9 600 2 6
1553118: 652 6 397 41 13
537907321: 572 24 94 95 785 838
38295402: 851 90 79 5 7
1044: 81 5 6 876 77
4814391: 67 24 1 716 9
43347045: 405 28 409 61 48
14000704: 93 965 4 39 484
148494: 2 7 21 706 6 4 2 1 4 2 7
2087576160: 332 859 6 4 5 61
39096: 52 3 9 64 74 1 58 6 18
93081385: 54 1 17 23 57 387
438497: 650 33 5 8 90 7 8 9
1957081: 46 71 771 847 564 2
16973783: 1 484 443 3 79
58567835: 60 7 2 1 96 6 4 5 677 9 8
741152: 30 43 7 27 9
358872444: 6 7 6 59 7 63 6 5 37 1 1 9
1356: 81 54 339 1 873 8
579: 6 7 18 515 4
298964: 76 1 613 3 9 9 4 4 5 6 4 5
7844: 1 93 5 7 74
35269280: 5 925 6 79 46 80
101029: 117 46 422 360 65 29
40800: 50 4 8 25 74 8 8 3 1 1
458716: 48 1 695 88 1 5 2 51 7 6
1706: 82 9 394 563 11
5516955400: 9 7 8 2 643 30 5 7 5 55 8
10841741: 90 2 6 5 440 47 9 371 8
819495: 1 9 6 37 805 6 2 4 9 6 7 4
22154675400: 6 70 839 55 664 663
972026: 9 24 45 23 3
5571: 9 8 8 28 6 8 8 3 9 6 609
82367: 2 91 2 5 44 79 709 399
10764106835: 85 421 5 76 43 586
690914026: 94 98 187 75 2
324456: 3 1 926 42 517 980 8
9979753: 37 425 4 6 1 9 7 28 430
1214098609828: 246 768 984 9 964 5 5
5445415212: 789 29 85 93 665 864
232925769: 800 5 86 417 57
3562762: 649 68 88 85 69 40
3024072: 25 79 4 6 6 87 6 6 7 8 9
171632276: 439 9 39 71 27 6
2878475: 533 6 21 9 84 1
250064836: 6 8 884 745 32 388 49
71568: 7 669 993 35 42
10740: 94 6 7 31 9
130429634: 96 347 7 4 7 3 264 8 6
142560: 137 1 1 4 561
268464239294: 725 57 9 37 925 7 39
14844538: 34 6 4 330 6 742 71
2280: 74 7 47 5 4
194958990: 215 11 6 924 41 86
525871833413: 72 7 249 83 3 2 2 6 7 5 2
2133354176: 5 553 92 9 857 80
825900: 103 89 9 56 1 30 3
100662626858: 2 2 3 253 22 93 82 8 58
20442464: 2 8 8 2 1 3 7 9 8 5 94 2
4177: 56 1 71 189 9
13529345: 2 7 5 29 344
41013168737: 422 729 7 14 7 99 464
1461696: 2 2 13 2 28 98
6768366264: 450 99 82 67 6 374
3301: 4 5 363 26 8
1856: 3 4 3 8 7 680
622356: 4 9 8 6 5 2 470 5 48 963
901318: 997 549 583
11093355: 6 64 3 39 735
3786516180217: 3 4 8 8 744 2 28 594 9 7
1122417: 2 58 4 69 93
12192: 43 337 5 48 6 2 81 421
137093: 340 7 469 168 5
200046: 7 21 15 7 91 66
974926680: 6 103 53 487 78 60
237: 1 3 9 66 3
767748: 2 1 1 22 734 934
1185073: 3 5 28 9 4 103 9 7 62 5
194340763406: 4 86 4 1 3 1 4 8 1 6 918 3
437870620: 973 5 153 76 9 9
1915429459948: 31 529 9 7 56 274 75 9
129448447: 1 84 92 635 7
2404856: 20 481 8 6 53
100356: 9 75 2 3 6 97 792 8 34
34368: 28 7 55 3 30 53 2 3 96
3053309: 812 6 4 626 933
580957: 7 4 545 7 955
75514741: 32 3 959 4 210
516123688: 5 84 28 844 52 808
6404552: 679 393 8 6 8 4
26248222: 3 8 78 1 91 7 22
230699: 24 12 35 8 21
48214854: 7 48 8 4 6 25 210 9 97 9
356308408569: 2 5 3 59 444 9 55 3 67
152001: 5 4 87 5 1 87 8 51 34 6 1
2375050: 47 15 912 3 7 2 3 76
2083231: 7 24 4 9 205 76 3 4 6 9
70434168: 623 345 460 327 3
256778: 48 419 5 544 10
17127218: 428 4 716 8 48
194256: 4 9 1 32 186 93 4 3 1 9
9170: 555 7 627 645 5
603471374: 7 862 710 3 75
5315744: 29 45 799 8 3 2 19 4 4 2
28950089840: 81 9 6 42 8 6 5 898 39
1899345324: 74 538 6 9 2 31 57 69
25580: 1 1 4 1 8 3 2 4 915 1 657
517756140: 127 71 33 4 87 5
11559915144139: 231 5 4 5 915 144 139
458808984: 31 456 575 941 909
1156: 9 16 35 106 3 867 1
158001: 7 305 140 2 8 342
591572808: 4 6 42 9 7 8 19 4 8 4 27 6
142291625: 9 88 3 406 8 16 6 41
10118: 20 42 38 64 54
272079360: 140 8 85 21 48 224
4729: 44 2 48 5 38 6 944 9 8
620: 5 187 5 3 29
45980860320: 770 51 89 90 76 92
18984313: 224 2 120 7 17 299
1621080: 7 4 8 42 3 804 60 6
816: 5 82 88 312 5
126656112: 4 4 4 2 6 17 31 4 2 66 4 1
4956502311: 71 24 7 658 695
600688282: 1 81 3 1 1 8 1 21 5 7 8 2
349496: 54 20 65 967 316
18120: 9 169 92 33 58 544
2076065: 5 1 91 94 8 3 3
387582752: 3 6 2 441 484 97 997 2
43236: 9 4 31 4 7 7 3 72 5 31 1 5
5185259: 637 1 814 9 70
438: 7 2 4 1 3
163296554683: 36 81 56 554 682
2638: 86 8 629 2 4
370152: 9 6 5 241 2 5 2 2 7 8 9
252671: 128 195 305 3 15
73033867008: 409 816 47 776 6
12385: 4 277 2 576 82 4 1 888
683: 87 3 3 8 582
412633: 4 91 37 4 56 2 560 5 8
74802: 385 2 97 36 76
6077322: 53 982 1 7 648 37 1 5 9
507574876: 13 5 372 574 876
14321123: 2 7 2 741 1 464 4 7 476
97916488: 84 979 466 9 4 5 64 6 1
25856656: 6 570 67 335 7 2 2
353544: 64 6 8 9 15 731
5737365612: 35 541 2 303 14
2897665008: 4 7 8 875 8 7 7 9 8 12 2 6
867866972593: 867 866 97 2 560 32 1
627660: 31 513 384 324 3
247956255509: 247 1 95 6 2 4 9 6 510
3593202616: 5 987 6 8 6 8 9 73 6 1 6
5690: 8 9 63 71 9
1814772: 454 2 111 9 2 11 577
471955: 79 339 4 5 221 24 5
14081166: 6 735 106 8 19
101338037917: 536 18 7 5 2 8 3 6 13 9 5
5873208005: 3 2 6 23 5 1 7 2 3 60 8 5
11415228: 364 6 18 8 648 60
16633: 7 6 4 978 7
39318: 433 6 6 260 50 1 52 2 4
441012: 6 7 5 84 282 1 8 1 42 7 2
184115700: 5 661 75 97 38
105393: 1 7 2 539 5
39612: 747 2 84 5 56 6 3 8 3 60
9082523: 94 91 2 2 607 991 8
22752200452: 9 4 6 2 4 60 67 133 452
16732245: 4 8 43 641 9 21 36
6789: 699 8 620 577 1
272043: 711 1 6 912 167
960249: 583 549 7 7 3 6 1
9381848: 121 7 25 29 371
1476: 48 147 85 5 76
326673018: 43 1 9 92 5 688 90 1 7 1
17526: 84 851 4 813 6
77447: 4 7 781 9 34 3 1 5 72 7 9
17111462255950: 97 9 6 47 139 235 950
17181223089: 149 59 118 604 4 7 9 3
11586: 6 52 4 6 7 241 1 7 99
2716391: 4 6 2 65 54 1 3 95 9 56
3432106: 4 3 4 3 2 712 17 9 8 1 1 1
587300: 2 698 839
6752480: 67 51 65 74 10 88
21109821785: 3 88 2 60 55 2 7 5 754 9
124648991: 398 647 869 6 52
1116032879: 5 5 37 4 2 603 1 3 79
195581: 99 27 73 446 6
127109: 2 4 160 9 7 6 66 4 9 96 5
308350: 42 1 5 17 82 350
361771787: 888 582 1 6 6 7 7 48
19878: 6 420 683 110 6
304: 2 4 28 1 80
147574: 5 59 5 68 4
2448810: 409 53 4 21 5 53 4 7 9
719716: 6 389 64 196 8 4
1732728: 8 2 4 3 5 940 8 39 9 43
24551999152: 2 90 783 428 1 46 554
57836: 3 68 8 2 27 5 9
134278200849: 2 3 6 45 8 7 520 7 5 848
79939703763: 4 6 2 7 5 4 1 4 3 29 83 9
52137948672: 931 436 534 31 3 8 96
9726654: 77 6 98 747 6 654
122932620: 135 57 102 9 986 634
262217569: 73 8 7 7 5 9 5 29 603 1 3
32941: 6 5 2 9 2 990 6 8 4 1 6 7
65761: 8 4 8 685 1
71664: 7 1 61 5 4
30188691225: 147 720 595 495 573
534605: 9 25 24 99 8
22307765: 367 262 29 8 37
123232: 485 131 1 5 2
179429560: 76 35 30 235 9
67914: 7 4 30 6 6 137 27 4 2 6
107951753: 6 7 257 5 6 61 56
5783045: 691 62 8 96 6
730398027: 5 81 1 57 2 5 149 27
134916360: 4 195 27 9 93 6 5 30
3272988: 239 88 110 188 6
5886141: 318 522 87 7 7
813650145: 81 300 526 4 406 158
420840: 5 3 827 3 7 68 532
8512852864405: 5 5 224 5 6 1 4 3 8 76 1 5
38682: 247 2 5 8 436 3
5256: 4 71 7 6
321720: 30 7 702 2 5 26 2 7 5
70454400: 2 3 7 2 98 614 4 2 82 4 8
154909476: 396 5 9 64 654 96 1 6 6
12480617: 2 5 52 24 617
132691: 1 73 767
10245752: 13 69 62 7 124 7
36484493: 6 1 5 705 8 9 77 9 8 1 7 3
14420234120: 79 65 202 341 23
1440: 9 1 6 128 1 8
907648961: 7 1 83 248 1 7 4 995 1 1
38653398: 66 23 7 3 9 1 78 9 139 2
812462401: 434 26 188 6 72 12
3451: 9 1 3 4 7 3 9 56 2 4 395 7
12856859: 29 4 1 56 435
18345048481: 925 491 187 51 4 6 9 4
14362270: 51 7 926 3 7
145899018: 751 1 98 891 2 7 978
599135437: 22 19 9 3 5 436
36110793601: 398 30 6 8 56 9 600
2444762940: 710 427 384 3 21
141178320: 62 52 44 5 1 8 3 3 6 8 3 5
17031: 5 34 28
469049041: 7 2 180 7 2 4 6 43 5 6 9 1
200611: 2 31 67 8 90 901
59903676: 119 660 18 30 87 49
904348: 3 7 9 1 3 993 352
32426911445: 58 243 154 83 5 36 5
8159988: 3 513 57 5 53
264192030: 61 96 4 2 81 58 345
47245: 1 3 4 2 8 8 973 28 4 5 8 5
4019: 6 8 5 66 29 75
1908535419: 20 1 2 5 4 13 8 1 2 491 9
63495761472: 7 8 8 5 522 1 53 1 2 724
974547: 2 2 5 6 9 1 6 7 4 82 651
8464945: 8 1 33 4 1 5 8 697 71 8 9
35191519: 7 4 301 173 9 3 6 1 43
3809988720: 2 82 4 610 890 354 6 2
1974: 930 24 9 25 2
19950132400: 68 50 319 34 541
116117283: 59 6 855 466 80 3
7105321381: 2 94 37 660 679 9 2 1 2
200055003120: 16 61 64 8 41 9 6 85
7052183817: 7 8 197 905 2 44 2 8 3 7
30619382: 4 4 5 588 10 8 3 9 4 1 1 4
49486383: 8 3 737 3 40 61 745 1
3059155939: 6 978 548 92 8
17913: 5 9 198 5 21 2 1 8 9 23
2322270: 6 6 7 30 9 915
864437011221: 78 42 3 6 16 190 6 9 3 7
9824074336: 982 399 8 433 5 1
172953218: 6 90 87 334 62
3416363: 7 4 6 7 476 5 3 5 7 957 1
3482929737: 73 1 6 4 47 2 2 1 8 737
143276320: 43 7 595 4 80
6399648: 247 75 207 96 775 89
171394: 63 32 85 6 28
6163474: 11 56 25 9 74 1
9740881928: 493 4 4 320 11 4 348 8
282630796: 7 5 927 4 871 3
5329: 54 468 7 9 95
198832303516: 473 41 6 1 4 1 7 88 7
1592: 44 34 9 80 5
78037377: 86 7 9 66 27 746 4
1435: 8 6 63 94 7
330759891: 50 66 7 598 91
201052210549: 9 5 5 1 525 9 4 8 2 5 5 46
1625512034997: 61 50 20 835 17 1 931
531193971: 4 3 57 7 12 939 69
8729765: 8 4 241 515 67
3361296: 6 78 500 2 3 8 239
2575584850: 398 2 66 813 7 6 4 1 1 2
77725723: 61 2 942 920 129 313
1303: 9 57 119 7 8
12121579: 37 252 2 9 13
1332800: 74 9 2 796 4
525202: 22 19 22 6 1 57 589 99
6420440: 2 5 1 7 7 6 8 4 3 76 65
97021540: 87 3 97 2 153 7 1
4553395: 9 35 61 92 395
34433: 819 1 6 5 7
350904680: 2 8 8 207 453 8 4 1 6
1767: 2 76 10 95 58 94
841148: 36 8 473 148
140428093859: 9 197 4 9 2 9 5 4 2 5 55 9
1935426374140: 82 59 5 65 9 351 1 4 96

9
7/testinput Normal file
View File

@@ -0,0 +1,9 @@
190: 10 19
3267: 81 40 27
83: 17 5
156: 15 6
7290: 6 8 6 15
161011: 16 10 13
192: 17 8 14
21037: 9 7 18 13
292: 11 6 16 20

164
8/8.ipynb Normal file
View File

@@ -0,0 +1,164 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"344"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Load the larger test file and process it using the solution\n",
"file_path = 'input'\n",
"\n",
"def process_large_file(file_path):\n",
" with open(file_path, 'r') as file:\n",
" lines = [line.rstrip('\\n') for line in file.readlines()]\n",
" \n",
" height = len(lines)\n",
" width = len(lines[0]) if height > 0 else 0\n",
"\n",
" # Identify antennas and their frequencies\n",
" freq_map = {}\n",
" for y in range(height):\n",
" for x in range(width):\n",
" c = lines[y][x]\n",
" if c != '.':\n",
" if c not in freq_map:\n",
" freq_map[c] = []\n",
" freq_map[c].append((x, y))\n",
"\n",
" # A set to hold all unique antinode locations\n",
" antinodes = set()\n",
"\n",
" # Candidate λ values based on derived equations\n",
" lambdas = [2, -1, 1/3, 2/3]\n",
"\n",
" for freq, antennas in freq_map.items():\n",
" n = len(antennas)\n",
" if n < 2:\n",
" continue\n",
"\n",
" for i in range(n):\n",
" for j in range(i+1, n):\n",
" x1, y1 = antennas[i]\n",
" x2, y2 = antennas[j]\n",
" dx = x2 - x1\n",
" dy = y2 - y1\n",
"\n",
" for lam in lambdas:\n",
" px = x1 + lam * dx\n",
" py = y1 + lam * dy\n",
"\n",
" if abs(px - round(px)) < 1e-12 and abs(py - round(py)) < 1e-12:\n",
" rx = round(px)\n",
" ry = round(py)\n",
"\n",
" if 0 <= rx < width and 0 <= ry < height:\n",
" antinodes.add((rx, ry))\n",
"\n",
" # Output the number of unique antinode locations\n",
" return len(antinodes)\n",
"\n",
"process_large_file(file_path)\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1182"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def process_part_two(file_path):\n",
" with open(file_path, 'r') as file:\n",
" lines = [line.rstrip('\\n') for line in file.readlines()]\n",
"\n",
" height = len(lines)\n",
" width = len(lines[0]) if height > 0 else 0\n",
"\n",
" # Identify antennas and their frequencies\n",
" freq_map = {}\n",
" for y in range(height):\n",
" for x in range(width):\n",
" c = lines[y][x]\n",
" if c != '.':\n",
" if c not in freq_map:\n",
" freq_map[c] = []\n",
" freq_map[c].append((x, y))\n",
"\n",
" # A set to hold all unique antinode locations\n",
" antinodes = set()\n",
"\n",
" # For each frequency group, consider all pairs of antennas\n",
" for freq, antennas in freq_map.items():\n",
" n = len(antennas)\n",
" if n < 2:\n",
" continue\n",
"\n",
" for i in range(n):\n",
" for j in range(i + 1, n):\n",
" x1, y1 = antennas[i]\n",
" x2, y2 = antennas[j]\n",
"\n",
" # Calculate the collinearity condition\n",
" for x in range(width):\n",
" for y in range(height):\n",
" if (x2 - x1) * (y - y1) == (y2 - y1) * (x - x1):\n",
" antinodes.add((x, y))\n",
"\n",
" # Include the positions of all antennas as antinodes\n",
" for freq, antennas in freq_map.items():\n",
" for x, y in antennas:\n",
" antinodes.add((x, y))\n",
"\n",
" # Return the number of unique antinode locations\n",
" return len(antinodes)\n",
"\n",
"\n",
"# Process the larger test file for part two\n",
"process_part_two('input')\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

50
8/input Normal file
View File

@@ -0,0 +1,50 @@
....K..........................8.................z
.....n..............r...........z.................
.......................w....8.............3...E...
.....Q.....U..4.........8.........................
...............rc...w........i....................
...........K.........i..2.........................
..................4.....i.........................
K.....n....................w...........z..........
..U......Q........................I...............
..........i.....I.....Q....g....................5E
..Q......................................5........
..........c............8......w...g..........5....
.............................I.O..................
.Z.............4....b.....................k.......
..n........4......r..g..6..c.............3........
....Z............c................................
...................................x..............
.......................................O..........
...............U...................E..........5...
.....f..........................OI3......k........
..m.......o......F.......R........x...............
m...........o..v6..3...............X..............
..............H6v.....F.g.....................W...
...........o....Fb....v...............E...........
...Z.............a................................
......U6.............V............................
.9.............b..............pTk.................
.......m........V.........H1....x.................
...m.................H....................MX......
............t.a............H......................
........Z...a............v.....1..T..p.W..X.......
.............................9...x.......p........
.....J.....................V..1................0..
...........r..j..........a............pT..........
.G..................J...N......f..................
...........G......T....B........W.e...........M...
..........j.............Rk.............M..........
.........q.............MB......R.F..1..P....X...f.
............................V....o...........h....
...........................................W......
......b......u............................e.......
.............................................0....
..CA....Gt..O........................7.....e....0.
C.u......A..9J..N........................h.....e..
uj....q..........N.2..................7...........
G....N.....uJ...............................0.....
.................B................P.......h.......
...C....q...........R.........P...................
.....q..tC....2.9.....B............P....f.........
...............2.................................7

4
8/test.py Normal file
View File

@@ -0,0 +1,4 @@
from tqdm import tqdm
for i in range(6e9):
pass