We use cookies to personalise content and advertisements and to analyse access to our website. Furthermore, our partners for online advertising receive pseudonymised information about your use of our website. cookie policy and privacy policy.
 
+0  
 
0
54
0
avatar+20 

I think everybody knows this puzzle.

We just count the circles in numbers.

 

Let's try to solve this puzzle using math.

Using the table data

We need a table that contains the number of zeroes of every digit.

xy
01
10
20
30
40
50
61
70
82
91

 

y = [1, 0, 0, 0, 0, 0, 1, 0, 2, 1]

 

Using summation and the table above, we just sum up circles of every digit of the number.

Here's the formula:

\(f\left(x\right)=\sum_{n=0}^{\lfloor\log_{10}x\rfloor}y\left[\Bigl\lfloor\frac{x}{10^{n}}\Bigr\rfloor\operatorname{mod}10+1\right]\)

 

\(\left\lfloor\frac{x}{10^n}\right\rfloor\) can be written as \(\lfloor10^{-n}x\rfloor\)

\(\left\lfloor\frac{x}{10^n}\right\rfloor=\lfloor10^{-n}x\rfloor\)

 

Hence

\(f\left(x\right)=\sum_{n=0}^{\lfloor\log_{10}x\rfloor}y\left[\lfloor10^{-n}x\rfloor\operatorname{mod}10+1\right]\)

Without the table

y of the table from the previous formula can be replaced with the if-else statement. If x=0 or 6 or 9 return 1, if x=8 return 2.

In math, the if-else statement can be written as follows:

(condition)(true-false)+false

Where the condition is 0 or 1,

true - returning value if the condition is 1,

false - returning value if the condition is 0.

 

To check if two numbers are equal, we can use the following formula:

\(eq(x,y)=1-|\operatorname{sign}(x-y)|\)

 

Here's the if-else statement that replaces y of the table

\(t\left(x\right)=\left(eq\left(x,0\right)+eq\left(x,6\right)+eq\left(x,9\right)\right)\left(1-2eq\left(x,8\right)\right)+eq\left(x,8\right)\)

 

As I said, y of the table can be replaced with the if-else statement, so the formula (without table) will look like the formula (using table data), but with y[...+1] replaced by t(...)

\(f\left(x\right)=\sum_{n=0}^{\lfloor\log_{10}x\rfloor}t\left(\lfloor10^{-n}x\rfloor\operatorname{mod}10\right)\)

 

Look at this in Desmos: https://www.desmos.com/calculator/ivopfgdddk​

off-topic
 Oct 19, 2019
edited by JoshuaGreen  Oct 19, 2019
edited by JoshuaGreen  Oct 22, 2019
edited by JoshuaGreen  Oct 23, 2019
edited by JoshuaGreen  Oct 23, 2019
edited by JoshuaGreen  Oct 23, 2019

32 Online Users

avatar
avatar