Hell no. Error suppression is bad and wrong. But putting $c = 0; before the loop would have been sensible.astions wrote:Might want to put an @ sign in front of the $c
[Challenge] Snakes and ladder style board
Moderator: General Moderators
Re: [Challenge] Snakes and ladder style board
Re: [Challenge] Snakes and ladder style board
Cool, but it doesn't work with my PHP CLI ...onion2k wrote:Just for completeness, here's my solution ...
There are 10 types of people in this world, those who understand binary and those who don't
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: [Challenge] Snakes and ladder style board
Unless your that dude from The Matrix that doesn't see the code, only a blonde, brunette, etc.VladSun wrote:Cool, but it doesn't work with my PHP CLI ...onion2k wrote:Just for completeness, here's my solution ...
//my attempt at a joke
Re: [Challenge] Snakes and ladder style board
I'm actually crying proper real tears here. I'm really sorry.VladSun wrote:Cool, but it doesn't work with my PHP CLI ...
Re: [Challenge] Snakes and ladder style board
That's because you didn't follow the MVC pattern!!!
You mixed up the View and the Model! Shame on you!

You mixed up the View and the Model! Shame on you!
There are 10 types of people in this world, those who understand binary and those who don't
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: [Challenge] Snakes and ladder style board
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":"");
}Re: [Challenge] Snakes and ladder style board
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";
} Re: [Challenge] Snakes and ladder style board
<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>
<?
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>