Page 1 of 1
I feel like practicing...
Posted: Thu Oct 06, 2005 5:18 pm
by Luke
Somebody give me an assignment so I can practice my php skills. Something kinda n00bish. I'll post it on my site, and whoever assigns it can critique away... if they feel like it anyway.
Posted: Thu Oct 06, 2005 5:24 pm
by feyd
I'd suggest creating solutions to the problems talked about in many threads. This is how I learned very quickly (took me under a week to get up to speed on PHP). Maybe focus on areas that you don't know so well first, like maybe you need to work on your selection queries or regex.. there are often many threads a week that can be worked with. (Ignore the solutions presented to the original poster, only looking through them when you believe you have a grip on a solution to compare yours to others, or get a nudge in one possible direction.)
Posted: Thu Oct 06, 2005 5:28 pm
by Luke
Alright I will... that was my original intention, but they are all solved so fast, I never have the chance. I'll just ignore the solutions.
that's a good idea, thanks.
Posted: Thu Oct 06, 2005 6:01 pm
by pickle
Um... How about open a file, read the first line (make sure it's a number), then write back to the file a fibbonacci sequence?
So, if the first line is 1, the file should look like this:
Posted: Thu Oct 06, 2005 6:30 pm
by Luke
1 2 3 5 8 13 21 34 55 89 144 233 377 610... I'm already tired of this assignment... I don't think I'll finish it
Posted: Thu Oct 06, 2005 9:44 pm
by mickd
One armed space goat wrote:1 2 3 5 8 13 21 34 55 89 144 233 377 610... I'm already tired of this assignment... I don't think I'll finish it
thats not the fibonacci sequence

Posted: Fri Oct 07, 2005 1:11 am
by n00b Saibot
mickd wrote:One armed space goat wrote:1 2 3 5 8 13 21 34 55 89 144 233 377 610... I'm already tired of this assignment... I don't think I'll finish it
thats not the fibonacci sequence

AFAI Remember, it really is... the original question gives something which is called some Triangle, it's Pascal's or something like that

Posted: Fri Oct 07, 2005 1:21 am
by mickd
oops yeah your right, got confused.
EDIT: it starts with 0,1

Posted: Fri Oct 07, 2005 4:43 am
by timvw
A brainteaser, try to solve the following problem as efficient as possible: $a = fib(2349);
fib($n) is the function that returns the n-th number in the fibonacci sequence..
And then my proposed solution:
http://timvw.madoka.be/comment.php?message_id=162.
Posted: Fri Oct 07, 2005 12:58 pm
by Luke
I don't even understand what you just asked, so I will forgo that project, but here is my function for fib... how would I get the return of ever instance of this function?
Code: Select all
<?php
function fibonacci($n1, $n2, $stop){
$n3 = $n1 + $n2;
if($n3 <= $stop){
echo $n3." ";
fibonacci($n2, $n3, $stop);
}
}
fibonacci(1, 2, 1000);
?>
Posted: Fri Oct 07, 2005 1:06 pm
by pickle
Given the sequence 1,2,3,5,8, then fib(4) would return '5'. Modify your function to also accept the desired position, and the position of the number you're currently calculating.
At this point, it might be easier to put it in an object.
Posted: Fri Oct 07, 2005 5:28 pm
by timvw
http://www.mcs.surrey.ac.uk/Personal/R. ... ml#Rabbits
well, i'll explain a little.. if you want to calculate the n-th number from the fibonacci series you do it as following:
if n equals 0 then the number = 0;
if n equals 1 then the number = 1;
if n equals 2 then the number = 1; (0 + 1)
if n equals 3 then the number = 2; (1 + 1)
if n equals 4 then the number = 3; (2 + 1)
if n equals 5 then the number = 5; (3+ 2)
if n equals 6 then the number = 8; (5 + 3)
if n equals 7 then the number = 13; (8 + 5)
basically, if n then the number = the (n-1)th number = (n-2)th number...
so you can start thinking about writing a recursive solution..
and then improve that recursive implementation..
and then use your math book and discover there is also a non-recursive solution which is even faster..
Posted: Fri Oct 07, 2005 9:56 pm
by Ambush Commander
Don't forget about computational reuse!
Personally, I think algorithms are no fun but a necessary part of life...
Posted: Sun Oct 09, 2005 6:59 pm
by Skara
hahahahaha.. *cries* I just got this as an assignment. Only I have to do it in assembly language. >_>