Snake Arithmetic

User avatar
laz0r
Posts: 290
Joined: Thu Feb 04, 2010 4:18 pm
Location: Within the depths of Unix

Post by laz0r »

Am I being really stupid, or isn't the calculation of any D(n) just going to go on forever as we have a recursive function without a base case?
There is no spoon.
User avatar
CodeX
Posts: 350
Joined: Fri Oct 17, 2008 5:28 pm

Post by CodeX »

Both functions have a conditional return based on a ternary operation, if n is any of None, False or 0 then it returns 1 as its not a bitwise operation.
User avatar
laz0r
Posts: 290
Joined: Thu Feb 04, 2010 4:18 pm
Location: Within the depths of Unix

Post by laz0r »

Ah, thanks!
There is no spoon.
User avatar
laz0r
Posts: 290
Joined: Thu Feb 04, 2010 4:18 pm
Location: Within the depths of Unix

Post by laz0r »

I've made a function that seems to model the snake one very closely, but it doesn't work - does Python overflow at a low value or something?
There is no spoon.
User avatar
CodeX
Posts: 350
Joined: Fri Oct 17, 2008 5:28 pm

Post by CodeX »

Just to let you know D(10^12) is so large alone it would take 9.53219GiB just to hold it's value so you aren't going to find directly imitating the function the way to go (it will take 4x more to hold the stated value of 4*b). Time to break it into maths?
User avatar
laz0r
Posts: 290
Joined: Thu Feb 04, 2010 4:18 pm
Location: Within the depths of Unix

Post by laz0r »

I did break D(n) into maths, and I found a function that seems to generate N(b*4)b/D(b*4). My function holds (plus or minus 1) for b = 1 to 300. I've tried a range of values around my value; it is 13 digits long like it should be.
Nice to see you using the GiB! It's much underrated in my opinion.
There is no spoon.
arthur
Posts: 21
Joined: Fri Jul 23, 2010 12:44 pm

Post by arthur »

Some calculus may help. :)
ShadowWidow
Posts: 6
Joined: Tue Nov 09, 2010 4:09 pm
Location: Germany

Post by ShadowWidow »

I think i am at a position where i need some help.
I've transformed the recursive functions in to a iterativ one.
The first 250 values are exactly the same as in the original.
But the result i get for 1000000000000 is wrong.

My Number is 13 digits long and looks like 37...99.
I allready tried it in a range from -15 to +15 but they are all incorrect.

Can somebady give me a little hint ?
hxhl95
Posts: 1
Joined: Fri Feb 18, 2011 8:33 pm

Post by hxhl95 »

same issue here, transformed the recursion into a simple almost linear function, got a value (the same value as poster above), doesn't work.

i've even simplified the thing by hand, it gives me exactly what i observe from calculating small values of b (b<1000).

hint?
uws8505
Posts: 32
Joined: Sun Jan 23, 2011 8:57 pm

Post by uws8505 »

If you got an iterative solution, then look really closely at it.

An infinite series approximates to a finite series, and vice versa :)
moose
Posts: 67
Joined: Fri Jul 16, 2010 7:32 pm

Post by moose »

The serie is not in oesis.org :-(

I transformed D(n) and N(n) to iterative functions. But it seems to take to long:

Code: Select all

$ time python snake-arithmetik.py -b    10 #time: 0m0.040s
$ time python snake-arithmetik.py -b   100 #time: 0m0.068s
$ time python snake-arithmetik.py -b  1000 #time: 0m14.037s
$ time python snake-arithmetik.py -b 10000 #time: 10h 5min 27s ... wow
How long did it take to calculate the result for b=1000000000000 (10*12 oder 10**12 in python ;-) )?
Last edited by moose on Sun Jul 17, 2011 8:52 pm, edited 1 time in total.
uws8505
Posts: 32
Joined: Sun Jan 23, 2011 8:57 pm

Post by uws8505 »

No, that's not a series of natural numbers, it's a famous series of fractions.
Aware that the word "series" means the sum of numbers in a sequence :D
moose
Posts: 67
Joined: Fri Jul 16, 2010 7:32 pm

Post by moose »

uws8505 wrote:No, that's not a series of natural numbers, it's a famous series of fractions.
Aware that the word "series" means the sum of numbers in a sequence :D
Hrmpf ... I forgot how Python is handling integer division...
uws8505
Posts: 32
Joined: Sun Jan 23, 2011 8:57 pm

Post by uws8505 »

I just found out that the words above might be misleading...
I meant that there is a pattern in N(4*n) / D(4*n), not N(n) and D(n) individually, that you can approximate into an infinite series, and the precision increases with n so you don't need to worry about integer division.
aurora
Posts: 54
Joined: Thu Feb 05, 2009 12:31 pm
Location: Bavaria, Germany

Post by aurora »

mmm ... i figured out, what N and D are doing. the problem is, that even with an iterative algorithm calculation will take too long for 1000000000000. i wonder, if there is a math trick (again) or if i will get a correct result by using an approximate algorithm?
Post Reply