File tree Expand file tree Collapse file tree 1 file changed +94
-0
lines changed
Expand file tree Collapse file tree 1 file changed +94
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ descriptions : ["deno"]
3+ ---
4+
5+ ### 2025 Solution Deno
6+
7+ ### Output
8+
9+ ```
10+ 1: Solutions - 1
11+ 2: Solutions - 1
12+ 3: Solutions - 3
13+ 4: Solutions - 4
14+ 5: Solutions - 7
15+ 6: Solutions - 14
16+ 7: Solutions - 23
17+ 8: Solutions - 39
18+ 9: Solutions - 71
19+ 10: Solutions - 123
20+ 11: Solutions - 211
21+ 12: Solutions - 372
22+ 13: Solutions - 647
23+ 14: Solutions - 1123
24+ 15: Solutions - 1967
25+ 16: Solutions - 3426
26+ 17: Solutions - 5961
27+ 18: Solutions - 10405
28+ 19: Solutions - 18134
29+ 20: Solutions - 31593
30+ 21: Solutions - 55094
31+ 22: Solutions - 96030
32+ 23: Solutions - 167357
33+ 24: Solutions - 291758
34+ 25: Solutions - 508564
35+ 26: Solutions - 886414
36+ 27: Solutions - 1545162
37+ 28: Solutions - 2693373
38+ 29: Solutions - 4694687
39+ 30: Solutions - 8183372
40+ 31: Solutions - 14264404
41+ ```
42+
43+ ``` ts
44+ class TubeSleigh {
45+ private static memorizedSolutions: Map <string , number [][]> = new Map ();
46+ private sequences: Generator <number []>;
47+ private sleighLength: number ;
48+
49+ constructor (sleighLength : number ) {
50+ this .sleighLength = sleighLength ;
51+ this .sequences = this .solve (sleighLength , undefined );
52+ }
53+
54+ public * solve(
55+ n : number ,
56+ prev : number | undefined = undefined ,
57+ prefix : number [] = []
58+ ): Generator <number []> {
59+ if (n === 0 ) {
60+ yield prefix ;
61+ return ;
62+ }
63+
64+ for (let i = 1 ; i <= n && i < 10 ; i ++ ) {
65+ if (i !== prev ) {
66+ for (const seq of this .solve (n - i , i , [... prefix , i ])) {
67+ yield seq ;
68+ }
69+ }
70+ }
71+ }
72+
73+ public printSeq() {
74+ for (const seq of this .sequences ) {
75+ console .log (seq .join (" , " ));
76+ }
77+ }
78+
79+ public printSolutionsCount() {
80+ let count = 0 ;
81+ for (const _ of this .sequences ) {
82+ count ++ ;
83+ }
84+ console .log (` ${this .sleighLength }: Solutions - ${count } ` );
85+ }
86+ }
87+
88+ if (import .meta .main ) {
89+ for (let i = 1 ; i <= 31 ; i ++ ) {
90+ const myTubeSleigh = new TubeSleigh (i );
91+ myTubeSleigh .printSolutionsCount ();
92+ }
93+ }
94+ ```
You can’t perform that action at this time.
0 commit comments