**New here?**Learn about Bountify and follow @bountify to get notified of new bounties! Follow @bountify x

I believe the code that was written by "Vyacheslav Sokolov" in Python (File: xyz2code.py) at cubicpostcode.com has some serious bugs. The file was converted to javascript at: https://cubicpostcode.github.io/calc/3xyz2cube.html may have some serious bugs. Test it and find some serious bugs or limitations and you will be eligible to win this bounty. Also your name and github account will be featured on this project website, if you wish so.

Only for the serious geek that wants to help this project to be 100% to trust and free of any bugs.

You may win the bounty if you are a serious geek that discovers serious bugs and problems with the project and website.

## 1 Solution

Hello!

The first bug at https://cubicpostcode.github.io/calc/3xyz2cube.html is in function max(...): in the script it takes 3 arguments but in fact it's called with four. So if you'll remove

```
function max(v1, v2, v3) {
let m = v1;
if (v2 > m)
m = v2;
if (v3 > m)
m = v3;
return m;
}
```

and replace

```
var square_number = max(y + 1, z + 1, -y, -z)
```

with

```
var square_number = Math.max(y + 1, z + 1, -y, -z)
```

the bug will be fixed.

Another two problems are in the end of the script where "code" is calculated. First, the precision of a Number in Javascript is not enough to hold 22 exact decimal digits, so the last digits in the resulting code are likely to be wrong (this problem doesn't exist in Python); second, there should be exactly 22 digits in the code, i.e. smaller code should be left-p-added with zeros which the script currently doesn't do. The first problem can be solved by dividing the code into two parts that contain much less than 22 digits; the second one is solved by the follopwing function.

All the end of the script starting from the line I commented can be replaced with this fragment:

```
// var code = slice_number * 441000000000000 + cube_p
function pad(x, n) {
var s = "000000000000" + x;
return s.substr(s.length - n);
}
var c1 = pad(Math.floor(slice_number * 441 + cube_p * 1e-12), 10)
var c2 = pad(cube_p % 1e12, 12)
var code = c1 + "" + c2
document.getElementById('cube-code').innerHTML = code;
```

`var c1 = pad(parseInt(slice_number * 441 + cube_p * 1e-12), 10)`

parseInt must be replaced with Math.floor.`coord_round(x)`

function can be replaced with one line:`return Math.floor(x)`

though the current function works too.