spamyboy wrote:You don't get point, it's listed in multyple lines.
like:
Code: Select all
Result1 Result 4 Result 7
Result2 Result 5 Result 8
Result3 Result 6 Result 9
In which case this is incorrect:
spamyboy wrote:Code: Select all
<tr>
<td id='title'><a href='index.php?word=1'>test</a></td>
<td id='title'><a href='index.php?word=2'>something</a></td>
<td id='title'><a href='index.php?word=3'>ok</a></td>
</tr>
<tr>
<td id='title'><a href='index.php?word=4'>dsfdfs</a></td>
<td id='title'><a href='index.php?word=5'>sosdfsdfmething</a></td>
<td id='title'><a href='index.php?word=6'>sdfsdfsdf</a></td>
</tr>
<tr>
<td id='title'><a href='index.php?word=7>s</a></td>
<td id='title'><a href='index.php?word=8'>fsdfdsf</a></td>
<td id='title'><a href='index.php?word=9'>dfsdfsdf</a></td>
</tr>
and should be more like:
Code: Select all
<tr>
<td id='title'><a href='index.php?word=1'>foo</a></td>
<td id='title'><a href='index.php?word=4'>foo</a></td>
<td id='title'><a href='index.php?word=7'>foo</a></td>
</tr>
<tr>
<td id='title'><a href='index.php?word=2'>foo</a></td>
<td id='title'><a href='index.php?word=5'>foo</a></td>
<td id='title'><a href='index.php?word=8'>foo</a></td>
</tr>
<tr>
<td id='title'><a href='index.php?word=3>foo</a></td>
<td id='title'><a href='index.php?word=6'>foo</a></td>
<td id='title'><a href='index.php?word=9'>foo</a></td>
</tr>
you wonder why I didn't get it
Here's the solution:
Code: Select all
<?php
function numberSequence($start, $cols, $end)
{
$rows = ($end - $start) / $cols;
$out = array();
for ($i = 0; $i < $rows; ++$i) {
$row = array();
for ($j = 0; $j < $cols; ++$j) {
$rowElement = $i + ($cols * $j) + $start;
if ($rowElement >= $end) {
break;
}
$row[] = $rowElement;
}
$out[] = $row;
}
return $out;
}
attest(numberSequence(0, 1, 3), array(array(0), array(1), array(2)));
attest(numberSequence(1, 1, 3), array(array(1), array(2)));
attest(numberSequence(10, 1, 10), array());
attest(numberSequence(0, 2, 4), array(array(0, 2), array(1, 3)));
attest(numberSequence(1, 2, 4), array(array(1, 3), array(2)));
attest(numberSequence(1, 3, 10), array(array(1, 4, 7), array(2, 5, , array(3, 6, 9)));
function attest($actual, $expected)
{
if ($actual === $expected) {
return;
}
// yeah i know it's deprecated mark-up
echo '<table><tr>';
echo '<td bgcolor="eeeeee" valign="top"><pre>';
var_dump($actual);
echo '</pre></td><td valign="top"><pre>';
var_dump($expected);
echo '</pre></td>';
echo '</tr></table>';
}
If you run it and you get no output, it worked.
That was pretty tough though.