[Challenge] Snakes and ladder style board

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: [Challenge] Snakes and ladder style board

Post by onion2k »

astions wrote:Might want to put an @ sign in front of the $c ;)
Hell no. Error suppression is bad and wrong. But putting $c = 0; before the loop would have been sensible.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: [Challenge] Snakes and ladder style board

Post by Benjamin »

LOL
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: [Challenge] Snakes and ladder style board

Post by VladSun »

onion2k wrote:Just for completeness, here's my solution ...
Cool, but it doesn't work with my PHP CLI ... :P
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: [Challenge] Snakes and ladder style board

Post by John Cartwright »

VladSun wrote:
onion2k wrote:Just for completeness, here's my solution ...
Cool, but it doesn't work with my PHP CLI ... :P
Unless your that dude from The Matrix that doesn't see the code, only a blonde, brunette, etc.

//my attempt at a joke
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: [Challenge] Snakes and ladder style board

Post by onion2k »

VladSun wrote:Cool, but it doesn't work with my PHP CLI ... :P
I'm actually crying proper real tears here. I'm really sorry.

:(
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: [Challenge] Snakes and ladder style board

Post by VladSun »

That's because you didn't follow the MVC pattern!!! :twisted:
You mixed up the View and the Model! Shame on you! :P :P :P
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: [Challenge] Snakes and ladder style board

Post by prometheuzz »

Eye-bleeding compact:

Code: Select all

for($i=100,$j=1,$x=-1;$i>0;$i+=$j%10==0?-10:$x,$j++,$x=((int)($i-1)/10)%2==1?-1:1) {
  printf("%3s%s",$i,$j%10==0?"\n":"");
}
jmaker
Forum Newbie
Posts: 16
Joined: Tue May 21, 2002 11:13 pm

Re: [Challenge] Snakes and ladder style board

Post by jmaker »

I'm a little late to this party, but here's mine. I'm not sure about performance wise, but I think it's easy enough to read.

Code: Select all

 for($x = 100, $y = 1; $x > 1; $x -= 10, $y++) {
    $ten = range($x, ($x-9));
    if($y % 2 == 0)
        sort($ten);
    foreach( $ten as $num )
        print "$num ";
    print "\n"; 
} 
saininvn
Forum Newbie
Posts: 1
Joined: Tue Apr 14, 2015 4:00 am

Re: [Challenge] Snakes and ladder style board

Post by saininvn »

<table border="1" cellpadding="5" cellspacing="2">

<?
for($k=100; $k>=1; $k -=10){?>
<tr> <? for($l=0; $l<10; $l +=1) {?>
<td> <?
if (($k/10) % 2 == 0)
{
echo $k-$l;
}

else
{
echo $k+$l-10+1;
}
?></td>

<? }?>
</tr>
<?
}
?>
</table>
Post Reply