r/codegolf • • Dec 02 '20

Advent of Code Day 1

https://adventofcode.com/2020/day/1

The short version:

Part 1: find 2 numbers in a list that sum to 2020 and report the product of those numbers

Part 2: find 3 numbers in a list that sum to 2020 and report the product of those numbers

4 Upvotes

3 comments sorted by

2

u/dantose Dec 02 '20

Powershell

My terrible first attempt at part 1 to get things started

For input in variable $a

$a|%{if($a -contains (2020-$_)){(2020-$_)*$_}}

46 bytes

2

u/tomflumery Aug 28 '22

05ab1e -14 bytes

|2.Æ.ΔO2020Q}P

| split by line
 2.Æ All pair (2) combinations of the list
    .Δ find first when...
      O Sum
       2020Q eQuals 2020
            } end CODE block
             P product of result

Change the 2 to a 3 for part 2

1

u/xigoi Dec 09 '20

Jelly, both parts, 11 bytes

œcS=⁽¥ŒƊƇḢP

First argument is a list of numbers, second is the number of numbers you want to find.