MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/12tm7rp/we_did_coding_in_physics_class/jh4bcly/?context=3
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.
120 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 1 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? -30 u/eugene2k Apr 21 '23 or may not be available in the language even 42 u/EarhackerWasBanned Apr 21 '23 This looks like Mathematica.https://reference.wolfram.com/language/ref/Floor.htmlIf you can find me a language that doesn’t have a floor function I’ll concede you’re right. No esoterics. 5 u/Frown1044 Apr 21 '23 Does Bash count?(not agreeing with the other person) 32 u/EarhackerWasBanned Apr 21 '23 Sure.#!/usr/bin/env bash python -c "from math import floor;"I leave the rest as an exercise to the reader. 6 u/[deleted] Apr 21 '23 | cut -d'.' -f2 → More replies (0) -4 u/eugene2k Apr 21 '23 awk?But I'd say mathematica itself is plenty esoteric - enough that it's syntax is recognized only by those who use mathematica. 5 u/EarhackerWasBanned Apr 21 '23 I’ve never used Mathematica in my life.
120
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
1 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? -30 u/eugene2k Apr 21 '23 or may not be available in the language even 42 u/EarhackerWasBanned Apr 21 '23 This looks like Mathematica.https://reference.wolfram.com/language/ref/Floor.htmlIf you can find me a language that doesn’t have a floor function I’ll concede you’re right. No esoterics. 5 u/Frown1044 Apr 21 '23 Does Bash count?(not agreeing with the other person) 32 u/EarhackerWasBanned Apr 21 '23 Sure.#!/usr/bin/env bash python -c "from math import floor;"I leave the rest as an exercise to the reader. 6 u/[deleted] Apr 21 '23 | cut -d'.' -f2 → More replies (0) -4 u/eugene2k Apr 21 '23 awk?But I'd say mathematica itself is plenty esoteric - enough that it's syntax is recognized only by those who use mathematica. 5 u/EarhackerWasBanned Apr 21 '23 I’ve never used Mathematica in my life.
1
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? -30 u/eugene2k Apr 21 '23 or may not be available in the language even 42 u/EarhackerWasBanned Apr 21 '23 This looks like Mathematica.https://reference.wolfram.com/language/ref/Floor.htmlIf you can find me a language that doesn’t have a floor function I’ll concede you’re right. No esoterics. 5 u/Frown1044 Apr 21 '23 Does Bash count?(not agreeing with the other person) 32 u/EarhackerWasBanned Apr 21 '23 Sure.#!/usr/bin/env bash python -c "from math import floor;"I leave the rest as an exercise to the reader. 6 u/[deleted] Apr 21 '23 | cut -d'.' -f2 → More replies (0) -4 u/eugene2k Apr 21 '23 awk?But I'd say mathematica itself is plenty esoteric - enough that it's syntax is recognized only by those who use mathematica. 5 u/EarhackerWasBanned Apr 21 '23 I’ve never used Mathematica in my life.
51
“Class, floor is a function that rounds down to the nearest whole number.”
What were the other cons again?
-30 u/eugene2k Apr 21 '23 or may not be available in the language even 42 u/EarhackerWasBanned Apr 21 '23 This looks like Mathematica.https://reference.wolfram.com/language/ref/Floor.htmlIf you can find me a language that doesn’t have a floor function I’ll concede you’re right. No esoterics. 5 u/Frown1044 Apr 21 '23 Does Bash count?(not agreeing with the other person) 32 u/EarhackerWasBanned Apr 21 '23 Sure.#!/usr/bin/env bash python -c "from math import floor;"I leave the rest as an exercise to the reader. 6 u/[deleted] Apr 21 '23 | cut -d'.' -f2 → More replies (0) -4 u/eugene2k Apr 21 '23 awk?But I'd say mathematica itself is plenty esoteric - enough that it's syntax is recognized only by those who use mathematica. 5 u/EarhackerWasBanned Apr 21 '23 I’ve never used Mathematica in my life.
-30
or may not be available in the language even
42 u/EarhackerWasBanned Apr 21 '23 This looks like Mathematica.https://reference.wolfram.com/language/ref/Floor.htmlIf you can find me a language that doesn’t have a floor function I’ll concede you’re right. No esoterics. 5 u/Frown1044 Apr 21 '23 Does Bash count?(not agreeing with the other person) 32 u/EarhackerWasBanned Apr 21 '23 Sure.#!/usr/bin/env bash python -c "from math import floor;"I leave the rest as an exercise to the reader. 6 u/[deleted] Apr 21 '23 | cut -d'.' -f2 → More replies (0) -4 u/eugene2k Apr 21 '23 awk?But I'd say mathematica itself is plenty esoteric - enough that it's syntax is recognized only by those who use mathematica. 5 u/EarhackerWasBanned Apr 21 '23 I’ve never used Mathematica in my life.
42
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.
5 u/Frown1044 Apr 21 '23 Does Bash count?(not agreeing with the other person) 32 u/EarhackerWasBanned Apr 21 '23 Sure.#!/usr/bin/env bash python -c "from math import floor;"I leave the rest as an exercise to the reader. 6 u/[deleted] Apr 21 '23 | cut -d'.' -f2 → More replies (0) -4 u/eugene2k Apr 21 '23 awk?But I'd say mathematica itself is plenty esoteric - enough that it's syntax is recognized only by those who use mathematica. 5 u/EarhackerWasBanned Apr 21 '23 I’ve never used Mathematica in my life.
5
Does Bash count?
(not agreeing with the other person)
32 u/EarhackerWasBanned Apr 21 '23 Sure.#!/usr/bin/env bash python -c "from math import floor;"I leave the rest as an exercise to the reader. 6 u/[deleted] Apr 21 '23 | cut -d'.' -f2 → More replies (0)
32
Sure.
#!/usr/bin/env bash python -c "from math import floor;"
I leave the rest as an exercise to the reader.
6
| cut -d'.' -f2
→ More replies (0)
-4
awk?
But I'd say mathematica itself is plenty esoteric - enough that it's syntax is recognized only by those who use mathematica.
5 u/EarhackerWasBanned Apr 21 '23 I’ve never used Mathematica in my life.
I’ve never used Mathematica in my life.
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.