countdown calc
-
- Forum Admin
- Posts: 496
- Joined: Sat May 28, 2011 9:14 am
- Location: Germany
I did this one even more lazy...
i googled the first 10 output values to see if it could be a more or less known sequence, but instead of that I accidently found the already decompiled c#-code at ideone.com
So i changed it to just "calculate" the last value, compiled it again and let it run. Lazy but effective
i googled the first 10 output values to see if it could be a more or less known sequence, but instead of that I accidently found the already decompiled c#-code at ideone.com
So i changed it to just "calculate" the last value, compiled it again and let it run. Lazy but effective
-
- Posts: 1
- Joined: Wed Aug 03, 2011 12:01 am
def calc(num):
num2 = 5
num2 = num2*10+(num2+1)*(num-10)
num2 = num2*10+(num2+num)*(num-10)
num2 = num2*10+(num2+num*num)*(num-10)
num2 = num2*10+(num2+num*num*num)*(num-10)
num2 = num2*10 + (num2+num*num*num*num)*(num-10)
num2 = (num2 + 16*num*num*num*num*num)
num2 &=0xffffffff
print(num2)
calc(99)
num2 = 5
num2 = num2*10+(num2+1)*(num-10)
num2 = num2*10+(num2+num)*(num-10)
num2 = num2*10+(num2+num*num)*(num-10)
num2 = num2*10+(num2+num*num*num)*(num-10)
num2 = num2*10 + (num2+num*num*num*num)*(num-10)
num2 = (num2 + 16*num*num*num*num*num)
num2 &=0xffffffff
print(num2)
calc(99)
-
- Posts: 3
- Joined: Tue Jun 28, 2011 12:37 pm
- Location: Germany
Code: Select all
#include <iostream>
// integer length
const unsigned int il(unsigned int AValue)
{
unsigned int c = 0;
do
{
AValue /= 10;
c++;
}
while(AValue);
return c;
}
int calc(int num)
{
int num1 = 0;
unsigned short int v[100];
for (int index1 = 0; index1 < num; ++index1)
{
v[index1] = il(index1);
}
for (int index1 = 0; index1 < num; ++index1)
{
for (int index2 = 0; index2 < num; ++index2)
{
for (int index3 = 0; index3 < num; ++index3)
{
for (int index4 = 0; index4 < num; ++index4)
{
for (int index5 = 0; index5 < num; ++index5)
{
num1 += v[index1] + v[index2] + v[index3] + v[index4] + v[index5] + 16;
}
}
}
}
}
return num1;
}
int main(int ac, char** av)
{
std::cout << "calculating..." << std::endl;
int num = 99;
for (int index = num; index >= 0; --index)
{
std::cout << index << std::endl;
std::cout << "val: " << calc(num - index) << std::endl;
}
return 0;
}
Code: Select all
$ grep "model name" /proc/cpuinfo | uniq
model name : Intel(R) Core(TM)2 Duo CPU P8800 @ 2.66GHz
$ time ./sharper > /dev/null
real 15m30.214s
user 15m27.970s
sys 0m0.364s
When I have seen this challenge I said to myself ... running windows executable ... hmm I should search for a disassembler, and than I forgot the challenge.
Today I have seen it again ... with huge amount of succesfull solvers ... so I have installed Microsoft Windows SDK. Funny that I have tried the Il Disassebler as the fist tool.
Running the code helped me to see the need for final transformation x%=2^32; x-=(x>2^31)?2^32:0;
I got f(i)=i^5*16+5*i^4*s(i), where s(i)=2i-10 for 100>i>10 is the sum of lengths of natural numbers till i.
And f(99) with the final transformation was it. (Computed in excell, starting results compared to the results got by runnig the executable).
Today I have seen it again ... with huge amount of succesfull solvers ... so I have installed Microsoft Windows SDK. Funny that I have tried the Il Disassebler as the fist tool.
Running the code helped me to see the need for final transformation x%=2^32; x-=(x>2^31)?2^32:0;
I got f(i)=i^5*16+5*i^4*s(i), where s(i)=2i-10 for 100>i>10 is the sum of lengths of natural numbers till i.
And f(99) with the final transformation was it. (Computed in excell, starting results compared to the results got by runnig the executable).
Code: Select all
# Formula in Python
# ((4*4+5)*(num**5)) + ((num-10)*(5*(num**4)))
((4*4+5)*(99**5)) + ((99-10)*(5*(99**4))) = 242454432924
Nice challenge.