5 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>

6 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!

    4 votes
  2. 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
  3. 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();
    
    1 vote
  4. 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
  5. 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
    
  6. lily
    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.size() == 0: {
            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]
    ))