Growing Bacteria

Discussion of challenges you have already solved
rmplpmpl
Posts: 113
Joined: Sun Oct 26, 2008 10:38 am
Location: Germany

Growing Bacteria

Post 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...
vogel
Posts: 4
Joined: Tue Oct 28, 2008 5:02 pm

Post 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.
Marv
Posts: 17
Joined: Tue Nov 25, 2008 12:58 pm

Post 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
whattheh@ck
Posts: 16
Joined: Wed Jul 16, 2008 2:33 am
Location: here

Post by whattheh@ck »

Did it in Python using 8 variables and a "while" statement... not too hard.
hack the planet
samuelandjw
Posts: 8
Joined: Sat Nov 01, 2008 2:49 pm

Post 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?
DaymItzJack
Posts: 106
Joined: Thu Oct 29, 2009 9:21 pm

Post 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.
Migue
Posts: 1
Joined: Sat Jun 05, 2010 1:43 am

Post 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)
Triton456
Posts: 11
Joined: Sun Oct 25, 2009 5:01 pm
Location: Between Germany and England

Post 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
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
Aghamemnon
Posts: 49
Joined: Fri Jul 02, 2010 9:34 pm
Location: Egypt
Contact:

Oh great

Post 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
:twisted: Devilish Angel Aghamemnon :twisted:
Nullsig
Posts: 3
Joined: Wed Sep 29, 2010 11:16 pm

Post by Nullsig »

Solved using excel. Once I mapped out the first 8 days by hand and recognized fibonacci sequence.
AMindForeverVoyaging
Forum Admin
Posts: 496
Joined: Sat May 28, 2011 9:14 am
Location: Germany

Post 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 :)
moose
Posts: 67
Joined: Fri Jul 16, 2010 7:32 pm

Post 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
CruzR
Posts: 1
Joined: Fri Aug 26, 2011 10:55 pm

Post 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:
Malfi
Posts: 4
Joined: Thu Jun 02, 2011 9:02 pm

Post 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.
dionmaster01
Posts: 1
Joined: Sun Feb 05, 2012 5:14 pm

Post by dionmaster01 »

I works it out till 42 days, than I just keep pressing till I had found the answer :D
Post Reply