Growing Bacteria
Growing Bacteria
Gosh, that was a hard one for me...
It took me ages to stop trying to develop a formula for this and just pick a piece of paper and a pen. After analysing the first 8 days it was obvious I could do it Fibonacci-style.
It's a shame that I forgot all these math skills I had back at university...
It took me ages to stop trying to develop a formula for this and just pick a piece of paper and a pen. After analysing the first 8 days it was obvious I could do it Fibonacci-style.
It's a shame that I forgot all these math skills I had back at university...
I think this was easy, too. But I liked it anyway. Here my Ruby Code:
Code: Select all
a = [1,0,0,0]
for i in 1..1000
break if a[0] + a[1] + a[2] + a[3] >= 1000000000000
a.unshift(a[1] + a[0]).pop
end
puts i
-
- Posts: 16
- Joined: Wed Jul 16, 2008 2:33 am
- Location: here
-
- Posts: 8
- Joined: Sat Nov 01, 2008 2:49 pm
I've just solved this chanllenge in a way that is not so good (at least to me)...
First I wrote down the first 11 numbers and plotted them. I guessed it increased in an exponential manner and then I wrote an expression that was supposed to approximate the trend. I got 53, so I kept trying numbers around 53 until I found 58... not a good method, right?
First I wrote down the first 11 numbers and plotted them. I guessed it increased in an exponential manner and then I wrote an expression that was supposed to approximate the trend. I got 53, so I kept trying numbers around 53 until I found 58... not a good method, right?
-
- Posts: 106
- Joined: Thu Oct 29, 2009 9:21 pm
I'm pretty sure that's what I did.samuelandjw wrote:I've just solved this chanllenge in a way that is not so good (at least to me)...
First I wrote down the first 11 numbers and plotted them. I guessed it increased in an exponential manner and then I wrote an expression that was supposed to approximate the trend. I got 53, so I kept trying numbers around 53 until I found 58... not a good method, right?
did it with python:
Code: Select all
def g(n):
a = 0
b = 1
for k in xrange(0,n-1):
a,b = b,a+b
return b
def f(n):
return g(n-3) + g(n-2) + g(n-1) + g(n)
for n in xrange(0,70):
print n,f(n)
I liked this challenge. Took me quite a while to figure out how to do it.
I'm not very skilled with program languages yet, but I just used Excel formules at school for the subject Database, so I used that for this challenge. I just made three rows, one with new bacteria, one with death bacteria and one with total bacteria, and figured out some formulas in it, then I just dragged it down till I've reached 1.000.000.000.000, and there was row nr. 58
I know this is a really dumb way to do it, but it worked for me
greetz,
Triton456
I'm not very skilled with program languages yet, but I just used Excel formules at school for the subject Database, so I used that for this challenge. I just made three rows, one with new bacteria, one with death bacteria and one with total bacteria, and figured out some formulas in it, then I just dragged it down till I've reached 1.000.000.000.000, and there was row nr. 58
![Very Happy :D](./images/smilies/icon_biggrin.gif)
I know this is a really dumb way to do it, but it worked for me
![Wink :wink:](./images/smilies/icon_wink.gif)
![Razz :P](./images/smilies/icon_razz.gif)
greetz,
Triton456
Play a Windows CD backwards and hear satanic messages. That’s nothing, play it forwards and it installs Windows.
Music = Life
Same Shit - Different Day
Music = Life
Same Shit - Different Day
-
- Posts: 49
- Joined: Fri Jul 02, 2010 9:34 pm
- Location: Egypt
- Contact:
Oh great
I tried to think very hard to solve it
squeezed my head with no answer just errors
but when I didn't think
I tried to solve and it worked
squeezed my head with no answer just errors
but when I didn't think
I tried to solve and it worked
![Twisted Evil :twisted:](./images/smilies/icon_twisted.gif)
![Twisted Evil :twisted:](./images/smilies/icon_twisted.gif)
-
- Forum Admin
- Posts: 496
- Joined: Sat May 28, 2011 9:14 am
- Location: Germany
I started with C as well, but since the standard library does not provide support for big integers and I didn't feel like installing additional stuffvogel wrote: I implemented a programm in C able to simulate this algorithm.
![Wink ;)](./images/smilies/icon_wink.gif)
Code: Select all
import java.math.BigInteger;
public class GBsolver {
public static void main(String args[]) {
BigInteger Summand1 = new BigInteger("4");
BigInteger Summand2 = new BigInteger("7");
BigInteger UpperBound = new BigInteger("1000000000000");
BigInteger Sum = new BigInteger("0");
int i = 5;
while(Sum.compareTo(UpperBound) == -1) {
Sum = Summand1.add(Summand2);
System.out.format("Day %2d: %13d\n", i, Sum);
Summand1 = Summand2;
Summand2 = Sum;
i++;
}
}
}
![Smile :)](./images/smilies/icon_smile.gif)
I tried it with python and got some weird results:
I guess the error is that I loose precision when devidion through 2. But I have no clue how to fix that. Can you help me?
Then I took Wolfram|Alpha
Code: Select all
from math import sqrt
from decimal import *
getcontext().prec = 100
def F(n):
phi = Decimal(1 + Decimal(str(sqrt(5))))/2
psi = Decimal(1 - Decimal(str(sqrt(5))))/2
return (Decimal(phi**n) - Decimal(psi**n) ) / (phi-psi)
day = 57
print (F(day) + F(day+1) + F(day+2) + F(day+3))/1000000000000
Then I took Wolfram|Alpha
-
- Posts: 1
- Joined: Sun Feb 05, 2012 5:14 pm