boB Rudis
3 years ago
5 changed files with 20 additions and 87 deletions
@ -0,0 +1,4 @@ |
|||
.Rproj.user |
|||
.Rhistory |
|||
.RData |
|||
.Ruserdata |
@ -1,27 +0,0 @@ |
|||
{ |
|||
"id": "91603C46", |
|||
"path": "~/Development/2020-code-advent/R/01.R", |
|||
"project_path": "01.R", |
|||
"type": "r_source", |
|||
"hash": "565949706", |
|||
"contents": "", |
|||
"dirty": false, |
|||
"created": 1606834493630.0, |
|||
"source_on_save": false, |
|||
"relative_order": 1, |
|||
"properties": { |
|||
"tempName": "Untitled1", |
|||
"source_window_id": "", |
|||
"Source": "Source", |
|||
"cursorPosition": "3,0", |
|||
"scrollLine": "1" |
|||
}, |
|||
"folds": "", |
|||
"lastKnownWriteTime": 1606835285, |
|||
"encoding": "UTF-8", |
|||
"collab_server": "", |
|||
"source_window": "", |
|||
"last_content_update": 1606835285557, |
|||
"read_only": false, |
|||
"read_only_alternatives": [] |
|||
} |
@ -1,59 +0,0 @@ |
|||
# https://adventofcode.com/2020 |
|||
|
|||
# Day 01 - 01 ------------------------------------------------------------- |
|||
|
|||
# Before you leave, the Elves in accounting just need you to fix your expense report (your puzzle input); apparently, something isn't quite adding up. |
|||
# |
|||
# Specifically, they need you to find the two entries that sum to 2020 and then multiply those two numbers together. |
|||
# |
|||
# For example, suppose your expense report contained the following: |
|||
# |
|||
# 1721 |
|||
# 979 |
|||
# 366 |
|||
# 299 |
|||
# 675 |
|||
# 1456 |
|||
# In this list, the two entries that sum to 2020 are 1721 and 299. Multiplying them together produces 1721 * 299 = 514579, so the correct answer is 514579. |
|||
# |
|||
# Of course, your expense report is much larger. Find the two entries that sum to 2020; what do you get if you multiply them together? |
|||
|
|||
scan( |
|||
file = here::here("../input/01-01.txt"), |
|||
what = integer() |
|||
) -> input |
|||
|
|||
pairs <- combn(input, 2) |
|||
|
|||
sums <- combn(input, 2, sum) |
|||
|
|||
Reduce(`*`, pairs[,which(sums == 2020)]) |
|||
|
|||
# Day 01 - 02 ------------------------------------------------------------- |
|||
|
|||
# Before you leave, the Elves in accounting just need you to fix your expense report (your puzzle input); apparently, something isn't quite adding up. |
|||
# |
|||
# Specifically, they need you to find the two entries that sum to 2020 and then multiply those two numbers together. |
|||
# |
|||
# For example, suppose your expense report contained the following: |
|||
# |
|||
# 1721 |
|||
# 979 |
|||
# 366 |
|||
# 299 |
|||
# 675 |
|||
# 1456 |
|||
# In this list, the two entries that sum to 2020 are 1721 and 299. Multiplying them together produces 1721 * 299 = 514579, so the correct answer is 514579. |
|||
# |
|||
# Of course, your expense report is much larger. Find the two entries that sum to 2020; what do you get if you multiply them together? |
|||
|
|||
scan( |
|||
file = here::here("../input/01-01.txt"), |
|||
what = integer() |
|||
) -> input |
|||
|
|||
tri <- combn(input, 3) |
|||
|
|||
sums <- combn(input, 3, sum) |
|||
|
|||
Reduce(`*`, tri[,which(sums == 2020)]) |
Loading…
Reference in new issue