LogoWCF

dallinstevens's Solution

2025 Solution Deno

Output

1: Solutions - 1
2: Solutions - 1
3: Solutions - 3
4: Solutions - 4
5: Solutions - 7
6: Solutions - 14
7: Solutions - 23
8: Solutions - 39
9: Solutions - 71
10: Solutions - 123
11: Solutions - 211
12: Solutions - 372
13: Solutions - 647
14: Solutions - 1123
15: Solutions - 1967
16: Solutions - 3426
17: Solutions - 5961
18: Solutions - 10405
19: Solutions - 18134
20: Solutions - 31593
21: Solutions - 55094
22: Solutions - 96030
23: Solutions - 167357
24: Solutions - 291758
25: Solutions - 508564
26: Solutions - 886414
27: Solutions - 1545162
28: Solutions - 2693373
29: Solutions - 4694687
30: Solutions - 8183372
31: Solutions - 14264404
class TubeSleigh {
  private static memorizedSolutions: Map<string, number[][]> = new Map();
  private sequences: Generator<number[]>;
  private sleighLength: number;

  constructor(sleighLength: number) {
    this.sleighLength = sleighLength;
    this.sequences = this.solve(sleighLength, undefined);
  }

  public *solve(
    n: number,
    prev: number | undefined = undefined,
    prefix: number[] = []
  ): Generator<number[]> {
    if (n === 0) {
      yield prefix;
      return;
    }

    for (let i = 1; i <= n && i < 10; i++) {
      if (i !== prev) {
        for (const seq of this.solve(n - i, i, [...prefix, i])) {
          yield seq;
        }
      }
    }
  }

  public printSeq() {
    for (const seq of this.sequences) {
      console.log(seq.join(", "));
    }
  }

  public printSolutionsCount() {
    let count = 0;
    for (const _ of this.sequences) {
      count++;
    }
    console.log(`${this.sleighLength}: Solutions - ${count}`);
  }
}

if (import.meta.main) {
  for (let i = 1; i <= 31; i++) {
    const myTubeSleigh = new TubeSleigh(i);
    myTubeSleigh.printSolutionsCount();
  }
}

Day 8: Santa's Tube Sleigh

Santa has limited space in his sleigh, so he needs to know the different ways it can be packed. Santa is magic, so his sleigh is a tube that can store only one long line of presents (check out Jesse’s lore for the reason why! It’s very interesting). Presents can be of any size from 1 - 9, but max out at the size of the sleigh (for when the sleigh is smaller than 9). Because of magic reasons (again, check the lore!), presents of the same size can’t be next to one another. Also, you’re only searching for present arrangements that fill the sleigh. An empty sleigh is not allowed! Neither is one with any gaps!

Here’s an example of all the possible combos for a sleigh of length 3:

Note, 1, 1, 1 is not allowed because it has 2 presents of the same size next to each other!

Some more examples for different sleigh sizes:

4:

5:

For 10 (which has 123 total valid combinations)
  • 1, 2, 1, 2, 1, 2, 1
  • 1, 2, 1, 2, 1, 3
  • 1, 2, 1, 2, 3, 1
  • 1, 2, 1, 2, 4
  • 1, 2, 1, 3, 1, 2
  • 1, 2, 1, 3, 2, 1
  • 1, 2, 1, 4, 2
  • 1, 2, 1, 5, 1
  • 1, 2, 1, 6
  • 1, 2, 3, 1, 2, 1
  • 1, 2, 3, 1, 3
  • 1, 2, 3, 4
  • 1, 2, 4, 1, 2
  • 1, 2, 4, 2, 1
  • 1, 2, 4, 3
  • 1, 2, 5, 2
  • 1, 2, 6, 1
  • 1, 2, 7
  • 1, 3, 1, 2, 1, 2
  • 1, 3, 1, 2, 3
  • 1, 3, 1, 3, 2
  • 1, 3, 1, 4, 1
  • 1, 3, 1, 5
  • 1, 3, 2, 1, 2, 1
  • 1, 3, 2, 1, 3
  • 1, 3, 2, 3, 1
  • 1, 3, 2, 4
  • 1, 3, 4, 2
  • 1, 3, 5, 1
  • 1, 3, 6
  • 1, 4, 1, 3, 1
  • 1, 4, 1, 4
  • 1, 4, 2, 1, 2
  • 1, 4, 2, 3
  • 1, 4, 3, 2
  • 1, 4, 5
  • 1, 5, 1, 2, 1
  • 1, 5, 1, 3
  • 1, 5, 3, 1
  • 1, 5, 4
  • 1, 6, 1, 2
  • 1, 6, 2, 1
  • 1, 6, 3
  • 1, 7, 2
  • 1, 8, 1
  • 1, 9
  • 2, 1, 2, 1, 3, 1
  • 2, 1, 2, 1, 4
  • 2, 1, 2, 3, 2
  • 2, 1, 2, 4, 1
  • 2, 1, 2, 5
  • 2, 1, 3, 1, 2, 1
  • 2, 1, 3, 1, 3
  • 2, 1, 3, 4
  • 2, 1, 4, 1, 2
  • 2, 1, 4, 2, 1
  • 2, 1, 4, 3
  • 2, 1, 5, 2
  • 2, 1, 6, 1
  • 2, 1, 7
  • 2, 3, 1, 3, 1
  • 2, 3, 1, 4
  • 2, 3, 2, 1, 2
  • 2, 3, 2, 3
  • 2, 3, 4, 1
  • 2, 3, 5
  • 2, 4, 1, 2, 1
  • 2, 4, 1, 3
  • 2, 4, 3, 1
  • 2, 5, 1, 2
  • 2, 5, 2, 1
  • 2, 5, 3
  • 2, 6, 2
  • 2, 7, 1
  • 2, 8
  • 3, 1, 2, 1, 2, 1
  • 3, 1, 2, 1, 3
  • 3, 1, 2, 3, 1
  • 3, 1, 2, 4
  • 3, 1, 3, 1, 2
  • 3, 1, 3, 2, 1
  • 3, 1, 4, 2
  • 3, 1, 5, 1
  • 3, 1, 6
  • 3, 2, 1, 3, 1
  • 3, 2, 1, 4
  • 3, 2, 3, 2
  • 3, 2, 4, 1
  • 3, 2, 5
  • 3, 4, 1, 2
  • 3, 4, 2, 1
  • 3, 4, 3
  • 3, 5, 2
  • 3, 6, 1
  • 3, 7
  • 4, 1, 2, 1, 2
  • 4, 1, 2, 3
  • 4, 1, 3, 2
  • 4, 1, 4, 1
  • 4, 1, 5
  • 4, 2, 1, 2, 1
  • 4, 2, 1, 3
  • 4, 2, 3, 1
  • 4, 2, 4
  • 4, 3, 1, 2
  • 4, 3, 2, 1
  • 4, 5, 1
  • 4, 6
  • 5, 1, 3, 1
  • 5, 1, 4
  • 5, 2, 1, 2
  • 5, 2, 3
  • 5, 3, 2
  • 5, 4, 1
  • 6, 1, 2, 1
  • 6, 1, 3
  • 6, 3, 1
  • 6, 4
  • 7, 1, 2
  • 7, 2, 1
  • 7, 3
  • 8, 2
  • 9, 1

Problem: Find the number of possible arrangements of presents for a sleigh of length 30. For an extra challenge, see how large a sleigh you can compute the number of combinations for!


Jesse's Lore Jesse will fill this out