#AdVENt of Code
1 messages · Page 6 of 1
dont worry it definiletly wont take 25 minutes to do part 2 by brute forcing
dont mind largeness
what..
btw this progress is completely wrong
oh its int64
I couldnt bother fixing it since it wasnt taking so long
okay part 1 was actually easy
do def solve { file }
||
def solve(file)
smallest_location_number = Int64::MAX
lines = File.read_lines(file)
seeds = lines.shift.split(":").last.strip.split(" ").map { |s| s.to_i64 }
did_map = false
seeds.each do |seed|
number = seed
lines.each do |line|
if line.ends_with? "map:"
did_map = false
next
end
next if did_map || line.empty?
dest_range_start, source_range_start, range_length = line.split(" ").map { |s| s.to_i64 }
if number >= source_range_start && number < source_range_start + range_length
number = dest_range_start + (number - source_range_start)
did_map = true
end
end
smallest_location_number = [smallest_location_number, number].min
end
puts file, smallest_location_number
end
||
crystal language server is nonexistent
(part 2 is where the fun begins)
cant tell if im doing it wrong, are you only allowed to apply a map rule once to an element for part one?
dont forget to multithread
parallelism is experimental in crystal.
untruthy!
ok

cargo run -p day05 --release
ty
rustasian
cuz rn im doing || ` lines.each do |rule|
dest, source, range = rule.split(" ").map(&.to_i64)
state = state.map do |x|
if x >= source && x < source + range
x - source + dest
else
x
end
end
end`||
okay brute force time
Wdym
like
for uhh

It goes once per map
lets see how long this takes
seed-to-soil converts it to soil so you then have to move onto the next map
If that's what you meant
fert to water, for 53 it maps to 49 and then 49 to 32 no?
Yeah it's only once
ah
When you apply the map, it's now in a different "category"
what if i threw this on vps and just waited til its done 
||
def solve2(file)
smallest_location_number = Int64::MAX
lines = File.read_lines(file)
seeds = lines.shift.split(":").last.strip.split(" ").map { |s| s.to_i64 }
did_map = false
(0...seeds.size).step(by: 2) do |i|
(seeds[i]..(seeds[i] + seeds[i + 1])).each do |seed|
number = seed
lines.each do |line|
if line.ends_with? "map:"
did_map = false
next
end
next if did_map || line.empty?
dest_range_start, source_range_start, range_length = line.split(" ").map { |s| s.to_i64 }
if number >= source_range_start && number < source_range_start + range_length
number = dest_range_start + (number - source_range_start)
did_map = true
end
end
smallest_location_number = [smallest_location_number, number].min
end
end
puts file, smallest_location_number
end
||
brute force code
my fan is so loud lmao
its just the dumbest synchronous approach
its still running 
what
wrong
its not dumbest
there are people who use arrays
@real hinge rate my bruteforce
i came up with a way to do non brute force
will try that after i see how long brute force took
its still running 11 minutes later
did you nuke overlaps or smthn
is that 1000 seconds
||nah there are none||
@tranquil vapor can i not do that
mine only took 2.5 mins

