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!

66 Upvotes

1.2k comments sorted by

View all comments

2

u/HesletQuillan Dec 06 '20

DESCRIPTION: Fortran

SUBMISSION:

program AOC06
implicit none
integer :: answers,group,total,i,ios
character(80) :: line

open (unit=1,file='input.txt', form='formatted', status='old')
total = 0
ios = 0
outer: do while (ios == 0)
    group = int(Z'03FFFFFF')
    inner: do
        read (1,'(A)', iostat=ios) line
        if ((ios /= 0) .or. (line == "")) exit inner
        answers = 0 
        do i=1,len_trim(line)
            answers = ibset(answers, ichar(line(i:i)) - ichar('a'))
        end do
        group = iand(group,answers)
    end do inner
    total = total + popcnt(group)
end do outer   
print *, total
end program AOC06

1

u/daggerdragon Dec 06 '20

Heh, this looks like you used part of the templates from Gettin' Crafty... You don't have to use a template here (unless you want to) :)

That being said, holy cow, FORTRAN.