File tree 9 files changed +26
-52
lines changed
9 files changed +26
-52
lines changed Original file line number Diff line number Diff line change 1
1
import type { Grid , ReadonlyGrid } from "../../grid.ts" ;
2
2
3
+ import lcm from "../../../../../lib/lcm.ts" ;
4
+ import mod from "../../../../../lib/mod.ts" ;
5
+
3
6
const charToDirection = {
4
7
"^" : { x : 0 , y : - 1 } ,
5
8
"v" : { x : 0 , y : 1 } ,
@@ -13,19 +16,6 @@ function parseGrid(text: string): ReadonlyGrid {
13
16
) ;
14
17
}
15
18
16
- function gcd ( a : number , b : number ) : number {
17
- while ( b ) [ a , b ] = [ b , a % b ] ;
18
- return a ;
19
- }
20
-
21
- function lcm ( a : number , b : number ) {
22
- return a * b / gcd ( a , b ) ;
23
- }
24
-
25
- function mod ( n : number , d : number ) {
26
- return ( ( n % d ) + d ) % d ;
27
- }
28
-
29
19
function calculateGrid ( initialGrid : ReadonlyGrid , step : number ) : ReadonlyGrid {
30
20
const { length : height , 0 : { length : width } } = initialGrid ;
31
21
const result = structuredClone ( initialGrid ) as Grid ;
Original file line number Diff line number Diff line change 1
1
import type { Grid , ReadonlyGrid } from "../../grid.ts" ;
2
2
3
+ import lcm from "../../../../../lib/lcm.ts" ;
4
+ import mod from "../../../../../lib/mod.ts" ;
5
+
3
6
const charToDirection = {
4
7
"^" : { x : 0 , y : - 1 } ,
5
8
"v" : { x : 0 , y : 1 } ,
6
9
"<" : { x : - 1 , y : 0 } ,
7
10
">" : { x : 1 , y : 0 } ,
8
11
} ;
9
12
10
- function gcd ( a : number , b : number ) : number {
11
- while ( b ) [ a , b ] = [ b , a % b ] ;
12
- return a ;
13
- }
14
-
15
- function lcm ( a : number , b : number ) {
16
- return a * b / gcd ( a , b ) ;
17
- }
18
-
19
- function mod ( n : number , d : number ) {
20
- return ( ( n % d ) + d ) % d ;
21
- }
22
-
23
13
function calculateGrid ( initialGrid : ReadonlyGrid , step : number ) : ReadonlyGrid {
24
14
const { length : height , 0 : { length : width } } = initialGrid ;
25
15
const result = structuredClone ( initialGrid ) as Grid ;
Original file line number Diff line number Diff line change
1
+ import lcm from "../../../../../lib/lcm.ts" ;
2
+
1
3
type Pulse = { source : string ; type : "low" | "high" ; destination : string } ;
2
4
3
5
type CommonModuleProps = {
@@ -18,15 +20,6 @@ type UntypedModule = CommonModuleProps & {
18
20
} ;
19
21
type Module = FlipFlopModule | ConjunctionModule | UntypedModule ;
20
22
21
- function gcd ( a : number , b : number ) : number {
22
- while ( b ) [ a , b ] = [ b , a % b ] ;
23
- return a ;
24
- }
25
-
26
- function lcm ( a : number , b : number ) {
27
- return a * b / gcd ( a , b ) ;
28
- }
29
-
30
23
export default function solve ( input : string ) {
31
24
const modules = input . split ( "\n" ) . map < Module > ( ( line ) => {
32
25
const [ left , right ] = line . split ( " -> " ) ;
Original file line number Diff line number Diff line change 1
1
import { BinaryHeap } from "std/data_structures/binary_heap.ts" ;
2
2
3
+ import mod from "../../../../../lib/mod.ts" ;
4
+
3
5
const directions = [
4
6
{ x : 0 , y : 1 } ,
5
7
{ x : 0 , y : - 1 } ,
6
8
{ x : - 1 , y : 0 } ,
7
9
{ x : 1 , y : 0 } ,
8
10
] ;
9
11
10
- function mod ( a : number , b : number ) {
11
- return ( ( a % b ) + b ) % b ;
12
- }
13
-
14
12
function _solve ( input : string , { steps = 26501365 } = { } ) {
15
13
const map = input . split ( "\n" ) ;
16
14
const { length : height , 0 : { length : width } } = map ;
Original file line number Diff line number Diff line change
1
+ import lcm from "../../../../../lib/lcm.ts" ;
2
+
1
3
function parseDocuments ( text : string ) {
2
4
const [ instructionsText , networkText ] = text . split ( "\n\n" ) ;
3
5
const instructions = Array . from (
@@ -12,15 +14,6 @@ function parseDocuments(text: string) {
12
14
return { instructions, network } ;
13
15
}
14
16
15
- function gcd ( a : number , b : number ) : number {
16
- while ( b ) [ a , b ] = [ b , a % b ] ;
17
- return a ;
18
- }
19
-
20
- function lcm ( a : number , b : number ) {
21
- return a * b / gcd ( a , b ) ;
22
- }
23
-
24
17
export default function solve ( input : string ) {
25
18
const { instructions, network } = parseDocuments ( input ) ;
26
19
return Array . from ( network . keys ( ) )
Original file line number Diff line number Diff line change
1
+ import mod from "../../../../../lib/mod.ts" ;
2
+
1
3
const regExp = / ^ p = (?< px > \d + ) , (?< py > \d + ) v = (?< vx > - ? \d + ) , (?< vy > - ? \d + ) $ / gm;
2
4
3
5
export default function solve (
@@ -15,7 +17,3 @@ export default function solve(
15
17
}
16
18
return quadrantCounts . reduce ( ( product , count ) => product * count , 1 ) ;
17
19
}
18
-
19
- function mod ( a : number , b : number ) {
20
- return ( ( a % b ) + b ) % b ;
21
- }
Original file line number Diff line number Diff line change
1
+ export default function gcd ( a : number , b : number ) : number {
2
+ while ( b ) [ a , b ] = [ b , a % b ] ;
3
+ return a ;
4
+ }
Original file line number Diff line number Diff line change
1
+ import gcd from "./gcd.ts" ;
2
+
3
+ export default function lcm ( a : number , b : number ) {
4
+ return a * b / gcd ( a , b ) ;
5
+ }
Original file line number Diff line number Diff line change
1
+ export default function mod ( n : number , d : number ) {
2
+ return ( ( n % d ) + d ) % d ;
3
+ }
You can’t perform that action at this time.
0 commit comments