A common riddle-like question for programmers asks them to swap the values of two integers without a temporary intermediate value. There are two common solutions that I’m aware of, addition swap and XOR swap. Here’s what each looks like in C:
Tag: math
Shaders provide programmers with a beautiful combination of art and math. Most other throwaway projects are devoid of any artistic value. In less than a dozen lines of code you can draw fractals. A few more and you can start creating intricate animations. The most interesting part is the unique perspective they force you into.
Say you want to draw a circle in an imperative programming language. You need to break out a for loop and calculate the sin and cos of different angles until you have points all around the circumference of a circle.
It’s very common for high-school students to learn the geometry of a circle.
Trigonometric functions (sin()
, cos()
, etc.) are required knowledge for
high-school graduates, and they have a close relationship to circles. This means
that most students have seen the equation for a unit circle: