11 votes

Day 1: Dusty Shed

Today's problem description: https://adventofcode.com/2026/day/1

Please post your solutions in your own top-level comment. Here's a template you can copy-paste into your comment to format it nicely, with the code collapsed by default inside an expandable section with syntax highlighting (you can replace python with any of the "short names" listed in this page of supported languages):

<details>
<summary>Part 1</summary>

```python
Your code here.
```

</details>

10 comments

  1. fidwell
    Link
    Sorry for hijacking, but no one has started this year's AoC threads yet. Hopefully that doesn't mean everyone else has lost interest!

    Sorry for hijacking, but no one has started this year's AoC threads yet. Hopefully that doesn't mean everyone else has lost interest!

    5 votes
  2. Banazir
    Link
    I'm using Lua as usual, partially because I never get past the first day or two and I'm a very basic scripter. Both parts local function sortcountsdesc(a, b) return a > b end local infile =...

    I'm using Lua as usual, partially because I never get past the first day or two and I'm a very basic scripter.

    Both parts
    local function sortcountsdesc(a, b)
    	return a > b
    end
    
    local infile = io.open("input")
    local counts = {}
    local t = {}
    for line in infile:lines() do
    	if counts[line] ~= nil then
    		counts[line] = counts[line] + 1
    	else
    		counts[line] = 1
    		table.insert(t, line)
    	end
    end
    infile:close()
    
    table.sort(t, function(a,b) return sortcountsdesc(counts[a], counts[b]) end)
    
    --[[ Output to file to check sorting
    local outfile = io.open("output.txt", "w+")
    for _,v in pairs(t) do
    	outfile:write(string.format("%s, %d\n", v, counts[v]))
    end
    outfile:close()
    ]]--
    
    print(tonumber(t[1]) * tonumber(t[2]) * tonumber(t[3])) --part 1 solution
    print(tonumber(t[#t]) * tonumber(t[#t - 1]) * tonumber(t[#t - 2])) --part 2 solution
    
    3 votes
  3. tomf
    Link
    I could do this shorter but it'd be uglier. Google Sheets: Part 1 and 2 =LET( u,UNIQUE(A:A), MAP( {0;1}, LAMBDA( s, PRODUCT( ARRAY_CONSTRAIN( SORT( u, COUNTIF(A:A,u),s), 3,1)))))

    I could do this shorter but it'd be uglier.

    Google Sheets: Part 1 and 2
    =LET(
      u,UNIQUE(A:A),
      MAP(
       {0;1},
       LAMBDA(
        s,
        PRODUCT(
         ARRAY_CONSTRAIN(
          SORT(
           u,
           COUNTIF(A:A,u),s),
          3,1)))))
    
    3 votes
  4. fidwell
    Link
    Welcome to 2026! A pretty simple puzzle for day 1, as usual, and thankfully part 2 is likely trivial if you get part 1. Both solutions Pretty straightforward in C#; just chaining together a lot of...

    Welcome to 2026! A pretty simple puzzle for day 1, as usual, and thankfully part 2 is likely trivial if you get part 1.

    Both solutions Pretty straightforward in C#; just chaining together a lot of standard library functions. Theoretically, you could maybe make some optimizations by _not_ sorting the entire list, and manually calculating the top or bottom three only. But sorting a list of this size is already so fast that it's not really worth it.
        public override object SolvePartOne(string input) =>
            input.SplitByNewline() // custom library method I use for almost every puzzle
                .GroupBy(id => id)
                .OrderByDescending(g => g.Count()) // part 2: OrderBy
                .Take(3)
                .Select(g => int.Parse(g.Key))
                .Aggregate(1, (a, b) => a * b)
                .ToString();
    
    2 votes
  5. Kremor
    Link
    I'm using Guile to solve the problems. My solutions may not be as elegant because I'm using this as an opportunity to learn the language. And for what I've seen, there's a lot of wheel reinventing...

    I'm using Guile to solve the problems.

    My solutions may not be as elegant because I'm using this as an opportunity to learn the language. And for what I've seen, there's a lot of wheel reinventing in Scheme.

    Day 1: Dusty Shed
    (use-modules (ice-9 rdelim)
                 (srfi srfi-1)
                 (srfi srfi-13))
    
    ;;; Read input
    
    (define (parse-num line)
      (let ((trimmed (string-trim-both line)))
        (if (string-null? trimmed)
            #f
            (let ((num (string->number trimmed)))
              (and num (integer? num) num)))))
    
    (define (read-file path)
      (call-with-input-file path
        (lambda (port)
          (let loop ((line (read-line port))
                     (numbers '()))
            (if (eof-object? line)
                numbers
                (let ((num (parse-num line)))
                  (if num
                      (loop (read-line port) (cons num numbers))
                      (loop (read-line port) numbers))))))))
    
    ;;; Solution
    
    (define (group-by-count lst)
      (let ((counts (make-hash-table)))
        (let loop ((items lst))
          (unless (null? items)
            (let ((n (car items)))
              (hashv-set! counts n (1+ (hashv-ref counts n 0))))
            (loop (cdr items))))
        (let ((pairs (hash-fold (lambda (k v acc)
                                  (cons (cons k v) acc))
                                '()
                                counts)))
          (sort pairs (lambda (a b) (> (cdr a) (cdr b)))))))
    
    (define (get-product lst n)
      (let loop ((items lst) (i 0) (product 1))
        (if (or (null? items) (>= i n))
            product
            (let ((num (car (car items))))
              (loop (cdr items)
                    (1+ i)
                    (* product num))))))
    
    (define arr (group-by-count (read-file "input.txt")))
    
    (format #t "Top 3:  ~a~%" (get-product arr 3))
    (format #t "Last 3: ~a~%" (get-product (reverse arr) 3))
    
    2 votes
  6. lily
    (edited )
    Link
    I was originally planning on learning a new language for AoC this year, but I don't have as much time as I'd hoped, so since I've continued to work with it for personal projects I'm doing it in...

    I was originally planning on learning a new language for AoC this year, but I don't have as much time as I'd hoped, so since I've continued to work with it for personal projects I'm doing it in Lily again. There have been some significant additions and changes to the language since last December, though none of them matter for such a simple puzzle.

    Solution (Lily)
    #[
        Advent of Code 2026
        Day 01: Dusty Shed
    ]#
    
    var counts: Hash[Integer, Integer] = []
    
    for line in File.read_to_string("inputs/day_01.txt").split("\n"): {
        if line == "": {
            break
        }
    
        var id = line.parse_i().unwrap()
    
        if counts.has_key(id): {
            counts[id] += 1
        else:
            counts[id] = 1
        }
    }
    
    var sorted = counts.keys().sort(|a, b| counts[a] - counts[b])
    
    print("Part 1: {}\nPart 2: {}".format(
        sorted[-1] * sorted[-2] * sorted[-3], sorted[0] * sorted[1] * sorted[2]
    ))
    
    2 votes
  7. [2]
    balooga
    Link
    Forgot all about it this year! Thanks for posting it. I’m relieved to see it’s still happening even as AI is actively flipping the table. Normally I share my code here, fresh from the TypeScript...

    Forgot all about it this year! Thanks for posting it. I’m relieved to see it’s still happening even as AI is actively flipping the table.

    Normally I share my code here, fresh from the TypeScript harness I use to build and run AoC solutions. Today was more ad hoc, I just whipped up a few lines of vanilla JS in Notepad and ran it directly. Very simple today.

    2 votes
    1. fidwell
      Link Parent
      I'm extra excited for it this year since I have been barely writing any code at work (very sad tbh), so I'm itching to actually solve some puzzles by hand. I miss doing this kind of pure programming!

      I'm extra excited for it this year since I have been barely writing any code at work (very sad tbh), so I'm itching to actually solve some puzzles by hand. I miss doing this kind of pure programming!

      2 votes
  8. vsczpv
    (edited )
    Link
    Obligatory Rust version. I tried making it all functional-ly looking but the fors just look better: Both Parts (Rust) pub fn main(part: Part) -> Result<(), Box<dyn Error>> { let file =...

    Obligatory Rust version. I tried making it all functional-ly looking but the fors just look better:

    Both Parts (Rust)
    pub fn main(part: Part) -> Result<(), Box<dyn Error>> {
        let file = std::fs::read_to_string(PATH).expect(format!("Error: {} missing!", PATH).as_str());
    
        let mut map = HashMap::new();
    
        for l in file.lines().map(|l| l.parse::<i32>()) {
            map.entry(l?).and_modify(|e| *e = *e + 1).or_insert(1);
        }
    
        let mut sorted = BTreeMap::new();
    
        for (key, val) in map.iter() {
            sorted
                .entry(*val)
                .and_modify(|e: &mut Vec<_>| e.push(*key))
                .or_insert(vec![*key]);
        }
    
        let mut temp_iter1;
        let mut temp_iter2;
    
        let iter: &mut dyn Iterator<Item = _> = match part {
            Part::One => {
                temp_iter1 = sorted.values_mut().rev();
                &mut temp_iter1
            }
            Part::Two => {
                temp_iter2 = sorted.values_mut();
                &mut temp_iter2
            }
        };
    
        let numlist = iter
            .take(3)
            .reduce(|a, b| {
                a.append(b);
                a
            })
            .unwrap();
    
        println!("{}", numlist[0] * numlist[1] * numlist[2]);
    
        Ok(())
    }
    
    2 votes
  9. kari
    Link
    Pretty short but, because I love to learn a new language for AoC, took me a bit to get started. Gleam seems fun so far :) Both parts import gleam/dict.{type Dict} import gleam/int import...

    Pretty short but, because I love to learn a new language for AoC, took me a bit to get started. Gleam seems fun so far :)

    Both parts
    import gleam/dict.{type Dict}
    import gleam/int
    import gleam/list
    import gleam/order.{type Order}
    import gleam/string
    
    fn counts(input: String) -> Dict(Int, Int) {
      let assert Ok(ids) =
        input
        |> string.split("\n")
        |> list.map(string.trim)
        |> list.filter(fn(line) { !string.is_empty(line) })
        |> list.try_map(int.parse)
    
      ids
      |> list.fold(dict.new(), fn(counts, id) {
        let count = case dict.get(counts, id) {
          Ok(n) -> n + 1
          _ -> 1
        }
    
        dict.insert(counts, id, count)
      })
    }
    
    fn top_three_product(
      input: String,
      compare_counts: fn(Int, Int) -> Order,
    ) -> Int {
      counts(input)
      |> dict.to_list()
      |> list.sort(by: fn(a, b) {
        let #(_, count_a) = a
        let #(_, count_b) = b
        compare_counts(count_a, count_b)
      })
      |> list.take(3)
      |> list.map(fn(pair) {
        let #(id, _count) = pair
        id
      })
      |> list.fold(1, int.multiply)
    }
    
    /// Takes a list of line-separated container-ID numbers.
    /// Returns the product of the three most-common IDs.
    pub fn part1(input: String) -> Int {
      top_three_product(input, fn(a, b) { int.compare(b, a) })
    }
    
    /// Takes a list of line-separated container-ID numbers.
    /// Returns the product of the three least-common IDs.
    pub fn part2(input: String) -> Int {
      top_three_product(input, fn(a, b) { int.compare(a, b) })
    }
    

    I'm not 100% sure how idiomatic it is but I tried to be functional?

    1 vote