a_bertrand Posted April 22, 2007 Posted April 22, 2007 Ok: I have an assignment for you guys: Write a script which reads a web page and extracts all the URL from the links... 2 criteria to designate the winner: short code, and fully working. Time: 1 week. Next Sunday I will check the result and designate the winner, ok? Submission: via email: bertrand (at) nodalideas {dot} com Language: PHP (4 or 5) You may submit as many trials you want, I will check them as soon as possible and give you my comment out. At then end I will post the winner name here, and his/her code. So please provide your forum name, and zip the code... Quote
a_bertrand Posted April 22, 2007 Author Posted April 22, 2007 Mini Coding Contests 2nd assignement: (an easy easy one) Build the following figure with PHP and loops (no HTML / or huge echo block allowed) * *** ***** *** * The shape need to be 10 height / 10 width Same rules as before for the deadline and the submission Quote
a_bertrand Posted April 22, 2007 Author Posted April 22, 2007 Re: Mini Coding Contests BTW at the end I will show you my solutions. Maybe it will not be the best one but at least it may help those which didn't managed to make it. Quote
Decepti0n Posted April 22, 2007 Posted April 22, 2007 Re: Mini Coding Contests I'll do it :p For the second one, is it just a diamond made up of '*'s? Quote
mdshare Posted April 22, 2007 Posted April 22, 2007 Re: Mini Coding Contests dunno if the word shape is a hint, if so I would go for the GD library functions Quote
Decepti0n Posted April 22, 2007 Posted April 22, 2007 Re: Mini Coding Contests GD or loops would be easy enough :p Quote
Aqua Posted April 22, 2007 Posted April 22, 2007 Re: Mini Coding Contests This is a bit to easy :( it is for some :) Quote
Decepti0n Posted April 22, 2007 Posted April 22, 2007 Re: Mini Coding Contests Uh, enter then Deathstar Quote
mdshare Posted April 22, 2007 Posted April 22, 2007 Re: Mini Coding Contests yea enter it, will be interesting to get input/comments from well one of the few people we know that hold a Zend certificate Quote
seanybob Posted April 22, 2007 Posted April 22, 2007 Re: Mini Coding Contests 2nd assignement: (an easy easy one) Build the following figure with PHP and loops (no HTML / or huge echo block allowed) * *** ***** *** * The shape need to be 10 height / 10 width Same rules as before for the deadline and the submission um... following the pattern, it would have to be 11 or 9 (seeing as to how the rows all contain an odd number of asterisks. would you accept one of those? if so, I'm done. or is there something I'm missing? Quote
a_bertrand Posted April 22, 2007 Author Posted April 22, 2007 Re: Mini Coding Contests for the 2nd assignment, GD is not allowed, you have to do it via ECHO :-P And my mistake, it need to be 9 or 11 width... Actually it doesn't really matter as what is important is to see if you can code it, and if yes if you discover some shortcuts. I will give you a few solutions at the end... you will see, some are way easier than what we all think at the beginning :-P Quote
a_bertrand Posted April 22, 2007 Author Posted April 22, 2007 Re: Mini Coding Contests Got the first result. It works BUT do not fully qualify as there is a . and not a space before the stars... now I will accept both, but the one which come with space will be voted better than the one with a . or other... I will let you find out how to display it correctly :-P BTW there is at least 3 or 4 solutions to do it. Quote
seanybob Posted April 22, 2007 Posted April 22, 2007 Re: Mini Coding Contests Got the first result. It works BUT do not fully qualify as there is a . and not a space before the stars... now I will accept both, but the one which come with space will be voted better than the one with a . or other... I will let you find out how to display it correctly :-P BTW there is at least 3 or 4 solutions to do it. ;P I could change the . to a space, but some servers seem to make the space disappear when I do it. also, I could make it more efficient... aye caramba, spose I'll do it later. this is kinda fun ;) and echo... print... same thing, right? :D finally... instead of adding spaces or periods, could I just add a <center> command? :) Quote
Decepti0n Posted April 22, 2007 Posted April 22, 2007 Re: Mini Coding Contests i p00ned it seany come on Quote
a_bertrand Posted April 22, 2007 Author Posted April 22, 2007 Re: Mini Coding Contests echo and print are not exactly the same... nearly but not exactly... echo is slightly faster. I will not say what you did as it is one option as nobody see the problem directly, but using space is possible... I will give the answer next week in case. And yes center would be one of the trick but now you spoiled the fun :-P So nobody will be allowed to use center anymore :-P I could change the . to a space, but some servers seem to make the space disappear when I do it. also, I could make it more efficient... aye caramba, spose I'll do it later. this is kinda fun ;) and echo... print... same thing, right? :D finally... instead of adding spaces or periods, could I just add a <center> command? :) Quote
a_bertrand Posted April 22, 2007 Author Posted April 22, 2007 Re: Mini Coding Contests BTW I just made myself the second assignment, and without cheating and counting the <?PHP and ?> I have 6 lines of code (so no multiple code on a single line like "echo '1';echo '2'" that would be 2 lines not 1) Now who will discover how I did it? Hint: that's how my code look like: 1 <?PHP 2 for(...) 3 ....; 4 for(...) 5 ....; 6 ?> And I'm not using center nor dots! Quote
a_bertrand Posted April 29, 2007 Author Posted April 29, 2007 Re: Mini Coding Contests And the winners are: Seanybob for the diamond shaped text Deception for the link parser Congratz to both! So my solution for the diamond shaped text: change the width value with a even number and your diamond will change. As you can see you can avoid double loops ;-) <PRE> <?php $width=12; for($i=0;$i < ($width/2);$i++) echo str_repeat(" ",($width/2)-$i).str_repeat("*",$i*2)."*\n"; for($i=($width/2)-2;$i >= 0;$i--) echo str_repeat(" ",($width/2)-$i).str_repeat("*",$i*2)."*\n"; ?> </PRE> and why not try to do all with one loop? Well that would be my solution then: <PRE> <?php $width=12; $half=array(); for($i=0;$i < ($width/2);$i++) $half[]=str_repeat(" ",($width/2)-$i).str_repeat("*",$i*2)."*\n"; echo implode("",$half); array_pop($half); echo implode("",array_reverse($half)); ?> </PRE> This second code is a bit longer but maybe executed a bit faster as we don't have to iterate in a second loop. The iteration is done with native PHP functions and therefore could be a bit faster. BTW if you want to remove the <PRE></PRE> tag you could use the &nbps; tag in order to add spaces. Quote
ignite Posted April 29, 2007 Posted April 29, 2007 Re: Mini Coding Contests Now a competition for the novices ? Quote
Raptor_Jesus Posted April 29, 2007 Posted April 29, 2007 Re: Mini Coding Contests Interesting truth stated earlier about echo being faster than print. From what I read various places around 20% on some benchmarks comparing the two. Anyway thats good ammo to know, something simple over all can make a small but significant difference. Alot of people should remember that lil fact. Quote
Guest Anonymous Posted April 29, 2007 Posted April 29, 2007 Re: Mini Coding Contests Grats Seany and rah ...good job to you both :) Quote
a_bertrand Posted May 15, 2007 Author Posted May 15, 2007 Re: Mini Coding Contests Question: do you want a super easy contest as next one, or something which requires a bit of thinking? Quote
stryker Posted May 15, 2007 Posted May 15, 2007 Re: Mini Coding Contests i agree with death, don't have time to f**k around. Quote
oxidati0n Posted May 16, 2007 Posted May 16, 2007 Re: Mini Coding Contests Nice piece of code. lol ;) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.