I feel like practicing...
Moderator: General Moderators
I feel like practicing...
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.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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.)
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:
So, if the first line is 1, the file should look like this:
Code: Select all
1
11
121
1331
14641Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- n00b Saibot
- DevNet Resident
- Posts: 1452
- Joined: Fri Dec 24, 2004 2:59 am
- Location: Lucknow, UP, India
- Contact:
AFAI Remember, it really is... the original question gives something which is called some Triangle, it's Pascal's or something like thatmickd wrote:thats not the fibonacci sequenceOne 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
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.
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.
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);
?>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.
At this point, it might be easier to put it in an object.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
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..
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..
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US