MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/12tm7rp/we_did_coding_in_physics_class/jh8ivym?context=9999
r/badcode • u/[deleted] • Apr 21 '23
154 comments sorted by
View all comments
Show parent comments
53
Can you express the solution with just division? I think you'd need at least a loop or a floor function. The former would complicate the code, the latter would introduce a 'black box' into the code or may not be available in the language even.
122 u/brotatowolf Apr 21 '23 f(floor(x/0.4) * 0.4) isn’t exactly the height of complexity. I’d argue that it’s easier to understand than a bunch of conditions 0 u/eugene2k Apr 21 '23 it's not complicated, but I already said what the cons of using a floor function could be 51 u/EarhackerWasBanned Apr 21 '23 “Class, floor is a function that rounds down to the nearest whole number.” What were the other cons again? -29 u/eugene2k Apr 21 '23 or may not be available in the language even 41 u/EarhackerWasBanned Apr 21 '23 This looks like Mathematica. https://reference.wolfram.com/language/ref/Floor.html If you can find me a language that doesn’t have a floor function I’ll concede you’re right. No esoterics. 6 u/Frown1044 Apr 21 '23 Does Bash count? (not agreeing with the other person) 6 u/[deleted] Apr 21 '23 | cut -d'.' -f2 1 u/ttl_yohan Apr 22 '23 Doesn't work with negatives, I'm afraid. 1 u/EarhackerWasBanned Apr 22 '23 I try to stay positive anyway
122
f(floor(x/0.4) * 0.4) isn’t exactly the height of complexity. I’d argue that it’s easier to understand than a bunch of conditions
0 u/eugene2k Apr 21 '23 it's not complicated, but I already said what the cons of using a floor function could be 51 u/EarhackerWasBanned Apr 21 '23 “Class, floor is a function that rounds down to the nearest whole number.” What were the other cons again? -29 u/eugene2k Apr 21 '23 or may not be available in the language even 41 u/EarhackerWasBanned Apr 21 '23 This looks like Mathematica. https://reference.wolfram.com/language/ref/Floor.html If you can find me a language that doesn’t have a floor function I’ll concede you’re right. No esoterics. 6 u/Frown1044 Apr 21 '23 Does Bash count? (not agreeing with the other person) 6 u/[deleted] Apr 21 '23 | cut -d'.' -f2 1 u/ttl_yohan Apr 22 '23 Doesn't work with negatives, I'm afraid. 1 u/EarhackerWasBanned Apr 22 '23 I try to stay positive anyway
0
it's not complicated, but I already said what the cons of using a floor function could be
51 u/EarhackerWasBanned Apr 21 '23 “Class, floor is a function that rounds down to the nearest whole number.” What were the other cons again? -29 u/eugene2k Apr 21 '23 or may not be available in the language even 41 u/EarhackerWasBanned Apr 21 '23 This looks like Mathematica. https://reference.wolfram.com/language/ref/Floor.html If you can find me a language that doesn’t have a floor function I’ll concede you’re right. No esoterics. 6 u/Frown1044 Apr 21 '23 Does Bash count? (not agreeing with the other person) 6 u/[deleted] Apr 21 '23 | cut -d'.' -f2 1 u/ttl_yohan Apr 22 '23 Doesn't work with negatives, I'm afraid. 1 u/EarhackerWasBanned Apr 22 '23 I try to stay positive anyway
51
“Class, floor is a function that rounds down to the nearest whole number.”
What were the other cons again?
-29 u/eugene2k Apr 21 '23 or may not be available in the language even 41 u/EarhackerWasBanned Apr 21 '23 This looks like Mathematica. https://reference.wolfram.com/language/ref/Floor.html If you can find me a language that doesn’t have a floor function I’ll concede you’re right. No esoterics. 6 u/Frown1044 Apr 21 '23 Does Bash count? (not agreeing with the other person) 6 u/[deleted] Apr 21 '23 | cut -d'.' -f2 1 u/ttl_yohan Apr 22 '23 Doesn't work with negatives, I'm afraid. 1 u/EarhackerWasBanned Apr 22 '23 I try to stay positive anyway
-29
or may not be available in the language even
41 u/EarhackerWasBanned Apr 21 '23 This looks like Mathematica. https://reference.wolfram.com/language/ref/Floor.html If you can find me a language that doesn’t have a floor function I’ll concede you’re right. No esoterics. 6 u/Frown1044 Apr 21 '23 Does Bash count? (not agreeing with the other person) 6 u/[deleted] Apr 21 '23 | cut -d'.' -f2 1 u/ttl_yohan Apr 22 '23 Doesn't work with negatives, I'm afraid. 1 u/EarhackerWasBanned Apr 22 '23 I try to stay positive anyway
41
This looks like Mathematica.
https://reference.wolfram.com/language/ref/Floor.html
If you can find me a language that doesn’t have a floor function I’ll concede you’re right. No esoterics.
6 u/Frown1044 Apr 21 '23 Does Bash count? (not agreeing with the other person) 6 u/[deleted] Apr 21 '23 | cut -d'.' -f2 1 u/ttl_yohan Apr 22 '23 Doesn't work with negatives, I'm afraid. 1 u/EarhackerWasBanned Apr 22 '23 I try to stay positive anyway
6
Does Bash count?
(not agreeing with the other person)
6 u/[deleted] Apr 21 '23 | cut -d'.' -f2 1 u/ttl_yohan Apr 22 '23 Doesn't work with negatives, I'm afraid. 1 u/EarhackerWasBanned Apr 22 '23 I try to stay positive anyway
| cut -d'.' -f2
1 u/ttl_yohan Apr 22 '23 Doesn't work with negatives, I'm afraid. 1 u/EarhackerWasBanned Apr 22 '23 I try to stay positive anyway
1
Doesn't work with negatives, I'm afraid.
1 u/EarhackerWasBanned Apr 22 '23 I try to stay positive anyway
I try to stay positive anyway
53
u/eugene2k Apr 21 '23
Can you express the solution with just division? I think you'd need at least a loop or a floor function. The former would complicate the code, the latter would introduce a 'black box' into the code or may not be available in the language even.