Can you solve a problem like this?

  • Thread starter Raistlin Majere
  • Start date
R

Raistlin Majere

Jesus Christ! I am trying to solve a problem for a day (I will tell my
progress by the end)...

It must be:

AEIM
BFJN
CGKO
DHLP

It must not be:

ABCD
EFGH
IJKL
MNOP

How can links be added in alphabetic order down instead of up in a
table that has 4 cols for every row, 11 rows and 47 links?

#!C:\Programas\xampplite\perl\bin\perl.exe

print "Content-type: text/html\n\n";

open(OLDLIST, "<link list.tmp1");
open(NEWLIST, ">link list.tmp2");

$count=1;

$col=0;
$row=0;

$place=1;

@newlist=();

foreach $line(<OLDLIST>)
{
$col=$count / 4;
$row=$count % 4;

$place=$col * 4 + $row;

$newlist[$place]=$line;

$count++;
};

print NEWLIST @newlist;

close(NEWLIST);
close(OLDLIST);
 
L

l v

Raistlin said:
Jesus Christ! I am trying to solve a problem for a day (I will tell my
progress by the end)...

It must be:

AEIM
BFJN
CGKO
DHLP

It must not be:

ABCD
EFGH
IJKL
MNOP

How can links be added in alphabetic order down instead of up in a
table that has 4 cols for every row, 11 rows and 47 links?

#!C:\Programas\xampplite\perl\bin\perl.exe

print "Content-type: text/html\n\n";

open(OLDLIST, "<link list.tmp1");
open(NEWLIST, ">link list.tmp2");

$count=1;

$col=0;
$row=0;

$place=1;

@newlist=();

foreach $line(<OLDLIST>)
{
$col=$count / 4;
$row=$count % 4;

$place=$col * 4 + $row;

$newlist[$place]=$line;

$count++;
};

print NEWLIST @newlist;

close(NEWLIST);
close(OLDLIST);

Install Text::Orientation from CPAN?

use Text::Orientation;
my $a ="ABCD\nEFGH\nIJKL\nMNOP";
print "$a\n\n";

$rot = Text::Orientation->new( TEXT => $a );
print $rot->transpose('horizontal');

OUTPUT:
ABCD
EFGH
IJKL
MNOP

AEIM
BFJN
CGKO
DHLP
 
R

Raistlin Majere

Rephrasing and more progress:

How can links be added in alphabetic between <td> and </td> order down
instead of up in a table that has 4 cols for every row, 11 rows and 47
links?

#!C:\Programas\xampplite\perl\bin\perl.exe

print "Content-type: text/html\n\n";

open(OLDLIST, "<link list.tmp1");
open(NEWLIST, ">link list.tmp2");

$count=1;

$up1=0;
$up2=0;

$place=1;

@newlist=();

foreach $line(<OLDLIST>)
{
$up1=int $count / 12;
$up2=int $count % 12;

$place=($up1 + 1) * 12 + ($up2 + 1);

$newlist[$place]=$line;

$count++;
};

print NEWLIST @newlist;

close(NEWLIST);
close(OLDLIST);
 
U

usenet

Raistlin said:
How can links be added in alphabetic between <td> and </td> order down
instead of up in a table that has 4 cols for every row, 11 rows and 47 links?

In your original post, you gave a nice example of exactly what you want
the output to be, and it was easy to understand what you wanted (and
Len gave you a helpful reply). However, this time, I have NO IDEA what
you are asking, and you didn't provide the helpful example.
 
X

xhoster

Raistlin Majere said:
Rephrasing and more progress:

How can links be added in alphabetic between <td> and </td> order down
instead of up in a table that has 4 cols for every row, 11 rows and 47
links?

You can't. 4x11 < 47.

Xho
 
X

Xicheng Jia

Raistlin said:
Jesus Christ! I am trying to solve a problem for a day (I will tell my
progress by the end)...

It must be:

AEIM
BFJN
CGKO
DHLP

It must not be:

ABCD
EFGH
IJKL
MNOP

How can links be added in alphabetic order down instead of up in a
table that has 4 cols for every row, 11 rows and 47 links?

#!C:\Programas\xampplite\perl\bin\perl.exe

print "Content-type: text/html\n\n";

open(OLDLIST, "<link list.tmp1");
open(NEWLIST, ">link list.tmp2");

$count=1;

$col=0;
$row=0;

$place=1;

@newlist=();

foreach $line(<OLDLIST>)
{
$col=$count / 4;
$row=$count % 4;

change this
=> $place=$col * 4 + $row;
to
$place=$col + $row * 4;

For a 2D array, $col=$count/4 you defined here is actually row-number,
and $row=$count%4 is col-number.

Xicheng
$newlist[$place]=$line;

$count++;
};

print NEWLIST @newlist;

close(NEWLIST);
close(OLDLIST);
 
R

Raistlin Majere

"link list.tmp1" is like this...

<a href="http://www.sitex">Site X</a>
<a href="http://www.sitey">Site Y</a>
<a href="http://www.sitem">Site M</a>
<a href="http://www.siten">Site N</a>
<a href="http://www.sitez">Site Z</a>

I mean, it is a text link list.

I need to add all these links to a table, but if I add it like...

