TypeScript Day 7
This commit is contained in:
parent
ffbe0a6125
commit
d64729f2fe
8 changed files with 148018 additions and 0 deletions
147392
TypeScript/day7/.yarn/releases/yarn-1.22.10.cjs
vendored
Normal file
147392
TypeScript/day7/.yarn/releases/yarn-1.22.10.cjs
vendored
Normal file
File diff suppressed because one or more lines are too long
5
TypeScript/day7/.yarnrc
Normal file
5
TypeScript/day7/.yarnrc
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||||
|
# yarn lockfile v1
|
||||||
|
|
||||||
|
|
||||||
|
yarn-path ".yarn/releases/yarn-1.22.10.cjs"
|
339
TypeScript/day7/input
Normal file
339
TypeScript/day7/input
Normal file
|
@ -0,0 +1,339 @@
|
||||||
|
bn RSHIFT 2 -> bo
|
||||||
|
lf RSHIFT 1 -> ly
|
||||||
|
fo RSHIFT 3 -> fq
|
||||||
|
cj OR cp -> cq
|
||||||
|
fo OR fz -> ga
|
||||||
|
t OR s -> u
|
||||||
|
lx -> a
|
||||||
|
NOT ax -> ay
|
||||||
|
he RSHIFT 2 -> hf
|
||||||
|
lf OR lq -> lr
|
||||||
|
lr AND lt -> lu
|
||||||
|
dy OR ej -> ek
|
||||||
|
1 AND cx -> cy
|
||||||
|
hb LSHIFT 1 -> hv
|
||||||
|
1 AND bh -> bi
|
||||||
|
ih AND ij -> ik
|
||||||
|
c LSHIFT 1 -> t
|
||||||
|
ea AND eb -> ed
|
||||||
|
km OR kn -> ko
|
||||||
|
NOT bw -> bx
|
||||||
|
ci OR ct -> cu
|
||||||
|
NOT p -> q
|
||||||
|
lw OR lv -> lx
|
||||||
|
NOT lo -> lp
|
||||||
|
fp OR fv -> fw
|
||||||
|
o AND q -> r
|
||||||
|
dh AND dj -> dk
|
||||||
|
ap LSHIFT 1 -> bj
|
||||||
|
bk LSHIFT 1 -> ce
|
||||||
|
NOT ii -> ij
|
||||||
|
gh OR gi -> gj
|
||||||
|
kk RSHIFT 1 -> ld
|
||||||
|
lc LSHIFT 1 -> lw
|
||||||
|
lb OR la -> lc
|
||||||
|
1 AND am -> an
|
||||||
|
gn AND gp -> gq
|
||||||
|
lf RSHIFT 3 -> lh
|
||||||
|
e OR f -> g
|
||||||
|
lg AND lm -> lo
|
||||||
|
ci RSHIFT 1 -> db
|
||||||
|
cf LSHIFT 1 -> cz
|
||||||
|
bn RSHIFT 1 -> cg
|
||||||
|
et AND fe -> fg
|
||||||
|
is OR it -> iu
|
||||||
|
kw AND ky -> kz
|
||||||
|
ck AND cl -> cn
|
||||||
|
bj OR bi -> bk
|
||||||
|
gj RSHIFT 1 -> hc
|
||||||
|
iu AND jf -> jh
|
||||||
|
NOT bs -> bt
|
||||||
|
kk OR kv -> kw
|
||||||
|
ks AND ku -> kv
|
||||||
|
hz OR ik -> il
|
||||||
|
b RSHIFT 1 -> v
|
||||||
|
iu RSHIFT 1 -> jn
|
||||||
|
fo RSHIFT 5 -> fr
|
||||||
|
be AND bg -> bh
|
||||||
|
ga AND gc -> gd
|
||||||
|
hf OR hl -> hm
|
||||||
|
ld OR le -> lf
|
||||||
|
as RSHIFT 5 -> av
|
||||||
|
fm OR fn -> fo
|
||||||
|
hm AND ho -> hp
|
||||||
|
lg OR lm -> ln
|
||||||
|
NOT kx -> ky
|
||||||
|
kk RSHIFT 3 -> km
|
||||||
|
ek AND em -> en
|
||||||
|
NOT ft -> fu
|
||||||
|
NOT jh -> ji
|
||||||
|
jn OR jo -> jp
|
||||||
|
gj AND gu -> gw
|
||||||
|
d AND j -> l
|
||||||
|
et RSHIFT 1 -> fm
|
||||||
|
jq OR jw -> jx
|
||||||
|
ep OR eo -> eq
|
||||||
|
lv LSHIFT 15 -> lz
|
||||||
|
NOT ey -> ez
|
||||||
|
jp RSHIFT 2 -> jq
|
||||||
|
eg AND ei -> ej
|
||||||
|
NOT dm -> dn
|
||||||
|
jp AND ka -> kc
|
||||||
|
as AND bd -> bf
|
||||||
|
fk OR fj -> fl
|
||||||
|
dw OR dx -> dy
|
||||||
|
lj AND ll -> lm
|
||||||
|
ec AND ee -> ef
|
||||||
|
fq AND fr -> ft
|
||||||
|
NOT kp -> kq
|
||||||
|
ki OR kj -> kk
|
||||||
|
cz OR cy -> da
|
||||||
|
as RSHIFT 3 -> au
|
||||||
|
an LSHIFT 15 -> ar
|
||||||
|
fj LSHIFT 15 -> fn
|
||||||
|
1 AND fi -> fj
|
||||||
|
he RSHIFT 1 -> hx
|
||||||
|
lf RSHIFT 2 -> lg
|
||||||
|
kf LSHIFT 15 -> kj
|
||||||
|
dz AND ef -> eh
|
||||||
|
ib OR ic -> id
|
||||||
|
lf RSHIFT 5 -> li
|
||||||
|
bp OR bq -> br
|
||||||
|
NOT gs -> gt
|
||||||
|
fo RSHIFT 1 -> gh
|
||||||
|
bz AND cb -> cc
|
||||||
|
ea OR eb -> ec
|
||||||
|
lf AND lq -> ls
|
||||||
|
NOT l -> m
|
||||||
|
hz RSHIFT 3 -> ib
|
||||||
|
NOT di -> dj
|
||||||
|
NOT lk -> ll
|
||||||
|
jp RSHIFT 3 -> jr
|
||||||
|
jp RSHIFT 5 -> js
|
||||||
|
NOT bf -> bg
|
||||||
|
s LSHIFT 15 -> w
|
||||||
|
eq LSHIFT 1 -> fk
|
||||||
|
jl OR jk -> jm
|
||||||
|
hz AND ik -> im
|
||||||
|
dz OR ef -> eg
|
||||||
|
1 AND gy -> gz
|
||||||
|
la LSHIFT 15 -> le
|
||||||
|
br AND bt -> bu
|
||||||
|
NOT cn -> co
|
||||||
|
v OR w -> x
|
||||||
|
d OR j -> k
|
||||||
|
1 AND gd -> ge
|
||||||
|
ia OR ig -> ih
|
||||||
|
NOT go -> gp
|
||||||
|
NOT ed -> ee
|
||||||
|
jq AND jw -> jy
|
||||||
|
et OR fe -> ff
|
||||||
|
aw AND ay -> az
|
||||||
|
ff AND fh -> fi
|
||||||
|
ir LSHIFT 1 -> jl
|
||||||
|
gg LSHIFT 1 -> ha
|
||||||
|
x RSHIFT 2 -> y
|
||||||
|
db OR dc -> dd
|
||||||
|
bl OR bm -> bn
|
||||||
|
ib AND ic -> ie
|
||||||
|
x RSHIFT 3 -> z
|
||||||
|
lh AND li -> lk
|
||||||
|
ce OR cd -> cf
|
||||||
|
NOT bb -> bc
|
||||||
|
hi AND hk -> hl
|
||||||
|
NOT gb -> gc
|
||||||
|
1 AND r -> s
|
||||||
|
fw AND fy -> fz
|
||||||
|
fb AND fd -> fe
|
||||||
|
1 AND en -> eo
|
||||||
|
z OR aa -> ab
|
||||||
|
bi LSHIFT 15 -> bm
|
||||||
|
hg OR hh -> hi
|
||||||
|
kh LSHIFT 1 -> lb
|
||||||
|
cg OR ch -> ci
|
||||||
|
1 AND kz -> la
|
||||||
|
gf OR ge -> gg
|
||||||
|
gj RSHIFT 2 -> gk
|
||||||
|
dd RSHIFT 2 -> de
|
||||||
|
NOT ls -> lt
|
||||||
|
lh OR li -> lj
|
||||||
|
jr OR js -> jt
|
||||||
|
au AND av -> ax
|
||||||
|
0 -> c
|
||||||
|
he AND hp -> hr
|
||||||
|
id AND if -> ig
|
||||||
|
et RSHIFT 5 -> ew
|
||||||
|
bp AND bq -> bs
|
||||||
|
e AND f -> h
|
||||||
|
ly OR lz -> ma
|
||||||
|
1 AND lu -> lv
|
||||||
|
NOT jd -> je
|
||||||
|
ha OR gz -> hb
|
||||||
|
dy RSHIFT 1 -> er
|
||||||
|
iu RSHIFT 2 -> iv
|
||||||
|
NOT hr -> hs
|
||||||
|
as RSHIFT 1 -> bl
|
||||||
|
kk RSHIFT 2 -> kl
|
||||||
|
b AND n -> p
|
||||||
|
ln AND lp -> lq
|
||||||
|
cj AND cp -> cr
|
||||||
|
dl AND dn -> do
|
||||||
|
ci RSHIFT 2 -> cj
|
||||||
|
as OR bd -> be
|
||||||
|
ge LSHIFT 15 -> gi
|
||||||
|
hz RSHIFT 5 -> ic
|
||||||
|
dv LSHIFT 1 -> ep
|
||||||
|
kl OR kr -> ks
|
||||||
|
gj OR gu -> gv
|
||||||
|
he RSHIFT 5 -> hh
|
||||||
|
NOT fg -> fh
|
||||||
|
hg AND hh -> hj
|
||||||
|
b OR n -> o
|
||||||
|
jk LSHIFT 15 -> jo
|
||||||
|
gz LSHIFT 15 -> hd
|
||||||
|
cy LSHIFT 15 -> dc
|
||||||
|
kk RSHIFT 5 -> kn
|
||||||
|
ci RSHIFT 3 -> ck
|
||||||
|
at OR az -> ba
|
||||||
|
iu RSHIFT 3 -> iw
|
||||||
|
ko AND kq -> kr
|
||||||
|
NOT eh -> ei
|
||||||
|
aq OR ar -> as
|
||||||
|
iy AND ja -> jb
|
||||||
|
dd RSHIFT 3 -> df
|
||||||
|
bn RSHIFT 3 -> bp
|
||||||
|
1 AND cc -> cd
|
||||||
|
at AND az -> bb
|
||||||
|
x OR ai -> aj
|
||||||
|
kk AND kv -> kx
|
||||||
|
ao OR an -> ap
|
||||||
|
dy RSHIFT 3 -> ea
|
||||||
|
x RSHIFT 1 -> aq
|
||||||
|
eu AND fa -> fc
|
||||||
|
kl AND kr -> kt
|
||||||
|
ia AND ig -> ii
|
||||||
|
df AND dg -> di
|
||||||
|
NOT fx -> fy
|
||||||
|
k AND m -> n
|
||||||
|
bn RSHIFT 5 -> bq
|
||||||
|
km AND kn -> kp
|
||||||
|
dt LSHIFT 15 -> dx
|
||||||
|
hz RSHIFT 2 -> ia
|
||||||
|
aj AND al -> am
|
||||||
|
cd LSHIFT 15 -> ch
|
||||||
|
hc OR hd -> he
|
||||||
|
he RSHIFT 3 -> hg
|
||||||
|
bn OR by -> bz
|
||||||
|
NOT kt -> ku
|
||||||
|
z AND aa -> ac
|
||||||
|
NOT ak -> al
|
||||||
|
cu AND cw -> cx
|
||||||
|
NOT ie -> if
|
||||||
|
dy RSHIFT 2 -> dz
|
||||||
|
ip LSHIFT 15 -> it
|
||||||
|
de OR dk -> dl
|
||||||
|
au OR av -> aw
|
||||||
|
jg AND ji -> jj
|
||||||
|
ci AND ct -> cv
|
||||||
|
dy RSHIFT 5 -> eb
|
||||||
|
hx OR hy -> hz
|
||||||
|
eu OR fa -> fb
|
||||||
|
gj RSHIFT 3 -> gl
|
||||||
|
fo AND fz -> gb
|
||||||
|
1 AND jj -> jk
|
||||||
|
jp OR ka -> kb
|
||||||
|
de AND dk -> dm
|
||||||
|
ex AND ez -> fa
|
||||||
|
df OR dg -> dh
|
||||||
|
iv OR jb -> jc
|
||||||
|
x RSHIFT 5 -> aa
|
||||||
|
NOT hj -> hk
|
||||||
|
NOT im -> in
|
||||||
|
fl LSHIFT 1 -> gf
|
||||||
|
hu LSHIFT 15 -> hy
|
||||||
|
iq OR ip -> ir
|
||||||
|
iu RSHIFT 5 -> ix
|
||||||
|
NOT fc -> fd
|
||||||
|
NOT el -> em
|
||||||
|
ck OR cl -> cm
|
||||||
|
et RSHIFT 3 -> ev
|
||||||
|
hw LSHIFT 1 -> iq
|
||||||
|
ci RSHIFT 5 -> cl
|
||||||
|
iv AND jb -> jd
|
||||||
|
dd RSHIFT 5 -> dg
|
||||||
|
as RSHIFT 2 -> at
|
||||||
|
NOT jy -> jz
|
||||||
|
af AND ah -> ai
|
||||||
|
1 AND ds -> dt
|
||||||
|
jx AND jz -> ka
|
||||||
|
da LSHIFT 1 -> du
|
||||||
|
fs AND fu -> fv
|
||||||
|
jp RSHIFT 1 -> ki
|
||||||
|
iw AND ix -> iz
|
||||||
|
iw OR ix -> iy
|
||||||
|
eo LSHIFT 15 -> es
|
||||||
|
ev AND ew -> ey
|
||||||
|
ba AND bc -> bd
|
||||||
|
fp AND fv -> fx
|
||||||
|
jc AND je -> jf
|
||||||
|
et RSHIFT 2 -> eu
|
||||||
|
kg OR kf -> kh
|
||||||
|
iu OR jf -> jg
|
||||||
|
er OR es -> et
|
||||||
|
fo RSHIFT 2 -> fp
|
||||||
|
NOT ca -> cb
|
||||||
|
bv AND bx -> by
|
||||||
|
u LSHIFT 1 -> ao
|
||||||
|
cm AND co -> cp
|
||||||
|
y OR ae -> af
|
||||||
|
bn AND by -> ca
|
||||||
|
1 AND ke -> kf
|
||||||
|
jt AND jv -> jw
|
||||||
|
fq OR fr -> fs
|
||||||
|
dy AND ej -> el
|
||||||
|
NOT kc -> kd
|
||||||
|
ev OR ew -> ex
|
||||||
|
dd OR do -> dp
|
||||||
|
NOT cv -> cw
|
||||||
|
gr AND gt -> gu
|
||||||
|
dd RSHIFT 1 -> dw
|
||||||
|
NOT gw -> gx
|
||||||
|
NOT iz -> ja
|
||||||
|
1 AND io -> ip
|
||||||
|
NOT ag -> ah
|
||||||
|
b RSHIFT 5 -> f
|
||||||
|
NOT cr -> cs
|
||||||
|
kb AND kd -> ke
|
||||||
|
jr AND js -> ju
|
||||||
|
cq AND cs -> ct
|
||||||
|
il AND in -> io
|
||||||
|
NOT ju -> jv
|
||||||
|
du OR dt -> dv
|
||||||
|
dd AND do -> dq
|
||||||
|
b RSHIFT 2 -> d
|
||||||
|
jm LSHIFT 1 -> kg
|
||||||
|
NOT dq -> dr
|
||||||
|
bo OR bu -> bv
|
||||||
|
gk OR gq -> gr
|
||||||
|
he OR hp -> hq
|
||||||
|
NOT h -> i
|
||||||
|
hf AND hl -> hn
|
||||||
|
gv AND gx -> gy
|
||||||
|
x AND ai -> ak
|
||||||
|
bo AND bu -> bw
|
||||||
|
hq AND hs -> ht
|
||||||
|
hz RSHIFT 1 -> is
|
||||||
|
gj RSHIFT 5 -> gm
|
||||||
|
g AND i -> j
|
||||||
|
gk AND gq -> gs
|
||||||
|
dp AND dr -> ds
|
||||||
|
b RSHIFT 3 -> e
|
||||||
|
gl AND gm -> go
|
||||||
|
gl OR gm -> gn
|
||||||
|
y AND ae -> ag
|
||||||
|
hv OR hu -> hw
|
||||||
|
1674 -> b
|
||||||
|
ab AND ad -> ae
|
||||||
|
NOT ac -> ad
|
||||||
|
1 AND ht -> hu
|
||||||
|
NOT hn -> ho
|
16
TypeScript/day7/package.json
Normal file
16
TypeScript/day7/package.json
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"scripts": {
|
||||||
|
"lint": "prettier solution_a.ts solution_b.ts --write --print-width=180",
|
||||||
|
"a": "ts-node solution_a.ts",
|
||||||
|
"b": "ts-node solution_b.ts"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"prettier": "^2.1.2"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@types/node": "^14.14.8",
|
||||||
|
"ts-node": "^9.0.0",
|
||||||
|
"typescript": "^4.0.5"
|
||||||
|
},
|
||||||
|
"license": "WTFPL"
|
||||||
|
}
|
64
TypeScript/day7/solution_a.ts
Normal file
64
TypeScript/day7/solution_a.ts
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
import fs from "fs";
|
||||||
|
const input = fs.readFileSync("input").toString().split("\n");
|
||||||
|
const COMMAND_REGEX = /[A-Z]+/g;
|
||||||
|
const ARGUMENTS_REGEX = /[a-z0-9]+/g;
|
||||||
|
|
||||||
|
// Dictionary of our bitwise methods
|
||||||
|
const BITWISE_METHODS = {
|
||||||
|
AND: (a: number, b: number) => a & b,
|
||||||
|
OR: (a: number, b: number) => a | b,
|
||||||
|
NOT: (a: number, b?: number) => ~a,
|
||||||
|
LSHIFT: (a: number, b: number) => a << b,
|
||||||
|
RSHIFT: (a: number, b: number) => a >> b,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Parse instruction from input and return object with command, arguments and destination wire
|
||||||
|
function parseInstruction(instruction: string): Instruction & { destination: string } {
|
||||||
|
const raw_command = instruction.match(COMMAND_REGEX);
|
||||||
|
const args = instruction.match(ARGUMENTS_REGEX) ?? [];
|
||||||
|
const destination = args.pop()!;
|
||||||
|
const command = raw_command === null ? raw_command : (raw_command[0] as keyof typeof BITWISE_METHODS);
|
||||||
|
|
||||||
|
return {
|
||||||
|
command,
|
||||||
|
args: args.map((arg) => (isNaN(Number(arg)) ? arg : Number(arg))) as [Wire | number, Wire | number | undefined],
|
||||||
|
destination,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
type Wire = string;
|
||||||
|
type Instruction = {
|
||||||
|
command: keyof typeof BITWISE_METHODS | null;
|
||||||
|
args: [Wire | number, Wire | number | undefined];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Calculate value for one of the wires (recursively)
|
||||||
|
function calculateWire(wireName: Wire, wires: Map<Wire, any>) {
|
||||||
|
const wire = wires.get(wireName);
|
||||||
|
|
||||||
|
if (typeof wireName === "number") return wireName;
|
||||||
|
if (typeof wire === "number") return wire;
|
||||||
|
if (typeof wire === "undefined") return undefined;
|
||||||
|
|
||||||
|
if (!wire.command) {
|
||||||
|
wires.set(wireName, calculateWire(wire.args[0], wires));
|
||||||
|
} else if (Object.keys(BITWISE_METHODS).includes(wire.command)) {
|
||||||
|
wires.set(wireName, BITWISE_METHODS[wire.command as keyof typeof BITWISE_METHODS](calculateWire(wire.args[0], wires), calculateWire(wire.args[1], wires)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return wires.get(wireName);
|
||||||
|
}
|
||||||
|
async function main() {
|
||||||
|
// Our parsed wires in format {wire: value} or {wire: instruction}
|
||||||
|
const wires = new Map<Wire, Instruction>();
|
||||||
|
|
||||||
|
// Fill WIRES with parsed instructions and their future values
|
||||||
|
input.forEach((instruction) => {
|
||||||
|
const parsedInstruction = parseInstruction(instruction.trim());
|
||||||
|
wires.set(parsedInstruction.destination, { command: parsedInstruction.command, args: parsedInstruction.args });
|
||||||
|
});
|
||||||
|
|
||||||
|
return calculateWire("a", wires);
|
||||||
|
}
|
||||||
|
|
||||||
|
main().then(console.log).catch(console.error);
|
66
TypeScript/day7/solution_b.ts
Normal file
66
TypeScript/day7/solution_b.ts
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
import fs from "fs";
|
||||||
|
const input = fs.readFileSync("input").toString().split("\n");
|
||||||
|
const COMMAND_REGEX = /[A-Z]+/g;
|
||||||
|
const ARGUMENTS_REGEX = /[a-z0-9]+/g;
|
||||||
|
|
||||||
|
// Dictionary of our bitwise methods
|
||||||
|
const BITWISE_METHODS = {
|
||||||
|
AND: (a: number, b: number) => a & b,
|
||||||
|
OR: (a: number, b: number) => a | b,
|
||||||
|
NOT: (a: number, b?: number) => ~a,
|
||||||
|
LSHIFT: (a: number, b: number) => a << b,
|
||||||
|
RSHIFT: (a: number, b: number) => a >> b,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Parse instruction from input and return object with command, arguments and destination wire
|
||||||
|
function parseInstruction(instruction: string): Instruction & { destination: string } {
|
||||||
|
const raw_command = instruction.match(COMMAND_REGEX);
|
||||||
|
const args = instruction.match(ARGUMENTS_REGEX) ?? [];
|
||||||
|
const destination = args.pop()!;
|
||||||
|
const command = raw_command === null ? raw_command : (raw_command[0] as keyof typeof BITWISE_METHODS);
|
||||||
|
|
||||||
|
return {
|
||||||
|
command,
|
||||||
|
args: args.map((arg) => (isNaN(Number(arg)) ? arg : Number(arg))) as [Wire | number, Wire | number | undefined],
|
||||||
|
destination,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
type Wire = string;
|
||||||
|
type Instruction = {
|
||||||
|
command: keyof typeof BITWISE_METHODS | null;
|
||||||
|
args: [Wire | number, Wire | number | undefined];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Calculate value for one of the wires (recursively)
|
||||||
|
function calculateWire(wireName: Wire, wires: Map<Wire, any>) {
|
||||||
|
const wire = wires.get(wireName);
|
||||||
|
|
||||||
|
if (typeof wireName === "number") return wireName;
|
||||||
|
if (typeof wire === "number") return wire;
|
||||||
|
if (typeof wire === "undefined") return undefined;
|
||||||
|
|
||||||
|
if (!wire.command) {
|
||||||
|
wires.set(wireName, calculateWire(wire.args[0], wires));
|
||||||
|
} else if (Object.keys(BITWISE_METHODS).includes(wire.command)) {
|
||||||
|
wires.set(wireName, BITWISE_METHODS[wire.command as keyof typeof BITWISE_METHODS](calculateWire(wire.args[0], wires), calculateWire(wire.args[1], wires)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return wires.get(wireName);
|
||||||
|
}
|
||||||
|
async function main() {
|
||||||
|
// Our parsed wires in format {wire: value} or {wire: instruction}
|
||||||
|
const wires = new Map<Wire, Instruction>();
|
||||||
|
|
||||||
|
// Fill WIRES with parsed instructions and their future values
|
||||||
|
input.forEach((instruction) => {
|
||||||
|
const parsedInstruction = parseInstruction(instruction.trim());
|
||||||
|
wires.set(parsedInstruction.destination, { command: parsedInstruction.command, args: parsedInstruction.args });
|
||||||
|
});
|
||||||
|
const parsedInstruction = parseInstruction("46065 -> b");
|
||||||
|
wires.set(parsedInstruction.destination, { command: parsedInstruction.command, args: parsedInstruction.args });
|
||||||
|
|
||||||
|
return calculateWire("a", wires);
|
||||||
|
}
|
||||||
|
|
||||||
|
main().then(console.log).catch(console.error);
|
69
TypeScript/day7/tsconfig.json
Normal file
69
TypeScript/day7/tsconfig.json
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||||
|
|
||||||
|
/* Basic Options */
|
||||||
|
// "incremental": true, /* Enable incremental compilation */
|
||||||
|
"target": "ES2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
||||||
|
"module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
||||||
|
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||||
|
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||||
|
// "checkJs": true, /* Report errors in .js files. */
|
||||||
|
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||||
|
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||||
|
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||||
|
"sourceMap": false, /* Generates corresponding '.map' file. */
|
||||||
|
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||||
|
// "outDir": "./", /* Redirect output structure to the directory. */
|
||||||
|
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||||
|
// "composite": true, /* Enable project compilation */
|
||||||
|
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||||
|
// "removeComments": true, /* Do not emit comments to output. */
|
||||||
|
"noEmit": true, /* Do not emit outputs. */
|
||||||
|
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||||
|
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||||
|
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||||
|
|
||||||
|
/* Strict Type-Checking Options */
|
||||||
|
"strict": true, /* Enable all strict type-checking options. */
|
||||||
|
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||||
|
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||||
|
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||||
|
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||||
|
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||||
|
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||||
|
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||||
|
|
||||||
|
/* Additional Checks */
|
||||||
|
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||||
|
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||||
|
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||||
|
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||||
|
|
||||||
|
/* Module Resolution Options */
|
||||||
|
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||||
|
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||||
|
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||||
|
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||||
|
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||||
|
// "types": [], /* Type declaration files to be included in compilation. */
|
||||||
|
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||||
|
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||||
|
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||||
|
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||||
|
|
||||||
|
/* Source Map Options */
|
||||||
|
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||||
|
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||||
|
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||||
|
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||||
|
|
||||||
|
/* Experimental Options */
|
||||||
|
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||||
|
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||||
|
|
||||||
|
/* Advanced Options */
|
||||||
|
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
||||||
|
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
||||||
|
}
|
||||||
|
}
|
67
TypeScript/day7/yarn.lock
Normal file
67
TypeScript/day7/yarn.lock
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||||
|
# yarn lockfile v1
|
||||||
|
|
||||||
|
|
||||||
|
"@types/node@^14.14.8":
|
||||||
|
version "14.14.8"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.8.tgz#2127bd81949a95c8b7d3240f3254352d72563aec"
|
||||||
|
integrity sha512-z/5Yd59dCKI5kbxauAJgw6dLPzW+TNOItNE00PkpzNwUIEwdj/Lsqwq94H5DdYBX7C13aRA0CY32BK76+neEUA==
|
||||||
|
|
||||||
|
arg@^4.1.0:
|
||||||
|
version "4.1.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
|
||||||
|
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
|
||||||
|
|
||||||
|
buffer-from@^1.0.0:
|
||||||
|
version "1.1.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
|
||||||
|
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
|
||||||
|
|
||||||
|
diff@^4.0.1:
|
||||||
|
version "4.0.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
|
||||||
|
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
|
||||||
|
|
||||||
|
make-error@^1.1.1:
|
||||||
|
version "1.3.6"
|
||||||
|
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
|
||||||
|
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
|
||||||
|
|
||||||
|
prettier@^2.1.2:
|
||||||
|
version "2.1.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5"
|
||||||
|
integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==
|
||||||
|
|
||||||
|
source-map-support@^0.5.17:
|
||||||
|
version "0.5.19"
|
||||||
|
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
|
||||||
|
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
|
||||||
|
dependencies:
|
||||||
|
buffer-from "^1.0.0"
|
||||||
|
source-map "^0.6.0"
|
||||||
|
|
||||||
|
source-map@^0.6.0:
|
||||||
|
version "0.6.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
|
||||||
|
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
|
||||||
|
|
||||||
|
ts-node@^9.0.0:
|
||||||
|
version "9.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-9.0.0.tgz#e7699d2a110cc8c0d3b831715e417688683460b3"
|
||||||
|
integrity sha512-/TqB4SnererCDR/vb4S/QvSZvzQMJN8daAslg7MeaiHvD8rDZsSfXmNeNumyZZzMned72Xoq/isQljYSt8Ynfg==
|
||||||
|
dependencies:
|
||||||
|
arg "^4.1.0"
|
||||||
|
diff "^4.0.1"
|
||||||
|
make-error "^1.1.1"
|
||||||
|
source-map-support "^0.5.17"
|
||||||
|
yn "3.1.1"
|
||||||
|
|
||||||
|
typescript@^4.0.5:
|
||||||
|
version "4.0.5"
|
||||||
|
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389"
|
||||||
|
integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ==
|
||||||
|
|
||||||
|
yn@3.1.1:
|
||||||
|
version "3.1.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
|
||||||
|
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==
|
Loading…
Reference in a new issue