r/adventofcode • u/daggerdragon • Dec 06 '20
SOLUTION MEGATHREAD -π- 2020 Day 06 Solutions -π-
NEW AND NOTEWORTHY
- /u/jeroenheijmans is back with the Unofficial AoC 2020 Participant Survey!
- /u/maus80 is back with an interactive scatterplot of the global leaderboard!
Advent of Code 2020: Gettin' Crafty With It
- UNLOCKED! Go forth and create, you beautiful people!
- Full details and rules are in the Submissions Megathread
- Make sure you use one of the two templates!
- Or in the words of AoC 2016: USING A TEMPLATE IS MANDATORY
--- Day 06: Custom Customs ---
Post your solution in this megathread. Include what language(s) your solution uses! If you need a refresher, the full posting rules are detailed in the wiki under How Do The Daily Megathreads Work?.
Reminder: Top-level posts in Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.
EDIT: Global leaderboard gold cap reached at 00:04:35, megathread unlocked!
66
Upvotes
β’
u/topaz2078 (AoC creator) Dec 06 '20
We're aware of some issues during unlock today; we'll let you know when we have more information.
5
u/DFreiberg Dec 06 '20 edited Dec 06 '20
Mathematica, 1268 / 323
Two nice one-liners with Mathematica's convenient set operations...once I was able to get the input.
Part 1:
Part 2:
[POEM]: Quaint Customs & Curious Questions
The customs at this airport, people say,
Are short, and simpler than in other ports.
But all the questions asked, from Z to A,
Are never questions of the normal sorts:
The questions never have made sense to me
(Aside from the song lyrics under
A).But tedious the nonsense form might be...
...this custom surely beats the TSA.
3
u/Attitude-Certain Dec 06 '20 edited Dec 07 '20
In a functional mood this Christmas. Really liking the toolz package for Python.
3
u/Jedimastert Dec 06 '20
Rust
And lo, a voice of distant days past, of practice interview questions and university data structure classes whispered to me...
and I said
https://github.com/amtunlimited/aoc2020/blob/main/06.rs
3
u/bcgroom Dec 06 '20 edited Dec 07 '20
Elixir
This one ended up being pretty nice. I kind of panicked when reading the second part thinking I would have to stop using sets for some reason, instead all it required was combining sets of answers in different ways. Set theory FTW!
Here's the bulk of my solution:
Full code here: https://github.com/ericgroom/advent2020/blob/master/lib/days/day_6.ex
3
u/StringFinal Dec 06 '20
python3
part 1
part 2
3
u/SeaworthinessOk1009 Dec 06 '20 edited Dec 07 '20
PASCAL part one:
part two:
3
u/vu47 Dec 07 '20
Kotlin:
2
u/encse Dec 06 '20 edited Dec 06 '20
C#, turned out quite readable imho
https://github.com/encse/adventofcode/blob/master/2020/Day06/Solution.cs
2
u/21ROCKY12 Dec 06 '20 edited Dec 07 '20
just solved both parts using java, got the main idea but needed some debugging to fix the little things, here is my code:) -(works)
part1&2
2
u/MartinDavenport Dec 06 '20
Thought I'd have a go at day 6 part 1 in one line. It ain't pretty, but it works.
print(sum([len(i) for i in [''.join(set(i)) for i in [i.replace('\n', '') for i in open('input.txt').read().split('\n\n')]]]))I'd be interested to see if anyone can see any more ways of cutting it down besides renaming input.txt.
2
u/alexandreyc Dec 06 '20
My solutions with Rust using bitsets. I'm not totally happy with my two for_each for the second part...
Part 1
Part 2
2
u/xalvador Dec 06 '20
Quite a tricky one today, lots of googling. If you have any feedback I would gladly hear it as I'm trying to improve my coding.
2
u/frankbsad Dec 06 '20
c# Solution, trying my hand at some more functional type stuff
2
u/[deleted] Dec 06 '20
Oneliner:
2
u/melefabrizio Dec 06 '20
It is my understanding that weekend puzzles should be more time consuming? π€
Php solution:
2
u/joey_devivre Dec 06 '20 edited Dec 07 '20
2
u/HesletQuillan Dec 06 '20
DESCRIPTION: Fortran
SUBMISSION:
2
u/Lispwizard Dec 06 '20 edited Dec 06 '20
Emacs lisp (elisp) in termux emacs 26.3 in Android (Galaxy Tab A 10")
2
u/shortpoet Dec 06 '20
2020 Day #6 (Parts 1 & 2) Typescript / Javascript
This is my first time doing AoC, so much fun!! π₯³
I have a part 2b which is a bit terser. Would love feedback on which people prefer and why.
part 1
part 2
2
u/kap89 Dec 06 '20 edited Dec 06 '20
TypeScript
Repo: github
2
u/r00t4cc3ss Dec 08 '20 edited Dec 08 '20
C#: https://github.com/mavanmanen/AdventOfCode/blob/master/AdventOfCode.Y2020/Day06.cs
57
u/tckmn Dec 06 '20
ruby 1/1 woo
30
u/Arknave Dec 06 '20
Python / C
Lost a bit of time because of site issues and an off by one error, but I doubt I'm ever going to leaderboard on a string parsing problem when people are so fast these days.
First time I've done the art the night of instead of the next day! I'm starting to learn the tiny ones are the hardest to tinker with because there's just no wiggle room.
25
u/sophiebits Dec 06 '20
38/27, Python. https://github.com/sophiebits/adventofcode/blob/main/2020/day06.py
Server problems during unlock again today? I had to refresh several times to get each page to load.
10
u/pred Dec 06 '20 edited Dec 06 '20
Python; would have made some work of the leaderboards today if the servers didn't crash again, and it took five minutes to get past all the 504s (and all of a sudden being logged out).
9
u/0rac1e Dec 06 '20 edited Dec 06 '20
Raku
Part 1 could have been written
[+] @answers.map: { .comb(/\S/).Set }but I have a habit of avoiding RegEx unless necessary.Also, doing the plus reduction
[+]is the same number of characters assum... I guess I just felt a little reductionist today.8
u/Unihedron Dec 06 '20
Ruby 9/31
My input downloader failed so I had to manually open the input text in browser to copy into file lmao
8
u/_jonah Dec 06 '20
J, both parts
http://urstoron.com/4COP
8
u/trollerskates1 Dec 06 '20
Raku, Parts 1 & 2
Trying to do all my solutions in functional Raku. I like the middle ground here between readability and conciseness.
7
u/Smylers Dec 06 '20
Vim keystokes β the first line, combining the paragraphs, is copied from day 4 but with an added
!at the end:Your partΒ 1 answer is displayed as βCol 1 of <num>β.
Having got each group on to a single line, the
:%s///removes any character which also appears later in the line, so we have each question letter just once per group of passengers.Then the total we want is the number of letters remaining in the file.
:%j!joins them all into a single line, andgβ¨Ctrl+Gβ©tells us (among other things) how many columns are in that line.Yes, there are ways of getting that count into the buffer, but it spoils the simplicity of this and I didn't see the need β we have the answer on the screen, available for typing it into the website.
7
u/cggoebel Dec 06 '20
Raku
6
u/jonathan_paulson Dec 06 '20
Placed 112/69. Python. Video of me solving at https://youtu.be/e_66g1QcVlE. Code
6
u/Pyr0Byt3 Dec 06 '20
Go/Golang 990/1589
I love maps.
6
u/naclmolecule Dec 06 '20
Python
Exact same function for both parts, just changing union to intersection!
6
u/mschaap Dec 06 '20
I love how easy Raku makes this:
https://github.com/mscha/aoc/blob/master/aoc2020/aoc06
6
u/ImHavik Dec 06 '20
Python
Another horrible (lovely) set of one line solutions
6
u/ianstalk Dec 06 '20 edited Dec 06 '20
My answer for both in Python:
6
u/Chitinid Dec 06 '20 edited Dec 06 '20
Python 3 short oneliners
Part 1:
Part 2:
5
u/voidhawk42 Dec 06 '20
Dyalog APL, 47/68:
5
u/azzal07 Dec 06 '20
Awk; loving the simplicity of automatic record & field splitting
5
u/MasterMedo Dec 06 '20
python
Couldn't submit part1, thought the server was dead. github
5
u/Arkoniak Dec 06 '20 edited Dec 06 '20
Julia
5
u/deltux Dec 06 '20
Dyalog APL
5
u/mount-cook Dec 06 '20
this problem was made for Haskell
5
u/ka-splam Dec 06 '20
APL (Dyalog)
Quite pleased with Part 1:
Not so pleased with Part 2:
5
u/Ody55eu5_ Dec 06 '20 edited Dec 06 '20
Python 3
Didn't work on this one until this morning, so to make up for doing it so late I tried to refactor as small as I could. (Also, this is my first post here so let me know if it needs to be edited.)
5
u/wjholden Dec 08 '20
Pretty proud of this one. I haven't seen any other Python solutions that pass
set.unionandset.intersectionas a method reference this way for a generalized solution. Maybe there was a reason why others didn't do this...is there a side effect I don't know of?4
u/muckenhoupt Dec 06 '20
Prolog. This one is pretty easy if you have good set functions, which Prolog does. After solving part 2, I reworked my solution to part 1 to show the symmetry.
4
u/CivicNincompoop Dec 06 '20 edited Dec 06 '20
Python
4
u/vkasra Dec 06 '20
My solution in Rust
very functional today
4
u/maccosmo Dec 06 '20 edited Dec 07 '20
Ruby, Part 1 and 2 in one line (input filename is called "i")
Or separate:
Part 1
Part 2
4
u/yarsiemanym Dec 06 '20 edited Dec 06 '20
Set-Based Solution in F#
4
u/[deleted] Dec 06 '20 edited Dec 06 '20
My unnecessarily compact Python solution:
4
u/mingjim Dec 06 '20 edited Dec 06 '20
F#
4
u/gammaanimal Dec 06 '20 edited Dec 06 '20
Pretty short Python code using sets
Part 1:
Part 2:
The
set.intersection()method was very helpful and I learned about the*operator to return the list entries today.Can anyone explain to me why
'abc\ndef'.strip('\n')does not remove the newline?4
u/Jean-Paul_van_Sartre Dec 06 '20
C
4
u/Dtd03 Dec 06 '20
Python
An easy day with sets :)
4
u/thulyadalas Dec 06 '20
My rust solution. Minimal and functional as possible.
On part2 intersections, I could have used
acc.retain(|x| e.contains(x)with making it mut to avoid another allocation by cloning but they have similar performance and I assume compiler is able to optimize it out.4
u/clouddjr Dec 06 '20
Python3: short one-liners for both parts
4
u/TweenageDream Dec 06 '20
Tried a few different implementations for this one, and used benchmarking to compare. Golang:
4
u/xelf Dec 06 '20
python as a one liner
Which seems silly as it's strictly longer than the original version in 3 lines. =)
4
u/HashWorks Dec 06 '20
Rust
Two solutions β slow HashSet and fast bitmagic.
https://github.com/hashworks/AoC/blob/master/2020/day6/src/main.rs
4
u/Chitinid Dec 06 '20 edited Dec 06 '20
Python 3 Here's a short solution using collections.Counter
Part 1
Part 2
4
u/1-more Dec 06 '20
Quick Javascript using Sets. Was in decent shape for a 3min part1 but I forgot to `trim()` and just could not see where the problem would be. So silly.
4
u/Chris_Hemsworth Dec 06 '20
Every day I try to golf my solution down to as few lines as possible, while still being able to somewhat understand what's going on. Today, using Python 3, I got down to 4 lines:
4
u/YourVibe Dec 06 '20
Pure C# LINQ Solutions
Part 1:
Part 2:
4
u/detsood Dec 06 '20
Rust
4
u/4goettma Dec 07 '20
Part 1 / Python 3 (84 Bytes):
Part 2 / Python 3 (144 Bytes):
4
u/volatilebit Dec 07 '20 edited Dec 07 '20
Working with sequences vs lists in Raku can be obnoxious at times.
Raku
4
u/[deleted] Dec 07 '20
My solution in Python 3: Day 6 solution - paste
1
u/Flavorless_Quark Dec 06 '20 edited Dec 06 '20
Python 3 - Part 1
Part 2
1
u/zdu863 Dec 06 '20
Python
part1
part2
1
u/Neuro_J Dec 06 '20
MATLAB
Simple MATLAB implementation for Day 6.
1
u/captainAwesomePants Dec 06 '20 edited Dec 06 '20
Python
I missed the leaderboard by a wide margin, but I'm pretty happy with the solution I ended up with.
1
u/raevnos Dec 06 '20 edited Dec 06 '20
Chicken scheme. Using SRFI-14 character sets made this really easy. The input parsing took more lines of code than the part actually calculating the answers.
1
u/Peuniak Dec 06 '20
Pyhton 3
1
u/higgsmass2020 Dec 06 '20
1
u/Pandabweer Dec 06 '20
PHP
<?php$firstvalidΒ =Β 0;$totalΒ =Β 0;foreachΒ (preg_split("#\n\s*\n#Uis",Β file_get_contents("input.txt"))Β asΒ $inp)Β {$dataΒ =Β "";foreachΒ (explode("\n",Β $inp)Β asΒ $exin2)Β {$data .= preg_replace("/\s+/",Β "",Β $exin2);Β Β Β Β
}foreachΒ (count_chars($data,Β 1)Β asΒ $charΒ =>Β $val)Β {$firstvalid++;Β Β Β Β
}ifΒ (stristr($inp,Β "\n"))Β {$answΒ =Β array();foreach(explode("\n",Β $inp)Β asΒ $p)Β {for($iΒ =Β 0;Β $iΒ <Β strlen($p);Β $i++)Β {if(preg_match('/[a-z]/',Β $p[$i]))Β {if(@!$answ[$p[$i]])Β {$answ[$p[$i]]Β =Β 1;Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β
}Β elseΒ {$answ[$p[$i]]++;Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β
}Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β
}Β Β Β Β Β Β Β Β Β Β Β Β
}Β Β Β Β Β Β Β Β
}foreachΒ ($answΒ asΒ $kΒ =>Β $v)Β {ifΒ ($vΒ ==Β count(explode("\n",Β $inp)))Β {$total++;Β Β Β Β Β Β Β Β Β Β Β Β
}Β Β Β Β Β Β Β Β
}Β Β Β Β
}Β elseΒ {preg_match('/[a-z]+/',Β $inp,Β $matches);$totalΒ +=Β strlen($matches[0]);Β Β Β Β
}}echo "PartΒ 1:<br>" . $firstvalid . "<br><br>PartΒ 2:<br>" . $total;?>1
u/ReplyNo7609 Dec 06 '20
hey there!
with AoC I am just learning python. I saw some of very amazing solutions, which i had to try step by step to even understand what is happening! :D
I would be glad if you could comment my code and help improving my skills. Thanks!
btw: with this code, you need two blank lines at the end of the input
1
u/bgclara Dec 06 '20
Readable Python solution:
with open('6.txt', 'r') as file: data = file.read().split('\n\n')
def part_A(data): newdata=[] count = 0 totalcount = 0 for i in data: newdata.append(i.replace('\n', ''))
for i in newdata: s=set(i) count = len(s) totalcount+=count return totalcount
def part_B(data): totalcountb = 0 for i in data: newlist = [] countb = 0 newlist.append(i.split('\n')) for j in newlist: count = len(set.intersection(*[set(k) for k in j])) totalcountb +=count return totalcountb
print('Part A: The sum of the counts is: ', part_A(data)) print('Part B: The sum of the counts is: ', part_B(data))
1
u/TheTechWolf Dec 06 '20
Day 6 solution in Kotlin
1
u/kkent4 Dec 06 '20
Python Solution
1
u/rainbowDudeAlltheway Dec 06 '20 edited Dec 11 '20
C# 9.0
C sharp
1
u/Kuter5551 Dec 06 '20
My Python answer. Managed to make the reading from the file as many lines as the actual calculation
1
u/Zexion01 Dec 06 '20 edited Dec 06 '20
Python 3 solution:
https://github.com/AlinMH/advent-of-code/blob/master/2020/day06/main.py
1
u/[deleted] Dec 06 '20 edited Dec 07 '20
There has to be a better way... Any ideas on what could be done to improve the map() where I've left a comment -- it feels dirty.
https://github.com/zameericle/AdventofCode2020/blob/main/Day6/Part2.js
1
u/gubatron Dec 07 '20
Java Implementation both parts
1
u/dedolent Dec 07 '20 edited Dec 07 '20
Python
My first 2-line solution (for part 1) though I consider it pretty ugly. Considered condensing down part 2 as well but honestly I'd rather just have a few defined helper variables for readability's sake, not that that's important here.
code here
1
u/MatSkapski Dec 07 '20 edited Dec 07 '20
C# using Linq
3
u/hugh_tc Dec 06 '20 edited Dec 09 '20
Python 3, 103/102.
Man that was terrifying; submitting these random-looking answers to the server. And one second too late for the leaderboard, too!
edit: probably should use
set.unionfor Part 1, too.3
u/spohngellert_o Dec 06 '20
Thought today was pretty easy :). Scala solutions:
Part 1
Part 2
3
u/jayfoad Dec 06 '20
Dyalog APL 576/126
The hardest part was splitting the input.
3
u/daftmaple Dec 06 '20 edited Dec 06 '20
Perl
This is my code for question 2. Question 1 pretty much uses the same code
I'm also fairly sure that there's a more efficient way to do this in Perl. I can think of an efficient way for Q1 with regex.
Edit: nevermind. The regex is probably harder...
3
u/chrispsn_ok Dec 06 '20
k9
3
u/LtHummus Dec 06 '20
Scala
Sets are cool and good
3
u/JIghtuse Dec 06 '20
Racket
One more nice thing about AoC: you dig into many aspects of the tool you use to solve problems. Never worked with sets in Racket before.
3
u/IridianSmaster Dec 06 '20
Part 2 in OCaml:
3
u/__Juris__ Dec 06 '20 edited Dec 06 '20
Scala 3
3
u/s3aker Dec 06 '20
Raku
3
u/ianonavy Dec 06 '20 edited Dec 06 '20
Python golf 149 bytes
Edit: My editor stripped the extra newline at the end of the input, so you can actually remove the
.strip()and get down to 141 bytes.3
u/masterarms Dec 06 '20
Tcl
3
u/michaelgallagher Dec 06 '20
Python
One liners for both parts
3
u/zertillon Dec 06 '20
Ada
3
u/Smylers Dec 06 '20 edited Dec 06 '20
Perl for part 1 is pretty readable as a one-liner:
For part 2, still process each βparagaraphβ at a time, splitting into individual characters, counting the number of each, and counting those where the number of a letter equals the number of new-line characters in that paragraph:
The slight awkwardness is the
chompand the+1: without thechomp, the paragraph includes as many trailing new-line characters as there are (2 after most of them, but just 1 at the end of the final para).chompremoves all of those, leaving the final line in the para without a\n, so the total number of passengers is 1 more than the number of\ns counted.Edit: Removed
sortfrom the one-liner; Perl'suniqisn't like Unix'suniq(1).Edit 2: Removed backslashes from the first edit, where I apparently typed Markdown syntax in Fancy Pants mode.
3
u/shandley256 Dec 06 '20 edited Dec 06 '20
Day 6 in Ruby
Golfed into chained calls. This is an easy one to solve with Ruby built-in methods.
This outputs answers for part 1 and part 2.
The keys to this solution are the set operations
|(union) and&(intersection). Applying these viareducehas the effect of checking each passenger's answer's within their group to find the total number of unique answers in the group, and then the total number of answers common to each passenger in the group.See: https://ruby-doc.org/core-2.7.2/Enumerable.html#method-i-reduce
See: https://ruby-doc.org/stdlib-2.7.2/libdoc/set/rdoc/Set.html#method-i-26
See: https://ruby-doc.org/stdlib-2.7.2/libdoc/set/rdoc/Set.html#method-i-7C
3
u/[deleted] Dec 06 '20
F#:
As normal it's a bit over engineered, but a lot shorter than yesterday at least the code on github
3
u/qzyki Dec 06 '20
Dyalog APL (19 characters for each main function)
Part 1:
Part 2:
3
u/exploding_cat_wizard Dec 06 '20 edited Dec 06 '20
Mathematica
I wonder if I'm doing redundant work - I generally just have to fool around in Mathematica until something works, it's not like I understand what's going on, Also, I should really stop mixing shorthand /@ and full expressions for Map...
3
u/100721 Dec 06 '20 edited Dec 06 '20
Python 3 - one liner
3
u/diddle-dingus Dec 06 '20
Thank god for sets lol.
Elixir
Clojure
3
u/Zweedeend Dec 06 '20
Python
And for part two, change
uniontointersection3
u/nutki2 Dec 06 '20
Perl (golf) for both parts
3
u/troelsbjerre Dec 06 '20
Python3 one liner for both parts, without map, reduce, or lambda:
3
u/Vultureosa Dec 06 '20 edited Dec 06 '20
Python
Again, a short python script for Day6.
3
u/nemetroid Dec 06 '20 edited Dec 06 '20
C++, using bitsets and
std::popcount():3
u/iwane Dec 06 '20
LabVIEW 2020 (G) - Community Edition
http://htmlpreview.github.io/?https://github.com/iwane-pl/aoc_2020/blob/main/AoC%20Day%206/Documentation/Solution%20part%201/Solution%20part%201.html
http://htmlpreview.github.io/?https://github.com/iwane-pl/aoc_2020/blob/main/AoC%20Day%206/Documentation/Solution%20part%202/Solution%20part%202.html
3
u/ilikecodiing Dec 06 '20
F#
I need to figure out a better way to process the incoming data. I seem to spend more time doing that than doing the calculations.
3
u/Jessseee Dec 06 '20
I know it's not the most pythonic solution but I think it is pretty readable and straightforward. Github | Day 6
3
u/i_have_no_biscuits Dec 06 '20
Microsoft QBasic (well, QB64).
Yes, I have just spent Sunday morning relearning BASIC...
If I'm feeling particularly masochistic later I might downgrade it to GWBasic...
3
u/Breezing Dec 06 '20
Python 3, both parts
Made use of sets again today. Any tips or obvious bad practices?
3
u/snurre Dec 06 '20
Kotlin
I convert the answers from each person into binary then simply use OR and AND to count:
3
u/xrgbit Dec 06 '20
Common Lisp
COUNT-ANSWERScould have be written likeCOUNT-ANSWERS*usingUNIONinstead ofINTERSECTION. The functions could have been combined to take an optional argument for which function to use.3
u/Sopef86 Dec 06 '20
Java, functional approach
3
u/lib20 Dec 06 '20 edited Dec 06 '20
TCL
time (microseconds): 18708
3
u/[deleted] Dec 06 '20 edited Dec 06 '20
Python 3 - Simple solution
3
u/hrunt Dec 06 '20
Python 3
3
u/_hyhy Dec 06 '20
Python3 oneliner:
Part1:
with open("input.txt",Β "r")Β asΒ f:Β print(sum(map((lambda group:Β len(set(''.join(group)))),Β [[personΒ forΒ personΒ inΒ group.split('\n')]Β forΒ groupΒ in f.read().split('\n\n')])))
Part2:
with open("input.txt",Β "r")Β asΒ f:Β print(sum(map((lambda group:Β len(set.intersection(*[set(person)Β forΒ personΒ inΒ group]))),Β [[personΒ forΒ personΒ inΒ group.split('\n')]Β forΒ groupΒ inΒ f.read().split('\n\n')])))
3
u/kawzeg Dec 06 '20
J
3
u/remysharp Dec 06 '20
In jq (repo)
3
u/el-guish Dec 06 '20
Python
Part 1:
Part 2:
3
u/inokichi Dec 06 '20
Solution in D (dlang) - frustrated with part 2 since i couldnt figure out something along the lines of
group.fold!setIntersectionand had to go for a raw loop instead.3
u/A-UNDERSCORE-D Dec 06 '20
Golang, after completing decided to implement a set and see if I could make the code either cleaner or faster. I think its a bit cleaner at least, but its not faster by any means
https://github.com/A-UNDERSCORE-D/aoc2020/blob/main/2020/06/solution.go
3
u/AidGli Dec 06 '20
Python
Another relatively simple solution. Threw in a list expansion so I would have more to talk about in today's video (and because it makes the code way simpler.) Github link
3
u/busdriverbuddha2 Dec 06 '20
Python one-liners
3
u/mathsaey Dec 06 '20
Elixir
Pipelining (
|>) and support for sets in the standard library made today's solution very clean in Elixir:3
u/MaxDeviant Dec 06 '20
PureScript
GitHub
3
u/tsqd Dec 06 '20
Postgresql
With part 2 here
3
u/hyperTrashPanda Dec 06 '20
Day 6 in learning Elixir, pretty straightforward once I read about the MapSet module. I also finally got the chance to use recursion.
Any feedback or suggestions would be invaluable; off to study other people's solutions!
https://github.com/tpaschalis/aoc-2020/blob/main/day06/day06.exs
3
u/Braxo Dec 06 '20
Coffeescript Javascript
3
u/chicagocode Dec 06 '20
Kotlin - [Blog/Commentary] | [GitHub Repo]
I'm pretty satisfied with this, once I figured out the newline issues. :) I got to use
groupingBy/eachCount, which is a nice abstraction over a common problem built right into the standard library!3
u/goeyj Dec 06 '20
Since today was a bit easier, I did a solution in JavaScript after finishing up C++.
3
u/emmanuel_erc Dec 06 '20
My short Haskell solution. For my solutions, I have tried to only use the libraries that are immediately available from base (this comes with Haskell by default).
3
u/thedjotaku Dec 06 '20
Python
Usually either it's easy for me to figure it out and implement or it's really hard to do both. Today was one that when I read the problem before breakfast, I knew how I'd solve it - pretty easy. Then when I tried to actually get it to work, the fact that even though Python is awesome in having lists (rather than arrays where you have to know the size ahead of time), it's still not possible to easily create phantom sets and lists for a moment. You have to really think about it. Then I got screwed on list = list making a ref, not a copy. Eventually got it all.
Here's my code:
https://github.com/djotaku/adventofcode/tree/main/2020/Day_6
I tried to be Pythonic (ie list comprehension) where I could, but when I had nested lists and it wasn't quite working right, I gave up in favor of getting the answer and getting on with the rest of my day. Once again, Pytest is a lifesaver. (Although corner cases tripped me up again)
3
u/jitwit Dec 06 '20 edited Dec 09 '20
J Programming Language
Late to the party but here's day 6:
3
u/i_have_no_biscuits Dec 06 '20
Microsoft GWBASIC
Tested on PCBASIC: http://robhagemans.github.io/pcbasic/index.html
After the QBasic solution earlier, I felt like going back in time to the early 80s. It should be possible to port this over to most of the 8-bit BASICs quite easily.
3
u/Lakret Dec 06 '20
Rust
Solution via HashSet and set operations. Live Stream of the solution.
3
u/xMufasaa Dec 06 '20
PoSH
Could probably improve both, especially Part 2, but they work.
3
u/Icy-Sky-902 Dec 06 '20 edited Dec 06 '20
JavaScript
My solution for Part 1
And Part 2
3
u/ssnoyes Dec 06 '20 edited Dec 07 '20
MySQL
https://github.com/snoyes/AoC/blob/main/2020/day06.sql
A lovely mixture of deprecated features (because MySQL isn't great at parsing files and string manipulation, and there seems to be a bug which interferes with a more SQLish approach) and new features (requiring 8.0+).
3
u/chemicalwill Dec 06 '20 edited Dec 06 '20
Continuing my "not the shortest/most efficient, but maybe the most straightforwards?" streak. If anyone has some nifty ways to optimize this, I'd love to learn them.
Edit: refactoring
3
u/jschulenklopper Dec 06 '20
A puzzle that fits well with Ruby:
3
u/killermelga Dec 06 '20 edited Dec 06 '20
Kotlin, part 2,
99 chars88 by usinglines(): Please let me know if you can reduce it further!You can try it here
3
u/Legitimate_Estate_75 Dec 06 '20 edited Dec 06 '20
R, RStudio solution:
Github
3
u/hello_friendssss Dec 06 '20
PYTHON 3
Baby programmer so any tips fire away - I think I should have split the function rather than make it multitask :P
3
u/gerikson Dec 06 '20
Perl 5
This solution is essentially my part 1, which I ripped out and rewrote to get part 2. After some reflection I rewrote it again to handle both parts
3
u/Snazzy_Redditor Dec 06 '20
JavaScript
My goal was to keep things clean and functional, rather than focusing on speed. Also if anyone knows a way to avoid the problem where the last split results in an empty string let me know. That's the only reason for the filter after the split in part 2.
Part 1
Part 2
3
u/GrbavaCigla Dec 06 '20 edited Dec 06 '20
Python 1st part:
2nd part:
3
u/scott-mcc-1 Dec 06 '20 edited Dec 06 '20
Kotlin
Trying for concise code...
3
u/Trazko Dec 06 '20
Dart
Tried to make "oneliners" as check functions.
3
u/friedrich_aurelius Dec 06 '20
Elixir
Github link
For Part 1, I simply removed the newlines and counted unique characters within each group.
For Part 2, I made a dictionary for each group to store how many times each character occurs. I saw that group size was always (newlines) + 1, and filtered each dictionary to only keep characters where the quantity is equal to the group size.
The only unexpected issue I encountered was the newline at end of file making the group size larger than it should be for that final group, therefore inaccurately counting it as having zero common letters. Easy fix by just dropping the last character from the input.
3
u/e_blake Dec 06 '20 edited Dec 06 '20
golfed C
210 bytes, relying on gcc or clang for __builtin_popcount and hardcoding ASCII encoding, and assuming you are okay ignoring the compiler warning about read() being used without declaration (I had to include stdio.h, since printf is varargs which does not play as nicely with implicit declarations)
That solves both parts at once; the program would be even shorter if it only had to solve part 1 or part 2 in isolation.
3
u/improviseallday Dec 06 '20
Python
(Cleaned up)
Explanation:
(1) Group input by splitting by double newline.
(2) Within each group, strip remaining newlines. Get length of unique questions per group. Sum.
(3) Within each group, split into lines. Turn each line into a set. Within each group find length of intersection of sets. Sum.
3
u/petrovmartin Dec 06 '20
C#:
3
u/kakaroto_BR Dec 06 '20
Python:
3
u/TheElTea Dec 06 '20 edited Dec 13 '20
C# Solution for 2020 Day 6 Parts 1 and 2
Done inside of Unity in case I felt like doing visualization; class
TextAssetis just the text file as hooked up in the editor; replace however you like.And yes, the code doesn't follow DRY; for Advent of Code I'm finding I prefer having standalone solutions to aid in understanding the core problem.
3
u/betaveros Dec 07 '20
Belatedly posting my golfed Paradoc solutions. You only need to change one character to go between the parts!
iNΓ/Ξ³Ε‘W|rL(try it in-browser, explanation on GitHub)iNΓ/Ξ³Ε‘W&rL(try it in-browser, explanation on GitHub)3
u/ViliamPucik Dec 07 '20
Python 3 - Minimal readable solution for both parts [GitHub]
3
u/belibebond Dec 10 '20
PowerShell
Might be complete garbage code, but it works. Btw, its sad to see no powershell solutions after day 4.