I feel like practicing...

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

I feel like practicing...

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.)
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

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

Code: Select all

1
11
121
1331
14641
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post 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 :?
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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 :?
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post by mickd »

oops yeah your right, got confused.

EDIT: it starts with 0,1 ;)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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);

?>
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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..
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Don't forget about computational reuse!

Personally, I think algorithms are no fun but a necessary part of life...
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

hahahahaha.. *cries* I just got this as an assignment. Only I have to do it in assembly language. >_>
Post Reply