boB Rudis
3 years ago
9 changed files with 2448 additions and 123 deletions
@ -1,3 +1,3 @@ |
|||
{ |
|||
"activeTab": 3 |
|||
"activeTab": 1 |
|||
} |
@ -1,7 +1,16 @@ |
|||
~%2FDevelopment%2F2020-code-advent%2FR%2F01.R="6CE8BD46" |
|||
~%2FDevelopment%2F2020-code-advent%2FR%2F01.py="E3582989" |
|||
~%2FDevelopment%2F2020-code-advent%2FR%2F02.R="5E60AF29" |
|||
~%2FDevelopment%2F2020-code-advent%2FR%2F04.R="17C8E91A" |
|||
~%2FDevelopment%2F2020-code-advent%2FR%2F04.py="374D3B07" |
|||
~%2FDevelopment%2F2020-code-advent%2FR%2F05.R="3147CB9C" |
|||
~%2FDevelopment%2F2020-code-advent%2FR%2F05.py="C22F3766" |
|||
~%2FDevelopment%2F2020-code-advent%2FR%2F06.R="2E0DCDD0" |
|||
~%2FDevelopment%2F2020-code-advent%2FR%2F06.py="A53BEE38" |
|||
~%2FDevelopment%2F2020-code-advent%2FREADME.md="87542FC2" |
|||
~%2FDevelopment%2F2020-code-advent%2FSwift%2F2020-code-advent.playground%2FSources%2F05-01.swift="A5C6F3F2" |
|||
~%2FDevelopment%2F2020-code-advent%2Finput%2F01-01.txt="22EEE1B0" |
|||
~%2FDevelopment%2F2020-code-advent%2Finput%2F06-01.txt="488B7FA9" |
|||
~%2FDevelopment%2F2020-code-advent%2Fjs%2F01.js="BCBA9F87" |
|||
~%2FDevelopment%2F2020-code-advent%2Fjs%2F02.js="823FD9BF" |
|||
~%2FDevelopment%2F2020-code-advent%2Fjs%2F05.js="28BC66DE" |
|||
|
@ -0,0 +1,116 @@ |
|||
# --- Day 6: Custom Customs --- |
|||
# |
|||
# As your flight approaches the regional airport where you'll switch to a much |
|||
# larger plane, customs declaration forms are distributed to the passengers. |
|||
# |
|||
# The form asks a series of 26 yes-or-no questions marked a through z. All you |
|||
# need to do is identify the questions for which anyone in your group answers |
|||
# "yes". Since your group is just you, this doesn't take very long. |
|||
# |
|||
# However, the person sitting next to you seems to be experiencing a language |
|||
# barrier and asks if you can help. For each of the people in their group, you |
|||
# write down the questions for which they answer "yes", one per line. For example: |
|||
# |
|||
# abcx |
|||
# abcy |
|||
# abcz |
|||
# |
|||
# In this group, there are 6 questions to which anyone answered |
|||
# "yes": a, b, c, x, y, and z. (Duplicate answers to the same question don't |
|||
# count extra; each question counts at most once.) |
|||
# |
|||
# Another group asks for your help, then another, and eventually you've collected |
|||
# answers from every group on the plane (your puzzle input). Each group's answers |
|||
# are separated by a blank line, and within each group, each person's answers are |
|||
# on a single line. For example: |
|||
# |
|||
# abc |
|||
# |
|||
# a |
|||
# b |
|||
# c |
|||
# |
|||
# ab |
|||
# ac |
|||
# |
|||
# a |
|||
# a |
|||
# a |
|||
# a |
|||
# |
|||
# b |
|||
# |
|||
# This list represents answers from five groups: |
|||
# |
|||
# The first group contains one person who answered "yes" to 3 questions: a, b, and c. |
|||
# The second group contains three people; combined, they answered "yes" to 3 questions: a, b, and c. |
|||
# The third group contains two people; combined, they answered "yes" to 3 questions: a, b, and c. |
|||
# The fourth group contains four people; combined, they answered "yes" to only 1 question, a. |
|||
# The last group contains one person who answered "yes" to only 1 question, b. |
|||
# |
|||
# In this example, the sum of these counts is 3 + 3 + 3 + 1 + 1 = 11. |
|||
# |
|||
# For each group, count the number of questions to which anyone answered "yes". |
|||
# What is the sum of those counts? |
|||
|
|||
library(stringi) |
|||
library(magrittr) |
|||
library(tidyverse) |
|||
|
|||
# input <- readLines("/tmp/test.txt") |
|||
input <- readLines("../input/06-01.txt", warn = FALSE) |
|||
|
|||
# 04-01 ------------------------------------------------------------------- |
|||
|
|||
split(input, findInterval(1:length(input), which(input == ""))) %>% |
|||
map_int(~length(unique(unlist(strsplit(.x, ""))))) %>% |
|||
sum() |
|||
|
|||
# --- Part Two --- |
|||
# |
|||
# As you finish the last group's customs declaration, you notice that you misread |
|||
# one word in the instructions: |
|||
# |
|||
# You don't need to identify the questions to which anyone answered "yes"; you |
|||
# need to identify the questions to which everyone answered "yes"! |
|||
# |
|||
# Using the same example as above: |
|||
# |
|||
# abc |
|||
# |
|||
# a |
|||
# b |
|||
# c |
|||
# |
|||
# ab |
|||
# ac |
|||
# |
|||
# a |
|||
# a |
|||
# a |
|||
# a |
|||
# |
|||
# b |
|||
# This list represents answers from five groups: |
|||
# |
|||
# In the first group, everyone (all 1 person) answered "yes" to 3 questions: a, b, and c. |
|||
# In the second group, there is no question to which everyone answered "yes". |
|||
# In the third group, everyone answered yes to only 1 question, a. Since some |
|||
# people did not answer "yes" to b or c, they don't count. |
|||
# In the fourth group, everyone answered yes to only 1 question, a. |
|||
# In the fifth group, everyone (all 1 person) answered "yes" to 1 question, b. |
|||
# |
|||
# In this example, the sum of these counts is 3 + 0 + 1 + 1 + 1 = 6. |
|||
# |
|||
# For each group, count the number of questions to which everyone answered "yes". |
|||
# What is the sum of those counts? |
|||
# |
|||
|
|||
# 04-02 |
|||
|
|||
split(input, findInterval(1:length(input), which(input == ""))) %>% |
|||
map(discard, equals, "") %>% |
|||
map_int(~{ |
|||
sum(table(unlist(strsplit(.x, ""))) == length(.x)) |
|||
}) %>% |
|||
sum() |
@ -0,0 +1,20 @@ |
|||
from itertools import groupby |
|||
from collections import Counter |
|||
|
|||
with open("../input/06-01.txt") as f: |
|||
input = f.read().splitlines() |
|||
|
|||
flatten = lambda x: [item for sublist in x for item in sublist] |
|||
|
|||
count01 = lambda x: len(set([chr for chr in x])) |
|||
|
|||
# 06-01 |
|||
|
|||
sum([ count01(flatten(list(grp))) for key, grp in groupby(input, lambda str: str != "") if key ]) |
|||
|
|||
# 06-02 |
|||
|
|||
count02 = lambda x: len([ val for val in Counter(flatten(x)).values() if val == len(x)]) |
|||
|
|||
sum([ count02(list(grp)) for key, grp in groupby(input, lambda str: str != "") if key ]) |
|||
|
File diff suppressed because it is too large
Loading…
Reference in new issue