If you mean graph coloring restricted to planar graphs, yes it can always be done with at most 4 colors. But it could still be less, so the answer is not always the same.
(I know it was probably not a very serious comment but I just wanted to infodump about graph theory.)
This kind of optimization, complete loop removal and computing the final value for simple math loops, is at least 10 years old.
https://github.com/llvm/llvm-project/blob/release/21.x/llvm/...
mgaunard•2h ago
The sum of integers is actually a question I ask developers in interviews (works well from juniors to seniors), with the extra problem of what happens if we were to use floating-point instead of integers.
bayesnet•1h ago
zipy124•1h ago
bayesnet•1h ago
dist-epoch•38m ago
ramraj07•1h ago
I know compilers can do some crazy optimizations but wouldn't have guessed it'll transform something from O(n) to O(1). Having said that, I dont still feel this has too much relevance to my actual job for the most part. Such performance knowledge seems to be very abstracted away from actual programming by database systems, or managed offerings like spark and snowflake, that unless you intend to work on these systems this knowledge isn't that useful (being aware they happen can be though, for sure).
scuff3d•1h ago
This kind of question is entirely useless in an interview. It's just a random bit of trivia that either a potential hire happen to have come across, or happens to remember from math class.
yeasku•42m ago
nickysielicki•7m ago
Anyone who dumbly suggests that loops in source code will always result in loops in assembly doesn’t have a clue. Anyone who throws their hands up and says, “I have no idea, but I wonder if there’s some loop invariant or algebraic trick that can be used to optimize this, let’s think about it out loud for a bit” has taken a compiler class and gets full marks. Anyone who says, “I dunno, let’s see what godbolt does and look through the llvm-opt pane” gets an explicit, “hire this one” in the feedback to the hiring manager.
It’s less about what they know and more about if they can find out.
zipy124•1h ago
Also this series is targeted towards more of a beginner audience to compilers, thus its likely to be suprising to the audience, even if not to you.
yeasku•1h ago
For you are essentials.
You and the juniors you hire must have a deeper knoledge than him.
porise•1h ago
I spend a lot of time looking at generated assembly and there are some more impressive ones.
yeasku•1h ago
It would be great if you shared it with the world like Matt does instead of being smug about it.
xandrius•1h ago
hypeatei•1h ago
cratermoon•56m ago
phh•13m ago
f1shy•10m ago
Maybe you have much more experience than Mr Godbolt in compiliers.