Rating:

# Keep Calculating

![Keep Calculating](https://raw.githubusercontent.com/bsempir0x65/CTF_Writeups/main/KnightCTF_2022/img/KnightCTF_Keep_Calculating.png)

With the Programming tasks we had some issues cause it was not quite clear how the functions needs to be implemented. So for example when you take the task here based on the math x would never change so how do you reach 666 ? Regardless of this issue our Math Magicians ![magic](https://github.githubassets.com/images/icons/emoji/unicode/1fa84.png) solved the task with no issues. Hope this little neat code can also help you.

```python
def f(x, y):
if y != 0:
a = math.floor(math.log10(y))
else:
a = -1

return int(x*10**(1+a)+y)

def calc(a, x, y):
a += (x * y) + f(x, y)
print("X: ", x, " A: ", a)
if x > 666:
print("Doooooop")
return "wrong"
if x != 666:
x += 1
calc(a, x, y)
return
if x == 666:
print("X: ", x, " A: ", a)
print("correct")
return "finished"

x = 1
y = 2
a = 0
print(f(1,2))
calc(a, x, y)
```

P.S: Yes the import is missing and the flag is *KCTF{2666664}*

Our [github](https://github.com/bsempir0x65/CTF_Writeups/tree/main/KnightCTF_2022#keep-calculating) and [webpage](https://bsempir0x65.github.io/CTF_Writeups/KnightCTF_2022/#keep-calculating)

Original writeup (https://github.com/bsempir0x65/CTF_Writeups/tree/main/KnightCTF_2022#keep-calculating).