<table>
<tr>
<td>*text link 1*</td>
<td>*text link 2*</td>
<td>*text link 3*</td>
<td>*text link 4*</td>
</tr>
<tr>
<td>*text link 5*</td>
<td>*text link 6*</td>
<td>*text link 7*</td>
<td>*text link 8*</td>
</tr>
</table>

....and my visitors want to read it by alphabetic order, they will have
to read it from left to right, then down, then from left to right, then
down and so on, but I want my visitors to be able to read it by
alphabetic order from top to bottom, then right, then from top to
bottom, then right, then from top to bottom and so on...

I want my table to be like this...

<table>
<tr>
<td>*text link 1*</td>
<td>*text link 3*</td>
<td>*text link 5*</td>
<td>*text link 7*</td>
</tr>
<tr>
<td>*text link 2*</td>
<td>*text link 4*</td>
<td>*text link 6*</td>
<td>*text link 8*</td>
</tr>
</table>

There are 47 links in "link list.tmp1". These links need to be sorted
in the order that I want in the table. I am trying to do that! Here
goes more progress.

#!C:\Programas\xampplite\perl\bin\perl.exe

print "Content-type: text/html\n\n";

open(OLDLIST, "<link list.tmp1");
open(NEWLIST, ">link list.tmp2");

$count=1;

$up1=0;
$up2=0;

$place=1;

@newlist=();

foreach $line(<OLDLIST>)
{
$up1=int $count / 12;
$up2=int $count % 12;

$place=($up1 + 1) * 12 + ($up2 + 1);

$newlist[$place]=$line;

$count++;
};

print NEWLIST @newlist;

close(NEWLIST);
close(OLDLIST);
 
R

Raistlin Majere

"link list.tmp1" is like this...

<a href="http://www.sitex.com/">Site X</a>
<a href="http://www.sitey.com/">Site Y</a>
<a href="http://www.sitem.com/">Site M</a>
<a href="http://www.siten.com/">Site N</a>
<a href="http://www.sitez.com/">Site Z</a>

I mean, it is a text link list.

I need to add all these links to a table, but if I add it like...

<table>
<tr>
<td>*text link 1*</td>
<td>*text link 2*</td>
<td>*text link 3*</td>
<td>*text link 4*</td>
</tr>
<tr>
<td>*text link 5*</td>
<td>*text link 6*</td>
<td>*text link 7*</td>
<td>*text link 8*</td>
</tr>
</table>

....and my visitors want to read it by alphabetic order, they will have
to read it from left to right, then down, then from left to right, then
down and so on, but I want my visitors to be able to read it by
alphabetic order from top to bottom, then right, then from top to
bottom, then right and so on...

I want my table to be like this...

<table>
<tr>
<td>*text link 1*</td>
<td>*text link 3*</td>
<td>*text link 5*</td>
<td>*text link 7*</td>
</tr>
<tr>
<td>*text link 2*</td>
<td>*text link 4*</td>
<td>*text link 6*</td>
<td>*text link 8*</td>
</tr>
</table>

There are 47 links in "link list.tmp1". These links need to be sorted
in the order that I want in the table. I am trying to do that! Here
goes more progress.

#!C:\Programas\xampplite\perl\bin\perl.exe

print "Content-type: text/html\n\n";

open(OLDLIST, "<link list.tmp1");
open(NEWLIST, ">link list.tmp2");

$count=1;

$up1=0;
$up2=0;

$place=1;

@newlist=();

foreach $line(<OLDLIST>)
{
$up1=int $count / 12;
$up2=int $count % 12;

$place=($up1 + 1) * 12 + ($up2 + 1);

$newlist[$place]=$line;

$count++;
};

print NEWLIST @newlist;

close(NEWLIST);
close(OLDLIST);
 
L

l v

Raistlin said:
Rephrasing and more progress:

How can links be added in alphabetic between <td> and </td> order down
instead of up in a table that has 4 cols for every row, 11 rows and 47
links?
[code snip]

OK. Fair enough. Perhaps you look at how Text::Orientation's
transpose() is written and apply the concept.
 
A

Anno Siegel

[
...and my visitors want to read it by alphabetic order, they will have
to read it from left to right, then down, then from left to right, then
down and so on, but I want my visitors to be able to read it by
alphabetic order from top to bottom, then right, then from top to
bottom, then right and so on...

I want my table to be like this...

<table>
<tr>
<td>*text link 1*</td>
<td>*text link 3*</td>
<td>*text link 5*</td>
<td>*text link 7*</td>
</tr>
<tr>
<td>*text link 2*</td>
<td>*text link 4*</td>
<td>*text link 6*</td>
<td>*text link 8*</td>
</tr>
</table>

There are 47 links in "link list.tmp1". These links need to be sorted
in the order that I want in the table.

So you want to organize a linear list @l into $n_col columns so that the
count goes down each column. You can calculate $height (the number of
rows) of the table and prepare a set @i of $n_col indices that are
$height steps apart. Use the indices to take a slice out of @l and
increase all indices by 1. Do that $height times.

my $n_col = 4;
my @l = map sprintf( 'text link %2d', $_), 1 .. 47;

my $height = 1 + int( (@l - 1)/$n_col);
my @i = map $height*$_, 0 .. $n_col - 1;
my @tab = map [ @l[ map $_++, @i]], 1 .. $height;
$_->[ -1] ||= '' for @tab; # last col can contain undef

print "@$_\n" for @tab;

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top