Compare commits
4
Commits
afb9849c3c
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b1cda63b1 | ||
|
|
75d5cb8943 | ||
|
|
2dd97d116f | ||
|
|
ee6e32dd3d |
No files matched your search
@@ -257,6 +257,7 @@ for (const pair of seedsPairs) {
|
|||||||
const loc = getMapResult(hum, humidityToLocation);
|
const loc = getMapResult(hum, humidityToLocation);
|
||||||
if (loc < minimalLocation) minimalLocation = loc;
|
if (loc < minimalLocation) minimalLocation = loc;
|
||||||
}
|
}
|
||||||
|
console.log("minimalLocation: ", minimalLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(minimalLocation);
|
console.log(minimalLocation);
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
type Race = {
|
||||||
|
time: number;
|
||||||
|
distance: number;
|
||||||
|
};
|
||||||
|
const races: Race[] = [];
|
||||||
|
|
||||||
|
const timeFrom = new Date().getTime();
|
||||||
|
|
||||||
|
// const input = `Time: 47 70 75 66
|
||||||
|
// Distance: 282 1079 1147 1062`.split("\n");
|
||||||
|
|
||||||
|
const input = `Time: 47707566
|
||||||
|
Distance: 282107911471062`.split("\n");
|
||||||
|
|
||||||
|
// parse input
|
||||||
|
const [t, ...rtimes] = input[0].split(" ");
|
||||||
|
const times = rtimes.filter((o) => o !== "").map((o) => Number(o));
|
||||||
|
const [d, ...rdist] = input[1].split(" ");
|
||||||
|
const dist = rdist.filter((o) => o !== "").map((o) => Number(o));
|
||||||
|
|
||||||
|
let mul = 1;
|
||||||
|
|
||||||
|
for (let i = 0; i < times.length; i++) {
|
||||||
|
races.push({ time: times[i], distance: dist[i] });
|
||||||
|
}
|
||||||
|
console.log(races);
|
||||||
|
|
||||||
|
function getDistance(race: Race, holdTime: number): number {
|
||||||
|
return (race.time - holdTime) * holdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const race of races) {
|
||||||
|
let from = 1;
|
||||||
|
let to = 1;
|
||||||
|
for (let i = 0; i < race.time; i++) {
|
||||||
|
if (getDistance(race, i) > race.distance) {
|
||||||
|
from = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let i = race.time; i >= 0; i--) {
|
||||||
|
if (getDistance(race, i) > race.distance) {
|
||||||
|
to = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mul *= to - from + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(mul);
|
||||||
|
|
||||||
|
const timeTotal = new Date().getTime() - timeFrom;
|
||||||
|
console.log(`Time took: ${timeTotal}ms`);
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
pico-8 cartridge // http://www.pico-8.com
|
||||||
|
version 41
|
||||||
|
__lua__
|
||||||
|
|
||||||
|
local races = {
|
||||||
|
{ 7, 9 },
|
||||||
|
{ 15, 40 },
|
||||||
|
{ 30, 200 }
|
||||||
|
}
|
||||||
|
|
||||||
|
printh("")
|
||||||
|
printh("aoc 2023 6")
|
||||||
|
printh("")
|
||||||
|
|
||||||
|
function get_dist(race, t)
|
||||||
|
return (race[1] - t) * t
|
||||||
|
end
|
||||||
|
|
||||||
|
function trace()
|
||||||
|
line(1, 126, 127, 126, 13)
|
||||||
|
line(1, 126, 1, 1, 13)
|
||||||
|
print("distance", 3, 1, 8)
|
||||||
|
local x, y
|
||||||
|
for race in all(races) do
|
||||||
|
local md = 0 ym = 0 xm = 0 bt = 0 pd = 0
|
||||||
|
line(2, 126 - race[2] / 2, 127, 126 - race[2] / 2, 2)
|
||||||
|
print("time", 80, 114, 15)
|
||||||
|
print("pressed", 80, 121, 15)
|
||||||
|
line()
|
||||||
|
for i = 0, race[1] do
|
||||||
|
local dist = get_dist(race, i)
|
||||||
|
x = 1 + i * 4
|
||||||
|
y = 126 - dist / 2
|
||||||
|
if dist > md then
|
||||||
|
md = dist xm = x ym = y
|
||||||
|
end
|
||||||
|
line(x, y, 7)
|
||||||
|
yield()
|
||||||
|
if pd > dist and bt == 0 then bt = i - 1 end
|
||||||
|
pd = dist
|
||||||
|
end
|
||||||
|
print(md .. "MM", xm - 2, ym - 6, 8)
|
||||||
|
print(bt .. "MS", xm + 20, ym - 6, 15)
|
||||||
|
-- print(race[2],50,126-race[2]/2-6,2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local co = cocreate(trace)
|
||||||
|
|
||||||
|
cls()
|
||||||
|
|
||||||
|
function _update()
|
||||||
|
coresume(co)
|
||||||
|
end
|
||||||
|
|
||||||
|
__gfx__
|
||||||
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
Reference in new issue
Block a user