no its 1 second
HOW
release takes 2.5 minutessss
||instead of looping thru all seeds and getting minimum result, i reverse the mappings and go up the locations from 0 and when i find a result in the seed range i stop||
oh that works
also yes --release made it like 10x faster
oh guh
||but that only works because minimum number is increadibly low||
i should release
BUT I DONT WANNA CANCXEL NOW
okay i built release
running now
||```rs
use std::ops::Range;
struct Step {
source: Range<i64>,
destination: Range<i64>,
}
fn main() {
// part 2
let contents = include_str!("input.txt");
let mut all_steps: Vec<Vec<Step>> = Vec::new();
let mut seeds: Vec<Range<i64>> = Vec::new();
contents.split("\n\n").for_each(|group| {
if let Some((_, group_steps)) = group.split_once('\n') {
let mut steps: Vec<Step> = Vec::new();
group_steps.split('\n').for_each(|step| {
let values: Vec<i64> = step.split(' ').map(|s| s.parse::<i64>().unwrap()).collect();
let [dest_start, source_start, range_len] = values[..] else {
unreachable!()
};
steps.push(Step {
source: source_start..(source_start + range_len),
destination: dest_start..(dest_start + range_len),
});
});
all_steps.push(steps);
} else {
group
.split_once(':')
.unwrap()
.1
.trim()
.split(' ')
.map(|n| n.parse::<i64>().unwrap())
.collect::<Vec<i64>>()
.chunks_exact(2)
.for_each(|seed_range| {
let [min, len] = seed_range else {
unreachable!()
};
seeds.push(*min..(min + len))
});
}
});
let mut reverse_steps: Vec<Vec<Step>> = Vec::new();
for steps in all_steps.iter().rev() {
let mut reverse_step: Vec<Step> = Vec::new();
for step in steps.iter() {
reverse_step.push(Step {
source: step.destination.clone(),
destination: step.source.clone(),
});
}
reverse_steps.push(reverse_step);
}
let mut min = 0i64;
loop {
let mut mapped = min;
for steps in reverse_steps.iter() {
for step in steps {
if step.source.contains(&mapped) {
mapped = mapped - step.source.start + step.destination.start;
break;
}
}
}
if seeds.iter().any(|seed| seed.contains(&mapped)) {
println!("Found min from seed: {}", mapped);
break;
}
min += 1;
}
println!("Min: {}", min);
}
SO LONG
i modified manti's part 2 cus i didnt wanna do from scratch
well i do so many allocations every loop
i should move the parsing to top level
^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D
lmaoo my dumbass was implicitly returning the result
what do end does to a mf
skill issue
REAL
it already did 20%
cracked
holy shit all i did was move the parsing outside of the loop
before i had it parse every map line for every single seed
now i parse it on the top and its so much faster
unsane
allocations sooooo expensive
ok its 90% done
if i multithread the brute force it can be like 20s
LAST SEED RANGE SOOOO LONG
WTF
ok nvm im dumb
end is 20 not 10
im at 14 now
sooooo slow
you're 14 now?
||
def solve2(file)
smallest_location_number = Int64::MAX
lines = File.read_lines(file)
seeds = lines.shift.split(":").last.strip.split(" ").map { |s| s.to_i64 }
mappings = [] of Array(Array(Int64))
curr_chunk = [] of Array(Int64)
lines.skip(1).each do |line|
if line.empty?
mappings << curr_chunk
curr_chunk = [] of Array(Int64)
next
end
next if line.ends_with? "map:"
curr_chunk << line.split(" ").map { |s| s.to_i64 }
end
mappings << curr_chunk
(0...seeds.size).step(by: 2) do |i|
puts i
(seeds[i]..(seeds[i] + seeds[i + 1])).each do |seed|
number = seed
mappings.each do |map|
did_map = false
map.each do |line|
dest_range_start, source_range_start, range_length = line
if number >= source_range_start && number < source_range_start + range_length
number = dest_range_start + (number - source_range_start)
did_map = true
end
end
smallest_location_number = [smallest_location_number, number].min
end
end
end
puts file, smallest_location_number
end
||
part two is killing me i need to optimize sm
18
happy birthday
LMAO
lmao
WHY IS IT TAKING SO LONG FOR LAST RANGE
ven :3
btw are there overlaps in the seeds im too lazy to check
a watched pot never boils
should.t
in my input there were no range overlaps anywhere
nah
how
i used numbers
okay time to implement non brute force 
at least you dont have to wait 5 minutes
since your code takes longer to run than 5
also did you not use example
my idea is: || for each mapping line, check the overlap with the current seed range. then split the existing seed range(s) into 3 new ranges with the overlapping part converted. finally we end up with an array of like a few hundred ranges, then just find the lowest number in these ranges ||
is that good
it was correct on the example
yea im assuming crystal's int32 is signed
so u lsoe a bit
and it cries like waaa waaaa waaa
yep u32 works
yop this is what i did in ts and it took <20ms
wait no
its prob less pain in crysal
||is there not a good NPM package for a js range with unions and subtractions||
I thought of a good solution that isn't brute force while eep, but I don't want to make that shit myself
yeah same
well it has a range class
well it didnt affect me really but
should i start a typescript repo for generating large inputs @proper totem
and add you
lol insane
oh wait no
wait
im so confused
i made it print all numbers that are > Uint32::MAX
and it printed nothing
yet when i tried to parse to u32 it explodes
oh true
oh true
if number >= source_range_start && number < source_range_start + range_length
this line
I finally found one
https://www.npmjs.com/package/rangem
yeahhhh
did u see my range impl
it hurt
crystal ranges actually dont seem to help me in any way
im gonna smash my fucking head
No. I just new it would hurt to implement a range by hand
I am glad to know it is not in fact easy
HORROR
Couldn't you just put
constructor(public min, _length) {
this.length = max(0, _length)
}
And then you wouldn't need so many ternarys to prevent negative lengths ?
i love crystal syntax for typing arrays:
numbers = [] of UInt64
At least it has a type system
kinda, theres still some logic that is being done that isnt just making sure its not negative
||thats true for before tho||
A
you can make parsing seeds shorter
use stop
||
input = File.read("./input.txt")
parts = input.split("\n\n")
seeds, *maps = parts
min_location = Float64::INFINITY
seeds = seeds.split.tap(&.shift).map(&.to_i64)
||
nop
yop
I HATE MATH
you love math
the math sucked i had to l ike
draw 6 different cases
and mentally sanity check them all with my math
i should turn off copilot for this
DEF
AND IT WILL BE SLIGHTLY WRONG
GIOJGIJOSGJIOJIOGE WHY IS THIS SO BRAINFUCK
i could cheat
crystal has binary search on range
that only rly tells you that there is some overlap
not really where it is and how to split it
ohhh true
enjoy pain
i think this is a good start, now we know there is overlap
TRUE
||make sure ur keeping track of if ur ranges are inclusive or exclusive||
real
or is it
OMG MY HEAD IS FRYING
KOPJIKOPFSOADJIKGOHJNDESAIOJFWQAJOIFWAIOJFEHIOUJFGEIOHUGEWHIOUEWGIOHUJEGRIJNOHU
okay i finished my logic
and it ran very fast
but idk if its correct yet xd
its not
the entire code
YES
IM CLOSE I THINKL
OJIK=FJIOFGJIOGJIOJIKOWOKPWIKOPJFJIKOPEFGJOIE
PART 1 SOLVED SUCCESSFULLY
BUT PART 2 IS 0
PLEASE WHY IS IT 0
F
I had similar bug at one point
the reason was I was parsing numbers wrong
my solution works for example but breaks on real
so when numbers were
12 58 24 52
it was doing
12- 70 first
58-72
24-74 etc
middle one isnt supposed to exist
nop wrong
how
0 AGAIN
@steady fog do aoc
nop
@warped dust help
im literally reversing adjectives
when i text things sometimes
rtl is a virus
UIUA BRAINROT
it's not evbn actually rtl like that
u read functions in same direction
ur a stack machine
IJFEIOJGIOEJGJIOPEWIWEFUJJIOEGQFJIKO=PEFGJIOGWEDJIOGEDOJI
I FIXED IT
DO YOU WANNA KNOW THE FIX
- unmapped_ranges.each do |range|
+ unmapped_ranges.clone.each do |range|
IM GONNA KILL YMSEFL NOW
@tranquil vapor
@tranquil vapor help me
my phone is sending 300 telemetry request every second
instagram literally sends events for no reason
rate speed @sullen fiber @real hinge
impressive
did u do range mapping
yeah
loooove
what if you rewrote it in golang now
faster
I dont know why but while reading other peoples aoc codes I feel dumb
I can not undrestand
i even wrote an assert function and spammed assert statements in all branches 
only to fucking realise the issue was mutating the same array i was looping over

its weird that crystal lets you do that
all languages I know explodes when you do that
ConcurrentModificationException blahblhg
ruby lets you do that
crystal
be nice btich
im too dumb to do range split rn
@tranquil vapor
why is the crystal extension useless
the demo gif shows intellisense...
but im not getting any
why every non popular languages langauge server is horrible
I never managed to get vlang language server running too
actually wait I did but it was working extremely slow
lmao
clickbaits on programming languages smh
yeah same xd
its sad that these languages are ruined by bad LSP
yeah
cause i dont wanna use a language that has poor IDE support
i think the language with the best IDE support is typescript
language server is the thing that makes language usable
and java / kotlin
and easy to learn
ruby language server is pretty shit as well
fake
real
WHAT THE FUCK
LOL
is ur logic anything like this https://codeberg.org/Ven/AdventOfCode/src/branch/main/2023/day5/solution.cr#L73-L98
BAD BOT
@burnt light BANGER IDEA FOR HIDDENPHOX
if u send a spoilered link, hiddenphox will spoiler the codeblock
like || https://codeberg.org/Ven/AdventOfCode/src/branch/main/2023/day5/solution.cr#L7 ||
**solution.cr: **Line 7
# ITS SO OVER
theyre pointers
yeah i can implement that real quick
one thing to note
yes
if codeblock contains || it will break
you can put ZWSP between them
yeah true
i mean
maybe u can add a warning
**solution.cr: **Line 7 - ⚠️ zero width spaces have been added to the code
# ITS SO OVER
ye
**solution.cr: **Line 5
# ```
what if discord was good
oh yea the spoiler distracted me let me look
uh not really but kinda
i handle the cases but not as separately as you
but its basically the same yea
||basically i just drew each of the 6 possible cases on paper, and wrote down a formula for each of the 3 ranges (before, mapped, after), and then map mapped and set unmapped to after||
spoilers implemented and breaking codeblocks fixed 
LMWAO
:troley
**solution.cr: **Line 5 - :warning: Zero width spaces present
# ```
bug bug bug bgu
one of thse days the aoc solution will be oriented around whitespace and the presence of that zwsp warning will be a spoiler too
trust
true true

