Page 1 of 2

Growing Bacteria

Posted: Sat Jul 11, 2009 8:28 pm
by rmplpmpl
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...

Posted: Tue Jul 14, 2009 12:15 pm
by vogel
In my opinion this is a really easy challenge.
I implemented a programm in C able to simulate this algorithm.
It took me only 15 minutes to write the program and less than 1 second to execute it.

Posted: Fri Jul 17, 2009 12:24 am
by Marv
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

Posted: Sun Oct 25, 2009 10:57 pm
by whattheh@ck
Did it in Python using 8 variables and a "while" statement... not too hard.

Posted: Wed Jan 06, 2010 12:09 pm
by samuelandjw
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?

Posted: Sat Jan 09, 2010 3:27 am
by DaymItzJack
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?
I'm pretty sure that's what I did.

Posted: Sat Aug 14, 2010 6:01 am
by Migue
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)

Posted: Thu Oct 07, 2010 3:39 pm
by Triton456
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 :D

I know this is a really dumb way to do it, but it worked for me :wink: :P

greetz,
Triton456

Oh great

Posted: Sat Oct 09, 2010 12:11 am
by Aghamemnon
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

Posted: Mon Oct 11, 2010 7:31 pm
by Nullsig
Solved using excel. Once I mapped out the first 8 days by hand and recognized fibonacci sequence.

Posted: Wed Jun 15, 2011 10:00 am
by AMindForeverVoyaging
vogel wrote: I implemented a programm in C able to simulate this algorithm.
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 stuff ;) I switched to Java:

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++;
		}
	}
}
The algorithm only works from Day 5 onwards - I guess this is because the law of generation for this bacterium includes a 5-day cycle? Maybe a mathematician could elaborate on that :)

Posted: Tue Jun 28, 2011 3:20 pm
by moose
I tried it with python and got some weird results:

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 
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

Posted: Sun Aug 28, 2011 12:49 am
by CruzR
Similar to some of you others who did it in Excel, I solved this in Libre Office Calc, pretty simple that way :wink:

Posted: Sun Aug 28, 2011 8:40 am
by Malfi
First I wrote an emulation in Java for this. This worked very fine ... until about n=38 then it ran into "out of merror ..." due to too many bacteria objects.

Should have thought about it a few minutes before start coding. BigInteger did it easily then.

Posted: Thu Feb 09, 2012 4:14 pm
by dionmaster01
I works it out till 42 days, than I just keep pressing till I had found the answer :D