countdown calc

Discussion of challenges you have already solved
AMindForeverVoyaging
Forum Admin
Posts: 496
Joined: Sat May 28, 2011 9:14 am
Location: Germany

Post by AMindForeverVoyaging »

If I remember correctly I started the program some time on June 30th during the working day, and the last change to the output file was on July 2nd, 10:10 a.m.
guga
Posts: 17
Joined: Fri Mar 02, 2012 2:39 pm

Post by guga »

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 :D
So i changed it to just "calculate" the last value, compiled it again and let it run. Lazy but effective :wink:
dmgciubotaru
Posts: 1
Joined: Wed Aug 03, 2011 12:01 am

Post by dmgciubotaru »

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)
nuggerator
Posts: 3
Joined: Tue Jun 28, 2011 12:37 pm
Location: Germany

Post by nuggerator »

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
User avatar
Hippo
Posts: 339
Joined: Sat Feb 01, 2014 12:05 am
Location: Praha 5

Post by Hippo »

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).
User avatar
0x1d1aN
Posts: 2
Joined: Sat Sep 26, 2015 8:53 pm

Post by 0x1d1aN »

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
But it took some time before I realized that C# int is 32 bit long and the answer must be truncated. :wink:
Nice challenge.
Post Reply