r/adventofcode • • Dec 06 '20

SOLUTION MEGATHREAD -🎄- 2020 Day 06 Solutions -🎄-

NEW AND NOTEWORTHY


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!

64 Upvotes

1.2k comments sorted by

View all comments

2

u/melefabrizio Dec 06 '20

It is my understanding that weekend puzzles should be more time consuming? 🤔

Php solution:

<?php
$file = file_get_contents('day6.txt');
$groups = explode("\n\n", $file);
//Part 1
$count = 0;
foreach ($groups as $group) {
 
 $group = array_unique(str_split(str_replace("\n", '', $group))); //doppie quote per forza per rilevare il \n
 $count += count($group);
 
}
echo "Part 1: $count\n";
//Part 2
$count = 0;
foreach ($groups as $group) {
 
 $group = array_map('str_split', explode("\n", $group));
 
 if(count($group)<2){
  $count += count($group[0]);
  continue;
 }
 
 $int = call_user_func_array('array_intersect', $group);  
 $count += count($int)."\n";
 
}
echo "Part 2: $count\n";
?>

1

u/daggerdragon Dec 06 '20

It is my understanding that weekend puzzles should be more time consuming? 🤔

Not necessarily. /u/topaz2078 does try to aim the more complex puzzles at the weekends but everyone will have varying amounts of "time-consuming" depending on their skill level, familiarity with their language, etc.

Besides, it's only Day 06. Wait for it.

1

u/backtickbot Dec 06 '20

Hello, melefabrizio: code blocks using backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead. It's a bit annoying, but then your code blocks are properly formatted for everyone.

An easy way to do this is to use the code-block button in the editor. If it's not working, try switching to the fancy-pants editor and back again.

Comment with formatting fixed for old.reddit.com users

FAQ

You can opt out by replying with backtickopt6 to this comment.

1

u/Iain_M_Norman Dec 06 '20

It's only the first weekend I guess, I was also hoping for something to get stuck into :)
Or something that runs for 3 hours before you've worked out to optimise it. Those are fun.

I've spent 5 years looking forward to something with a large search space but measurable result that I can use a genetic alg on ;-)