is ur solution easier or more complex than mine
its a lot terser
same complexity
less readable
also apparently my code has a bug but it doesnt affect my answer so fire
NaN
TYPESCRIPT SUCKS
soo false
classes suck in ts
they don't infer types from parent classes or interfaces
it's stupid
that's why vencord and really anything uses definePlugin()
cause that's the only way to get automatic typing in an object declaration
i havent noticed that before because ive only ever seen two cases where they actually handle it really good
which is inheritence, and forcing ur overrides to have the same signature
but this SUCKs
JUST INFER
yes but it doesn't infer
it only enforces
you still need to explicitly specify types and then it goes uhh can't assign to parent
belehe blheble hhleblh eblhlbehljhbe
hegrws
?!?!?!
are typescript devs okay? https://github.com/microsoft/TypeScript/issues/10570#issuecomment-296860943
Currently, this code is OK: for(;;);
if you do let me know and I can add my generator for day 2
okok
I feel like you could make a larger input by just generating more random numbers to put on the seeds line
but ig more mappings would be good too
more seeds would hardly do anything
but like 200.000 mappings would
actually mm
my solution likely would oom on 200k mappings
cause of exponential growth of subranges xd
that'd be interesting
it'd force you to re-join ranges
yea i was gonna add a Range.flatten(Range[]): Range[]
but i DIDNT CARE enough cus i didnt need to
i should check how many ranges I end up at the end
i wonder
cause it really is exponential growth lol
oh thats not too many
kk
if u wanna try my program on ur generated input
just put example.txt and input.txt in the same dir as the binary and run
wait can u run it without those files present and tell me if it leaks my file paths lol
im curious now cause it does for me
oh i htought u were win11
lol yeah
silly
i noticed cause of the stacktrace
i wonder if theres a way to have it strip those things
U can prob just mask it out
congratulations you just found a flaw every compiler seems to make somehow
the filepath leaking?
yop
i'd expect that to be disabled by default in release builds
weird
like in dev builds its very useful but not release

