Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
TimHi committed Dec 21, 2023
1 parent d2d01bb commit e29e0f8
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 16 deletions.
6 changes: 4 additions & 2 deletions Ruby/2023/d2/day02.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ def is_valid(line)
def solve
data = true ? DATA.readlines : File.open(File.join(File.dirname(__FILE__), 'full.txt')
).readlines.map(&:chomp)

puts data.select { |line|
is_valid(line)
}.map { |l| get_game_id(l) }.flatten.sum


data.map { |line| }
end
solve

__END__
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
Expand Down
65 changes: 57 additions & 8 deletions Typescript/2023/src/days/day20/Part2.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,75 @@
import * as fs from "fs";

interface Conjection {
interface Module {
id: string;
memory: Map<string, boolean>;
destinations: string[];
origins: string[];
}
interface Conjunction extends Module {
memory: Map<string, boolean>;
}

interface FlipFlop {
id: string;
interface FlipFlop extends Module {
state: boolean;
destinations: string[];
origins: string[];
}

interface Broadcast extends Module {}
interface Output extends Module {}

//&xq -> zl, cx, qh, hs, nt, sp
function parseMap(isSample: boolean) {
const fileName = isSample ? "/src/days/day20/sample.txt" : "/src/days/day20/full.txt";
const conjections: Conjunction[] = [];

const map = new Map<string, Module>();
fs.readFileSync(process.cwd() + fileName, "utf8")
.split("\n")
.forEach((line) => {});
.forEach((line) => {
const split = line.split(" -> ");
const origin = split[0];
const destinations = split[1].split(", ");
if (origin[0] === "%") {
const flip: FlipFlop = { id: origin.substring(1), destinations: destinations, state: false };
map.set(flip.id, flip);
} else if (origin[0] === "&") {
const con: Conjunction = { id: origin.substring(1), destinations: destinations, memory: new Map<string, boolean>() };
map.set(con.id, con);
conjections.push(con);
} else if (origin === "broadcaster") {
const broadcaster: Broadcast = { id: origin, destinations: destinations };
map.set(broadcaster.id, broadcaster);
} else {
const output: Output = { id: origin.substring(1), destinations: destinations };
map.set(output.id, output);
}

if (isSample) {
const out: Output = { id: "output", destinations: [] };
map.set(out.id, out);
} else {
const out: Output = { id: "rx", destinations: [] };
map.set(out.id, out);
}
});
return map;
}

export function CalculateNeededPresses(isSample: boolean): number {
const map = parseMap(isSample);
//https://www.devtoolsdaily.com/graphviz/full-screen/?#v2=N4IgJg9gLiBc4EsDmAnAhgBwBYAIDiOwAOgHY45YDOOAtAHw6UA2pYStDKAHqQG4YccAMzAAaHGF6kA1gC9BAKwDG4gLZLSJXoMmksXQUiGlVqwbyykRgqGFbb6FLuIBGTcShXCxOLlD3sjlwAjqS2Orzi+qRuiv4kLiiKoSTBuI5MJKQhgrLuOErOOGlRlOIkUOKUGKSUgQy8kThQKKxmjm7iuiRIUIIhUUikmYKqweIhJkr9TcphBo4osxokTNI6QySq9RT5c1oODLJNieLSRabiLZp9QeMFPCTHG6RKYIpeGJSknoIoql0pCQSApBBhKr4UokIGgwEo0JQoABTJKOCpnIqeNSbIw6Lzdf46AESIFcBYNJpKWSkBS3BiScT8Uh5QQg2oCRxsbLTRzKM7Ukh+F4VDkMfZMHkUxlZLTpBhkxlAsaCKgTFJKSU4Rp8MiORriDVhVEMRJ6JiCYIucT7OERcpAhTBUbE7Ukc7mJp1V7k4qWEjMXL5SYkKmCCWK0iWj4GuwgzVfCZNNbY7KHZqPcH9e69H5pvnNGokL79FakciItAoPoAbUoWEwSIAvABZMAINCqCAkMAAXQA3GWcEjuzha-WME3m5RggBXStI-ukAC+ICXQA
const cycleModules = ["sp", "xt", "zv", "lk"];
return 0;
}

function getOriginsForConjections(modules: Conjunction[], map: Map<string, Module>) {
map.forEach((mod) => {
modules.forEach((conjectionModule) => {
const cModulesInModule = mod.destinations.filter((mod) => mod === conjectionModule.id);
if (cModulesInModule.length > 0) {
const cModToUpdate = map.get(conjectionModule.id)! as Conjunction;
cModToUpdate.memory.set(mod.id, false);

map.set(cModToUpdate.id, cModToUpdate);
}
});
});
}
13 changes: 7 additions & 6 deletions Typescript/2023/src/days/day20/day20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Queue } from "data-structure-typed";
import * as fs from "fs";
import { CalculateNeededPresses } from "./Part2";

const isSample = true;
const isSample = false;

export function SolvePartOne(): number {
const fileName = isSample ? "/src/days/day20/sample.txt" : "/src/days/day20/full.txt";
Expand Down Expand Up @@ -106,7 +106,7 @@ class ÜberSystemQueueDispatcherService {
if (signalToProcess === undefined) throw new Error("How did an undefined signal get into the uber system");
this.processSignal(signalToProcess);
}
console.log(`Smashed button ${buttonSmashCount} times.`);
//console.log(`Smashed button ${buttonSmashCount} times.`);
}
}

Expand All @@ -116,13 +116,13 @@ class ÜberSystemQueueDispatcherService {
}

public enQueueSignal(signal: Signal) {
console.log(`Enquing Signal from ${signal.origin} to ${signal.destination} pulse: ${signal.pulse}`);
//console.log(`Enquing Signal from ${signal.origin} to ${signal.destination} pulse: ${signal.pulse}`);
this.buttonPressQueue.enqueue(signal);
signal.pulse ? this.highPulseCount++ : this.lowPulseCount++;
}

pulseProduct(): number {
console.log(`Low count: ${this.lowPulseCount + this.BUTTON_PRESSES} | High count ${this.highPulseCount}`);
//console.log(`Low count: ${this.lowPulseCount + this.BUTTON_PRESSES} | High count ${this.highPulseCount}`);
return (this.lowPulseCount + this.BUTTON_PRESSES) * this.highPulseCount;
}
}
Expand All @@ -135,11 +135,12 @@ class Broadcast implements Module {
public uberSystem: ÜberSystemQueueDispatcherService
) {}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public processSignal(signal: Signal) {
if (this.id === "output") {
console.log(`Output: Received ${signal.pulse} from ${signal.origin}`);
// console.log(`Output: Received ${signal.pulse} from ${signal.origin}`);
} else if (this.id === "rx") {
console.log(`Rx: Received ${signal.pulse} from ${signal.origin}`);
//console.log(`Rx: Received ${signal.pulse} from ${signal.origin}`);
} else {
throw new Error("Should not be reached");
}
Expand Down

0 comments on commit e29e0f8

Please sign in to comment.