File tree Expand file tree Collapse file tree 9 files changed +26
-52
lines changed
Expand file tree Collapse file tree 9 files changed +26
-52
lines changed Original file line number Diff line number Diff line change 11import type { Grid , ReadonlyGrid } from "../../grid.ts" ;
22
3+ import lcm from "../../../../../lib/lcm.ts" ;
4+ import mod from "../../../../../lib/mod.ts" ;
5+
36const charToDirection = {
47 "^" : { x : 0 , y : - 1 } ,
58 "v" : { x : 0 , y : 1 } ,
@@ -13,19 +16,6 @@ function parseGrid(text: string): ReadonlyGrid {
1316 ) ;
1417}
1518
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-
2919function calculateGrid ( initialGrid : ReadonlyGrid , step : number ) : ReadonlyGrid {
3020 const { length : height , 0 : { length : width } } = initialGrid ;
3121 const result = structuredClone ( initialGrid ) as Grid ;
Original file line number Diff line number Diff line change 11import type { Grid , ReadonlyGrid } from "../../grid.ts" ;
22
3+ import lcm from "../../../../../lib/lcm.ts" ;
4+ import mod from "../../../../../lib/mod.ts" ;
5+
36const charToDirection = {
47 "^" : { x : 0 , y : - 1 } ,
58 "v" : { x : 0 , y : 1 } ,
69 "<" : { x : - 1 , y : 0 } ,
710 ">" : { x : 1 , y : 0 } ,
811} ;
912
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-
2313function calculateGrid ( initialGrid : ReadonlyGrid , step : number ) : ReadonlyGrid {
2414 const { length : height , 0 : { length : width } } = initialGrid ;
2515 const result = structuredClone ( initialGrid ) as Grid ;
Original file line number Diff line number Diff line change 1+ import lcm from "../../../../../lib/lcm.ts" ;
2+
13type Pulse = { source : string ; type : "low" | "high" ; destination : string } ;
24
35type CommonModuleProps = {
@@ -18,15 +20,6 @@ type UntypedModule = CommonModuleProps & {
1820} ;
1921type Module = FlipFlopModule | ConjunctionModule | UntypedModule ;
2022
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-
3023export default function solve ( input : string ) {
3124 const modules = input . split ( "\n" ) . map < Module > ( ( line ) => {
3225 const [ left , right ] = line . split ( " -> " ) ;
Original file line number Diff line number Diff line change 11import { BinaryHeap } from "std/data_structures/binary_heap.ts" ;
22
3+ import mod from "../../../../../lib/mod.ts" ;
4+
35const directions = [
46 { x : 0 , y : 1 } ,
57 { x : 0 , y : - 1 } ,
68 { x : - 1 , y : 0 } ,
79 { x : 1 , y : 0 } ,
810] ;
911
10- function mod ( a : number , b : number ) {
11- return ( ( a % b ) + b ) % b ;
12- }
13-
1412function _solve ( input : string , { steps = 26501365 } = { } ) {
1513 const map = input . split ( "\n" ) ;
1614 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+
13function parseDocuments ( text : string ) {
24 const [ instructionsText , networkText ] = text . split ( "\n\n" ) ;
35 const instructions = Array . from (
@@ -12,15 +14,6 @@ function parseDocuments(text: string) {
1214 return { instructions, network } ;
1315}
1416
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-
2417export default function solve ( input : string ) {
2518 const { instructions, network } = parseDocuments ( input ) ;
2619 return Array . from ( network . keys ( ) )
Original file line number Diff line number Diff line change 1+ import mod from "../../../../../lib/mod.ts" ;
2+
13const regExp = / ^ p = (?< px > \d + ) , (?< py > \d + ) v = (?< vx > - ? \d + ) , (?< vy > - ? \d + ) $ / gm;
24
35export default function solve (
@@ -15,7 +17,3 @@ export default function solve(
1517 }
1618 return quadrantCounts . reduce ( ( product , count ) => product * count , 1 ) ;
1719}
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