Skip to content

Commit

Permalink
organized repo, added pytorch notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
VaasuDevanS committed Oct 18, 2023
1 parent 0879e1a commit c760ec5
Show file tree
Hide file tree
Showing 10 changed files with 781 additions and 285 deletions.
160 changes: 160 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
1 change: 1 addition & 0 deletions Advent of Code/2015.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"collapsed_sections":["Dat3goSTC4t6","Zpx1viglFIax","VTr_ew86KGCN","YdREkSr70XI4","Tn6j_nttQZc_","8K52PkUZW8c7","1YiOzBz-a4Dz"],"toc_visible":true,"authorship_tag":"ABX9TyPTcWJiAnPcEA54FqCPKTS4"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["https://adventofcode.com/2015"],"metadata":{"id":"q6GJgh3DKDod"}},{"cell_type":"code","source":["# @title Download Inputs\n","year = 2015 # @param {type:\"integer\"}\n","\n","!pip install -q 'advent-of-code-data[nb]'\n","\n","import os\n","os.environ['AOC_SESSION'] = '53616c7465645f5fff2fcc509a3a0f13ebc7e030d9d5819056b812eb14da7dcea31ada25507ca09c5b7f1ba139cfc1cb1659d303ed3e512a0444a2224945055f'\n","\n","os.system(f'mkdir {year}')\n","for day in range(1, 26):\n"," os.system(f'aocd {day} {year} > {year}/day{day:02}.txt')"],"metadata":{"id":"jVAZUtUpirOa","cellView":"form"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["# Day 1: Not Quite Lisp ⭐⭐"],"metadata":{"id":"Dat3goSTC4t6"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"PAL62Hs64dVm"},"outputs":[],"source":["def find_floor(characters: str) -> int:\n"," return sum(1 if ch == '(' else -1 for ch in characters)\n","\n","\n","assert find_floor('(())') == find_floor('()()') == 0\n","assert find_floor('(((') == find_floor('(()(()(') == 3\n","assert find_floor('))(((((') == 3\n","assert find_floor('())') == find_floor('))(') == -1\n","assert find_floor(')))') == find_floor(')())())') == -3"]},{"cell_type":"code","source":["def find_position_basement(characters: str) -> int:\n"," floor = 0\n"," for ix, ch in enumerate(characters, start=1):\n"," floor += 1 if ch == '(' else -1\n"," if floor == -1:\n"," return ix\n","\n","assert find_position_basement(')') == 1\n","assert find_position_basement('()())') == 5"],"metadata":{"id":"kh90PGMOC5hx"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["with open('2015/day01.txt') as file:\n"," puzzle_input: str = file.read().strip()\n"," print(find_floor(puzzle_input))\n"," print(find_position_basement(puzzle_input))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"b0JX3Rv3FAN5","executionInfo":{"status":"ok","timestamp":1695867191405,"user_tz":180,"elapsed":188,"user":{"displayName":"Vaasudevan Srinivasan","userId":"15487097235806161418"}},"outputId":"241a66e5-af11-4ce5-cdcb-b4de0b19a916"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["138\n","1771\n"]}]},{"cell_type":"markdown","source":["# Day 2: I Was Told There Would Be No Math ⭐⭐"],"metadata":{"id":"Zpx1viglFIax"}},{"cell_type":"code","source":["def calculate_sq_ft(dimensions: list[str]) -> int:\n","\n"," total_sq_ft = 0\n"," for dimension in dimensions:\n"," l, w, h = map(float, dimension.split('x'))\n"," side_a, side_b = sorted((l, w, h))[:2]\n"," sq_ft = (2 * l * w) + (2 * w * h) + (2 * h * l)\n"," slack = side_a * side_b\n"," total_sq_ft += sq_ft + slack\n","\n"," return total_sq_ft\n","\n","\n","assert calculate_sq_ft(['2x3x4']) == 58\n","assert calculate_sq_ft(['1x1x10']) == 43"],"metadata":{"id":"4rm7V5r4FMX5"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["def calculate_ribbon_ft(dimensions: list[str]) -> int:\n","\n"," total_ribbon_ft = 0\n"," for dimension in dimensions:\n"," l, w, h = map(float, dimension.split('x'))\n"," side_a, side_b = sorted((l, w, h))[:2]\n"," total_ribbon_ft += (side_a * 2) + (side_b * 2) + (l * w * h)\n","\n"," return total_ribbon_ft\n","\n","\n","assert calculate_ribbon_ft(['2x3x4']) == 34\n","assert calculate_ribbon_ft(['1x1x10']) == 14"],"metadata":{"id":"uYQiRKiDFRrb"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["with open('2015/day02.txt') as file:\n"," puzzle_input: list[str] = file.read().strip().split('\\n')\n"," print(calculate_sq_ft(puzzle_input))\n"," print(calculate_ribbon_ft(puzzle_input))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"9iUqH9spFsNJ","executionInfo":{"status":"ok","timestamp":1695867199165,"user_tz":180,"elapsed":5,"user":{"displayName":"Vaasudevan Srinivasan","userId":"15487097235806161418"}},"outputId":"0318f209-f861-4bb6-98eb-58155bea2643"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["1606483.0\n","3842356.0\n"]}]},{"cell_type":"markdown","source":["# Day 5: Doesn't He Have Intern-Elves For This? ⭐"],"metadata":{"id":"VTr_ew86KGCN"}},{"cell_type":"code","source":["import re\n","\n","def count_nice_strings(strings: list[str]) -> int:\n","\n"," count = 0\n","\n"," for string in strings:\n","\n"," vowels = re.findall(r'[aeiou]', string)\n"," repeated = re.findall(r'(\\w)\\1+', string)\n"," is_naughty = any(i in string for i in ['ab', 'cd', 'pq', 'xy'])\n","\n"," if len(vowels) >= 3 and len(repeated) >= 1 and not is_naughty:\n"," count += 1\n","\n"," return count\n","\n","\n","assert count_nice_strings(['ugknbfddgicrmopn']) == 1\n","assert count_nice_strings(['aaa']) == 1\n","assert count_nice_strings(['jchzalrnumimnmhp']) == 0\n","assert count_nice_strings(['haegwjzuvuyypxyu']) == 0\n","assert count_nice_strings(['dvszwmarrgswjxmb']) == 0"],"metadata":{"id":"MZaqvFZBJNwW"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["with open('2015/day05.txt') as file:\n"," puzzle_input: list[str] = file.read().strip().split('\\n')\n"," print(count_nice_strings(puzzle_input))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"UdHC34ba_47G","executionInfo":{"status":"ok","timestamp":1695942868868,"user_tz":180,"elapsed":191,"user":{"displayName":"Vaasudevan Srinivasan","userId":"15487097235806161418"}},"outputId":"c777d688-2412-4b64-80d8-5caeb634f683"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["238\n"]}]},{"cell_type":"markdown","source":["# Day 6: Probably a Fire Hazard ⭐⭐"],"metadata":{"id":"YdREkSr70XI4"}},{"cell_type":"code","source":["import numpy as np\n","import re\n","\n","def count_lit_lights(instructions: list[str]) -> int:\n","\n"," lights = np.zeros((1000, 1000), dtype=bool)\n","\n"," for instruction in instructions:\n","\n"," (a, b), (c, d) = np.asarray(re.findall('(\\d*),(\\d*)', instruction),\n"," dtype='u8')\n","\n"," c, d = int(c + 1), int(d + 1)\n","\n"," if instruction.startswith('turn on'):\n"," lights[a:c, b:d] = True\n","\n"," elif instruction.startswith('turn off'):\n"," lights[a:c, b:d] = False\n","\n"," elif instruction.startswith('toggle'):\n"," lights[a:c, b:d] = np.invert(lights[a:c, b:d])\n","\n"," return np.sum(lights)\n","\n","\n","def brightness_lights(instructions: list[str]) -> int:\n","\n"," lights = np.zeros((1000, 1000))\n","\n"," for instruction in instructions:\n","\n"," (a, b), (c, d) = np.asarray(re.findall('(\\d*),(\\d*)', instruction),\n"," dtype='u8')\n","\n"," c, d = int(c + 1), int(d + 1)\n","\n"," if instruction.startswith('turn on'):\n"," lights[a:c, b:d] += 1\n","\n"," elif instruction.startswith('turn off'):\n"," lights[a:c, b:d] = np.clip(lights[a:c, b:d] - 1, 0, None)\n","\n"," elif instruction.startswith('toggle'):\n"," lights[a:c, b:d] += 2\n","\n"," return int(np.sum(lights))"],"metadata":{"id":"HaRXzx9E2NF_"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["with open('2015/day06.txt') as file:\n"," puzzle_input: list[str] = file.read().strip().split('\\n')\n"," print(count_lit_lights(puzzle_input))\n"," print(brightness_lights(puzzle_input))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"Tn9cgT79Kr2r","executionInfo":{"status":"ok","timestamp":1695998070800,"user_tz":180,"elapsed":9,"user":{"displayName":"Vaasudevan Srinivasan","userId":"15487097235806161418"}},"outputId":"a5a55963-b4ba-4471-8e3e-134329fa95d5"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["377891\n","14110788\n"]}]},{"cell_type":"markdown","source":["# Day 9: All in a Single Night ⭐⭐"],"metadata":{"id":"Tn6j_nttQZc_"}},{"cell_type":"code","source":["from collections import defaultdict as ddict\n","import itertools\n","import re\n","\n","def find_distance_of_shortest_route(routes: list[str]) -> int:\n","\n"," cities, distances = set(), ddict(dict)\n"," for route in routes:\n"," start, end, distance = re.findall(r'(\\w+) to (\\w+) = (\\d+)', route)[0]\n"," distances[start][end] = int(distance)\n"," distances[end][start] = int(distance)\n"," cities.add(start)\n"," cities.add(end)\n","\n"," tsp_distances = ddict(int)\n"," possible_routes = list(itertools.permutations(cities))\n"," for route in possible_routes:\n"," for start, end in zip(route, route[1:]):\n"," tsp_distances[route] += distances[start][end]\n","\n"," # return min(tsp_distances.values())\n"," return max(tsp_distances.values())\n","\n","\n","example_route = ['London to Dublin = 464',\n"," 'London to Belfast = 518',\n"," 'Dublin to Belfast = 141']\n","\n","# assert find_distance_of_shortest_route(example_route) == 605\n","assert find_distance_of_shortest_route(example_route) == 982"],"metadata":{"id":"Do8WqV7sQaVD","executionInfo":{"status":"ok","timestamp":1696031393491,"user_tz":180,"elapsed":182,"user":{"displayName":"Vaasudevan Srinivasan","userId":"15487097235806161418"}}},"execution_count":24,"outputs":[]},{"cell_type":"code","source":["with open('2015/day09.txt') as file:\n"," puzzle_input: list[str] = file.read().strip().split('\\n')\n"," print(find_distance_of_shortest_route(puzzle_input))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"v8bWroYnQznY","executionInfo":{"status":"ok","timestamp":1696031396955,"user_tz":180,"elapsed":219,"user":{"displayName":"Vaasudevan Srinivasan","userId":"15487097235806161418"}},"outputId":"8176713c-6328-4296-b113-d0d64e927071"},"execution_count":25,"outputs":[{"output_type":"stream","name":"stdout","text":["736\n"]}]},{"cell_type":"markdown","source":["# Day 12: JSAbacusFramework.io ⭐"],"metadata":{"id":"8K52PkUZW8c7"}},{"cell_type":"code","source":["import re\n","\n","def sum_of_all_numbers(objects: list[str]) -> int:\n"," total = 0\n"," for obj in objects:\n"," total += sum(map(int, re.findall('-?\\d+', obj)))\n"," return total\n","\n","\n","assert sum_of_all_numbers(['[1,2,3]']) == sum_of_all_numbers(['{\"a\":2,\"b\":4}']) == 6\n","assert sum_of_all_numbers(['[[[3]]]']) == sum_of_all_numbers(['{\"a\":{\"b\":4},\"c\":-1}']) == 3\n","assert sum_of_all_numbers(['{\"a\":[-1,1]}']) == sum_of_all_numbers(['[-1,{\"a\":1}]']) == 0\n","assert sum_of_all_numbers(['[]']) == sum_of_all_numbers(['{}']) == 0"],"metadata":{"id":"MU2tSO12W9Kt","executionInfo":{"status":"ok","timestamp":1696032264433,"user_tz":180,"elapsed":221,"user":{"displayName":"Vaasudevan Srinivasan","userId":"15487097235806161418"}}},"execution_count":47,"outputs":[]},{"cell_type":"code","source":["with open('2015/day12.txt') as file:\n"," puzzle_input: list[str] = file.read().strip().split('\\n')\n"," print(sum_of_all_numbers(puzzle_input))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"smpbq6goW_X4","executionInfo":{"status":"ok","timestamp":1696032267385,"user_tz":180,"elapsed":251,"user":{"displayName":"Vaasudevan Srinivasan","userId":"15487097235806161418"}},"outputId":"678dfa3f-02bf-46c1-b966-abc4734c49b0"},"execution_count":48,"outputs":[{"output_type":"stream","name":"stdout","text":["156366\n"]}]},{"cell_type":"markdown","source":["# Day 17: No Such Thing as Too Much ⭐"],"metadata":{"id":"1YiOzBz-a4Dz"}},{"cell_type":"code","source":["import itertools\n","\n","def count_combos_containers(sizes: list[int], eggnog_litres: int) -> int:\n"," count = 0\n"," for size in range(1, len(sizes) + 1):\n"," for combo in itertools.combinations(sizes, size):\n"," if sum(combo) == eggnog_litres:\n"," count += 1\n"," return count\n","\n","\n","assert count_combos_containers([20, 15, 10, 5, 5], 25) == 4"],"metadata":{"id":"BbyaYjj4a4t9","executionInfo":{"status":"ok","timestamp":1696033127522,"user_tz":180,"elapsed":8,"user":{"displayName":"Vaasudevan Srinivasan","userId":"15487097235806161418"}}},"execution_count":67,"outputs":[]},{"cell_type":"code","source":["with open('2015/day17.txt') as file:\n"," puzzle_input: list[int] = list(map(int, file.read().strip().split('\\n')))\n"," print(count_combos_containers(puzzle_input, 150))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"bFSj1AQ-a6Ls","executionInfo":{"status":"ok","timestamp":1696033130300,"user_tz":180,"elapsed":719,"user":{"displayName":"Vaasudevan Srinivasan","userId":"15487097235806161418"}},"outputId":"7d325747-ea1f-4fad-c7fe-f48a1c1185d3"},"execution_count":68,"outputs":[{"output_type":"stream","name":"stdout","text":["1638\n"]}]}]}

Large diffs are not rendered by default.

Loading

0 comments on commit c760ec5

Please sign in to comment.