Last one should be // still a student
Programmer Humor
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
Every single entry other than thief is "still a student"
@coja I am the engineer because I forget about Math.max existence
Engineer likely ends up with the smallest code. Though the hit to execution time for a branch sucks. (Pipelines and such)
Bit hacker will take the least execution time because of pipelines, but it needs more comments. Maybe something like // trust me, this works.
What about the smooth approximation nerd?
import math
def max12(x, y, alpha=10):
u = math.exp(alpha * x)
v = math.exp(alpha * y)
return (u * x + v * y) / (u + v)
(obviously beware of overflows)
I use 8, but only when I'm operating on unsigned longs.
here’s another mathematical approach (that has the added benefit of only working when x and y are both positive).
let f denote the linear functional on ℝ^2^ defined by f(1,0) = x and f(0,1) = y (and extend by linearity). then the operator norm || f || is equal to max(x,y).
I'm mostly lost and in over my head
Yoink.
Actually I've probably been all of these at various times in my career.
Why use
const max = (x, y) => x > y ? x : y
instead of
function max(x, y) { return x > y ? x : y }
?
2, but I'm incredibly embarrassed to say that I've had to do 9 before
my $max = $x > $y ? $x : $y;