Skip to content

Commit

Permalink
adding the freeze
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoyira committed May 17, 2024
1 parent aeb1370 commit 5e2d4b3
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 18 deletions.
8 changes: 5 additions & 3 deletions _freeze/2023/day/1/index/execute-results/html.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions _freeze/2023/day/10/index/execute-results/html.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions _freeze/2023/day/2/index/execute-results/html.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions _freeze/2023/day/3/index/execute-results/html.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions _freeze/2023/day/6/index/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"hash": "4a9880534c941df3bf98f449b1af954d",
"hash": "47589059b5197229c7fde8ef6691680d",
"result": {
"engine": "jupyter",
"markdown": "---\ntitle: \"2023: Day 6\"\ndate: 2023-12-6\ncategories:\n - python\ndraft: false\n---\n\n## Setup\n\n[The original challenge](https://adventofcode.com/2023/day/6)\n\n[My data](input){target=\"_blank\"}\n\nNotes:\n\n- We arrive to Island Island\n- There should be a large pile of sand but there isn't\n- Boat races to win trip to Desert Island: fixed amount of time and boat has to travel as far as it can\n- Input: time allowed for each race and best distance until now\n- To win, we need to go farther than each current record holder\n- Boats are **toy boats**: we press a button to charge them, and release them to allow them to move.\n\n> Boats move faster if their button was held longer, but time spent holding the button counts against the total race time. You can only hold the button at the start of the race, and boats don't move until the button is released.\n\n> Your toy boat has a starting speed of zero millimeters per millisecond. For each whole millisecond you spend at the beginning of the race holding down the button, the boat's speed increases by one millimeter per millisecond.\n\n- This is an optimisation problem.\n- For each problem, we have several ways (amount of time we can press the button) that allow us to beat the current record holder.\n\n> To see how much margin of error you have, determine the number of ways you can beat the record in each race; in this example, if you multiply these values together, you get 288 (4 * 8 * 9).\n\n## Part 1\n\n::: {#8c371d1d .cell execution_count=1}\n``` {.python .cell-code}\nimport pandas as pd\nimport numpy as np\n```\n:::\n\n\n::: {#77566b2a .cell execution_count=2}\n``` {.python .cell-code}\nf = open(\"input\", \"r\")\ninput = f.readlines()\n# input is a list\n```\n:::\n\n\nExtracting the times:\n\n::: {#f34bbbaf .cell execution_count=3}\n``` {.python .cell-code}\nimport re\ntimes = re.findall('[0-9]+', input[0])\ntimes = list(map(int, times))\n```\n:::\n\n\nExtracting the distances:\n\n::: {#3037c206 .cell execution_count=4}\n``` {.python .cell-code}\ndistances = re.findall('[0-9]+', input[1])\ndistances = list(map(int, distances))\n```\n:::\n\n\nNext, I think I could write a function that, for any pair of times and distances, returns the count of different values of time that allow to surpass the current record.\n\n\nFirst, let's write the code of a particular case (using the example in the prompt)\n\n::: {#2dba84b3 .cell execution_count=5}\n``` {.python .cell-code}\ntime = 7\ndistance = 9\nn_possible_wins = 0\n\nfor i in range(time):\n speed = i\n available_time = time - i\n my_distance = speed*available_time\n\n if my_distance > distance:\n n_possible_wins += 1\n\nprint(n_possible_wins)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n4\n```\n:::\n:::\n\n\n::: {#fe19ca82 .cell execution_count=6}\n``` {.python .cell-code}\ndef calculate_n_ways_to_win(time, distance):\n n_possible_wins = 0\n\n for i in range(time):\n speed = i\n available_time = time - i\n my_distance = speed*available_time\n\n if my_distance > distance:\n n_possible_wins += 1\n\n return(n_possible_wins)\n```\n:::\n\n\n::: {#c2d98525 .cell execution_count=7}\n``` {.python .cell-code}\ncalculate_n_ways_to_win(7, 9)\n```\n\n::: {.cell-output .cell-output-display execution_count=7}\n```\n4\n```\n:::\n:::\n\n\nNow I need to iterate across the two lists. I would like to do that using something similar to map2, instead of a for loop\n\n::: {#ebfa57aa .cell execution_count=8}\n``` {.python .cell-code}\nn_ways = list(map(calculate_n_ways_to_win, times, distances))\n```\n:::\n\n\n::: {#ded74d04 .cell execution_count=9}\n``` {.python .cell-code}\nimport operator\nfrom functools import reduce\n\nreduce(operator.mul, n_ways)\n```\n\n::: {.cell-output .cell-output-display execution_count=9}\n```\n1660968\n```\n:::\n:::\n\n\n## Part 2\n\nThe input interpretation changed and all the values of time and distance now actually represent two big numbers.\n\n::: {#fd897df6 .cell execution_count=10}\n``` {.python .cell-code}\ncalculate_n_ways_to_win(47986698, 400121310111540)\n```\n\n::: {.cell-output .cell-output-display execution_count=10}\n```\n26499773\n```\n:::\n:::\n\n\n",
"markdown": "---\ntitle: \"2023: Day 6 - Wait For It\"\ndate: 2023-12-6\ncategories:\n - python\ndraft: false\n---\n\n## Setup\n\n[The original challenge](https://adventofcode.com/2023/day/6)\n\n[My data](input){target=\"_blank\"}\n\nNotes:\n\n- We arrive to Island Island\n- There should be a large pile of sand but there isn't\n- Boat races to win trip to Desert Island: fixed amount of time and boat has to travel as far as it can\n- Input: time allowed for each race and best distance until now\n- To win, we need to go farther than each current record holder\n- Boats are **toy boats**: we press a button to charge them, and release them to allow them to move.\n\n> Boats move faster if their button was held longer, but time spent holding the button counts against the total race time. You can only hold the button at the start of the race, and boats don't move until the button is released.\n\n> Your toy boat has a starting speed of zero millimeters per millisecond. For each whole millisecond you spend at the beginning of the race holding down the button, the boat's speed increases by one millimeter per millisecond.\n\n- This is an optimisation problem.\n- For each problem, we have several ways (amount of time we can press the button) that allow us to beat the current record holder.\n\n> To see how much margin of error you have, determine the number of ways you can beat the record in each race; in this example, if you multiply these values together, you get 288 (4 * 8 * 9).\n\n## Part 1\n\n::: {#6adcde8b .cell execution_count=1}\n``` {.python .cell-code}\nimport pandas as pd\nimport numpy as np\n```\n:::\n\n\n::: {#6dcc7f5b .cell execution_count=2}\n``` {.python .cell-code}\nf = open(\"input\", \"r\")\ninput = f.readlines()\n# input is a list\n```\n:::\n\n\nExtracting the times:\n\n::: {#1cf3e5cf .cell execution_count=3}\n``` {.python .cell-code}\nimport re\ntimes = re.findall('[0-9]+', input[0])\ntimes = list(map(int, times))\n```\n:::\n\n\nExtracting the distances:\n\n::: {#39a27472 .cell execution_count=4}\n``` {.python .cell-code}\ndistances = re.findall('[0-9]+', input[1])\ndistances = list(map(int, distances))\n```\n:::\n\n\nNext, I think I could write a function that, for any pair of times and distances, returns the count of different values of time that allow to surpass the current record.\n\n\nFirst, let's write the code of a particular case (using the example in the prompt)\n\n::: {#8a72aa03 .cell execution_count=5}\n``` {.python .cell-code}\ntime = 7\ndistance = 9\nn_possible_wins = 0\n\nfor i in range(time):\n speed = i\n available_time = time - i\n my_distance = speed*available_time\n\n if my_distance > distance:\n n_possible_wins += 1\n\nprint(n_possible_wins)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n4\n```\n:::\n:::\n\n\n::: {#7354eb2a .cell execution_count=6}\n``` {.python .cell-code}\ndef calculate_n_ways_to_win(time, distance):\n n_possible_wins = 0\n\n for i in range(time):\n speed = i\n available_time = time - i\n my_distance = speed*available_time\n\n if my_distance > distance:\n n_possible_wins += 1\n\n return(n_possible_wins)\n```\n:::\n\n\n::: {#396a3ca9 .cell execution_count=7}\n``` {.python .cell-code}\ncalculate_n_ways_to_win(7, 9)\n```\n\n::: {.cell-output .cell-output-display execution_count=7}\n```\n4\n```\n:::\n:::\n\n\nNow I need to iterate across the two lists. I would like to do that using something similar to map2, instead of a for loop\n\n::: {#d36821b5 .cell execution_count=8}\n``` {.python .cell-code}\nn_ways = list(map(calculate_n_ways_to_win, times, distances))\n```\n:::\n\n\n::: {#3b637678 .cell execution_count=9}\n``` {.python .cell-code}\nimport operator\nfrom functools import reduce\n\nreduce(operator.mul, n_ways)\n```\n\n::: {.cell-output .cell-output-display execution_count=9}\n```\n1660968\n```\n:::\n:::\n\n\n## Part 2\n\nThe input interpretation changed and all the values of time and distance now actually represent two big numbers.\n\n::: {#d002b47a .cell execution_count=10}\n``` {.python .cell-code}\ncalculate_n_ways_to_win(47986698, 400121310111540)\n```\n\n::: {.cell-output .cell-output-display execution_count=10}\n```\n26499773\n```\n:::\n:::\n\n\n",
"supporting": [
"index_files/figure-html"
],
Expand Down
6 changes: 3 additions & 3 deletions _freeze/2023/day/7/index/execute-results/html.json

Large diffs are not rendered by default.

Loading

0 comments on commit 5e2d4b3

Please sign in to comment.