Skip to main content

Tag: math

Why Doesn’t The Simple Formula Work?

Problem: Write a program to find sum of all multiples of 3 and 5 upto input n. If a number is multiple of both 3 and 5 add it only once. We were given this problem at work. I tried to “solve” it using math. Clearly, we can add all the multiples of 3 and 5 upto n and subtract multiples of 15 once to account for the overcounting. We could derive formula for this as follows:

Using Complex Numbers to Move Mars Rover

Recently I was given Mars Rover Problem and told that my solution was pretty cool. Before that I assumed this is how everybody else was doing it ;). Here is golang implementation. Enjoy! Design Position and orientation are represented as complex numbers implemented as type vect. Builtin complex type is not used because it uses floats which they can’t be compared easily. In calculations below $j = \sqrt{-1}$. Multiplication of complex numbers allow us to rotate.