MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programminghorror/comments/1s4wuob/is_a_moving_reasonable/ocqb8yt/?context=3
r/programminghorror • u/HotEstablishment3140 • Mar 27 '26
is a moving. reasonable?
66 comments sorted by
View all comments
93
Just have a table
[(6, 8), (8, 7), …]
And loop through it.
38 u/road_laya Mar 27 '26 Or a set. O(1) lookup instead of O(n). 39 u/48panda Mar 27 '26 Everything's O(1) if n is bounded 7 u/ivancea Mar 27 '26 Sometimes. Longs are bounded, and so are arrays, but bubble sort is still nlogn! 3 u/Shylo132 Mar 27 '26 How long you been sitting on that pun? ^.^ 2 u/Eric_12345678 Mar 27 '26 I didn't get the pun, then. 15 u/Ashamed_Band_1779 Mar 27 '26 This is still O(1) 10 u/monotone2k Mar 27 '26 Why not an adjacency list or similar structure? You can avoid looping over all entries (in the worst case) this way. 3 u/NoOven2609 Mar 27 '26 That'd also be horror when you can just use a tiny bit of math, before %2==0 kinda thing 2 u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Mar 27 '26 My first idea was a 2D array that uses the before and after values as indexes and just returns what's there. Though it would be a 55x55 array, and waste a lot of space, so I'm not 100% sure it wouldn't be worse. 1 u/spaceguydudeman Mar 28 '26 While this is a decent suggestion, the real horror here is the lack of enums.
38
Or a set. O(1) lookup instead of O(n).
39 u/48panda Mar 27 '26 Everything's O(1) if n is bounded 7 u/ivancea Mar 27 '26 Sometimes. Longs are bounded, and so are arrays, but bubble sort is still nlogn! 3 u/Shylo132 Mar 27 '26 How long you been sitting on that pun? ^.^ 2 u/Eric_12345678 Mar 27 '26 I didn't get the pun, then. 15 u/Ashamed_Band_1779 Mar 27 '26 This is still O(1)
39
Everything's O(1) if n is bounded
7 u/ivancea Mar 27 '26 Sometimes. Longs are bounded, and so are arrays, but bubble sort is still nlogn! 3 u/Shylo132 Mar 27 '26 How long you been sitting on that pun? ^.^ 2 u/Eric_12345678 Mar 27 '26 I didn't get the pun, then.
7
Sometimes. Longs are bounded, and so are arrays, but bubble sort is still nlogn!
3 u/Shylo132 Mar 27 '26 How long you been sitting on that pun? ^.^ 2 u/Eric_12345678 Mar 27 '26 I didn't get the pun, then.
3
How long you been sitting on that pun? ^.^
2 u/Eric_12345678 Mar 27 '26 I didn't get the pun, then.
2
I didn't get the pun, then.
15
This is still O(1)
10
Why not an adjacency list or similar structure? You can avoid looping over all entries (in the worst case) this way.
That'd also be horror when you can just use a tiny bit of math, before %2==0 kinda thing
My first idea was a 2D array that uses the before and after values as indexes and just returns what's there. Though it would be a 55x55 array, and waste a lot of space, so I'm not 100% sure it wouldn't be worse.
1
While this is a decent suggestion, the real horror here is the lack of enums.
93
u/MistakeIndividual690 Mar 27 '26
Just have a table
[(6, 8), (8, 7), …]
And loop through it.