it could just do relative paths or just filenames and still be useful
or not do any paths and not leak information about source code
Same w Julia
I really wanna learn Julia but it's crazy that the lsp has no intellisense support or good type information on hover
yeahh
crystal lsp is basically worthless
it reports errors but thats it xd
0 hover info or intellisense
vee do erlang tomorrow
vencord rewrite in crystal soon
YOP
oh yes i would like my lsp to not function as one
give em a choice for that
leave it as default
😭
i turned it on and switched to https://github.com/elbywan/crystalline
and now its actually usable
you will use the whatsapp erlang lsp
malware
thats terrifying
wheres the whatsapp car
this is much better btw fuck whatsapp https://github.com/erlang-ls/erlang_ls
sane
people will stop putting random languages on codeblocks that just contain documentation
AND ITS WRITTEN IN ERL. AS IT SHOULD
tbh i dont get the obsession with writing everything in the language its for xd
its kinda counter intuitive
cause you're reimplementing the same shit in every language
it'd make much more sense to just steal some other languages LSP and adapt it for ur own lang

exactly rust-analyzer shouldve been written in C
YOP
but the real answer is for interpreted languages its super easy to introspect
hell compiled languages can use part of the compiler to analyze (im p sure rust-analzer does that)
why do bots keep following me on github
my bad
so many followers
insane
blud is not even a contributor here https://github.com/novuhq/novu/
nor is he part of the org
fire
LOL HE MADE THIS SHIT https://www.hacksquad.dev/
well, claims to have anyway
i barely use github how do people find me
we got multiple spammers from this
he is look he made so many changes
😭
took it to the moon 🚀🚀🚀🚀🚀🚀v
get repo with many stars (supposedly)
"i want to help others"
become grifter
so normal
his name is nevo hes totally the guy who invented novu
he doesnt even follow u
did u block
dead ❤️
yes
i hope
LMAO
dunno didnt use
i dont expect them to be rust good but
Macros are methods that receive AST nodes at compile-time and produce code that is pasted into a program
this does sound fire
im gonna learn this so i can code on my phone for AOC
@warped dust rate https://www.cursorless.org/
cant even use it on mobile anyways it doesnt work from just vscode
needs some "talon" program
it looks pretty fire for what it is
voice coding
me personally ima just wait for bmi
too bad zed already stole that slogan
what is stroke
oh lmao
Code at the speed of thought
true
VOICE CODING AT THE SPEED OF THOUGHT
multiplayer code editor FIRE
my brain bad at speaking >~<
dang tho imagine you coding and have intrusive thoughts to delete entire codebase and it just does it
LOL
could definitely just ratelimit the destructive things also you'd prob have undo buffer still
zed looks like it might be good
crdt?
what the hell i read this already i straight up just forgot
true true
there was another good post i read somewhere abt actually implementing a crdt
in rust ofc
ok i think i made a good day 5 generator
@proper totem do you have a fast day 5 impl
this is vim with mnemonics
fire
yeah except no movement (cursorless du
i mean it just reminded me of that
and theres plugins that map positions to specific letters
Welcome to Cursorless! You may find it helpful to start with the tutorial videos.
HOW
cursorful
mine fast
mine will be faster
just to make sure we get the same answer
ohh
and that im not generating things wrong
mine is the fastest it runs in 0 nanosecnods
nah im not on pc rn im in bed
i think its right but blehg
but I sent binary above u can try
HOW
or just build from source I think they have crystal for windows now
virusware
LMAO
im using crystal
virtual crystal
soon
crystal but interpreted
insane
there are no real interpreted languages other than ones for the BEAM
rini biggest beam fan
the BEAM is the one and only vm
jvm
quit saying BEAM
GOOD
the BEAM
very good language
YEAH LOL
soo bad
yop
im still on part 1
btw switch to https://github.com/elbywan/crystalline
okay
download then change crystal server to the crystalline binary
i wil do
godo
you will die for it
ok fixed i think
this looks like it works
there is one difference i see but idc really
trying out cobol this is insanity
fancy
insanity
death
banger
you love
languages that have all caps my beloved
yop
oop
scary
i will do once I have large input capable solver
how many ranges do you end up with
is that something you're able to see
record Guh, dest_start : Int32, source_start : Int32, length : Int32 beautiful
yea my ts solution doesnt merge ranges so i can check
this person's rust solution does so i can check theirs too
@sullen fiber vaporized
oh wow this isnt even bad
oh that's pretty good
scary
humidity_to_location: [Guh(@dest_start=60, @source_start=56, @length=37), Guh(@dest_start=56, @source_start=93, @length=4)]

guh i just spilled hydrochloric acid all over me
@proper totem ok im gonna add u to the repo now
what language
I get 50s with python which I'm pretty happy with
i will stay awake but to play fnv
never going to be as fast at typescript lol
friday night vunkin
game of humanity's history
guhhhh
i played fallout 3 more
do any of you do crystal
rn my uncle is obsessed with f76
crystal lang i mean
f3 sucks from what i hear
i wouldnt know i was a child with no standards
@warped dust repo init -u https://android.googlesource.com/platform/manifest -b main
nO
i should play flaout new vega
u will
i would probably actually enjoy it
is there multiplayer mods
I end up with 7213 ranges in part 2
steam and gog version ONLY
i got it on sale
lemme check how many i end up with
smh
idk if mp works well actually cuz decisions matter a lot
i found limitation of crystal
@instance_vars are not yet allowed in metaclasses: use @@class_vars instead
sob
the best decision is to kill the quest character btw
aka myself
wt,f
this 'initialize' doesn't explicitly initialize instance variable '@dest_start' of Guh, rendering it nilable
The instance variable '@dest_start' is initialized in other 'initialize' methods,
and by not initializing it here it's not clear if the variable is supposed
to be nilable or if this is a mistake.
To fix this error, either assign nil to it here:
@dest_start = nil
Or declare it as nilable outside at the type level:
hhghh
ohhh true
ok im using a struct
you can kill like literally anyone and the quests just change to fix it
kills your rini
i freed this guy from hostage under premise he'd give me info and he just said nope im running away
promptly i shot him
and turns out i needed him alive but its fine either way
"A Soul of Fallen Worlds - Ruined America"
is this what they call the game in russia
true
oh no its a mod
wtf
@warped dust whats the best way to like
make these available
github releases?
@sullen fiber help
@dst_range = (dst_start..(dst_start + length)).to_a
@src_range = (src_start..(src_start + length)).to_a
am i understanding the ranges right?
Guh(@dst_start=56, @src_start=93, @length=4, @dst_range=[56, 57, 58, 59, 60], @src_range=[93, 94, 95, 96, 97])]
heres one
uh is that crystal
yes
i mean they're random right
i think a..b is [a, b] inclusive
you're probably better off commiting them
okay
oh is it constant
pseudo random implies seeding so i thought u were seeding it w time
fisher yates
yea i meant like
i meant seeded not psuedo random
do i foreach seed in seeds
1
idk this is all so worded weird
u will do an actual pseudorandom algo instead of hashing each step
word problems hard
i was gonna but like
then call order would matter
and yea i prob wont change call order without altering the output but
just in case ig idk
dissolves you
nop
yop
rini will get struck by lightning
crashed my browser
opening large?
yoap
huge
(it just took long to load
its not making sense to me
why the fuck does github even render it
2mb it must
vap help
what part
all
how do i get the new value
i got that
u did the ranges right i think
seed 79 goes in
u find either 1 or 0 lines that maps it
if it falls in the source range add destStart - sourceStart
if there are no lines that map it it stays the same
im trying to think of a visualization
i need to iterate through my ranges right
52 50 48```
yea u need to find which one actually maps the seed
so only one will map it?
or none
there are no overlapping ranges if that helps
the final value should be the location right
yea
cause i think i could do a min
ya def
final_location = seeds.min_by do |seed|
location = seed
seed_to_soil.each do |range|
end
soil_to_fertilizer.each do |range|
end
fertilizer_to_water.each do |range|
end
water_to_light.each do |range|
end
light_to_temperature.each do |range|
end
temperature_to_humidity.each do |range|
end
humidity_to_location.each do |range|
end
location
end
``` @sullen fiber so something like this
oh
but yea
i could make a common inteface or something
@sullen fiber Improved my time in python on the big input part 2 to 96.1 ms
I'm mostly improving it by just getting rid of useless iterations
cause my loops were not optimized
also 96.1 is kinda fake cause i'm benchmarking it after parsing
is there music
no the installer was silent sadly
pheonix is just like some kinda unpacker
for some old disc game format
i think
@sullen fiber its mapping the example correctly
it shouldnt be 13 though
i migth be using min_by wrong
yea thats right but yea itd be 35
oh i see
min_of is the one i needed
Unhandled exception: Invalid Int32: "2531594804" (ArgumentError)
funny overflow
optimized python solution: https://github.com/alchzh/advent-of-code/blob/master/2023/5/day5.ipynb
hmm i'm not taking advantage of the non-overlapping mapping ranges very well even with the binary search
there should be some smart iteration to avoid that entirely
oh well
PYTHON NOTEBOOK
what about it
i think i did something wrong




