Post #2993833
2026-01-19 12:26 UTC
@MxVerda@lgbtqia.space @johnnythan@tuebingen.network @ArchiteuthisFlux@leds.social Oh right!
Dear gods. When I said I'd done it in BASIC and Fortran, that's a clue to how long ago it was.
Replies (1)
-
@lproven@social.vivaldi.net 2026-01-19 12:26
@MxVerda@lgbtqia.space @johnnythan@tuebingen.network @ArchiteuthisFlux@leds.social Google failed me. Here is some pseudocode: Variables bug location x, y food location x, y 100x100 grid Bug location x = rnd * 100 Bug location y = rnd * 100 Calculate distance from bug to food, using Pythagoras https://byjus.com/maths/distance-formula/ The faint smell excites the bug: the _more_ excited the bug, the _slower_ it moves. More excitement = shorter stride Stride = 1/distance Search: Pick a random direction Move 1 stride that direction Sniff Calculate new stride length: if the smell is stronger, move shorter If bug(x,y) = food(x,y) exit Otherwise, go search End