Maybe by AWK: printing help diagonal matrix characters into line

Hi Experts,

I want to print this charts diagonal data into straight lines.
This is a matrix 24X24 Horizontal and vertical.

  • I want to print all the diagonal cutting characters into straight line:

Data:

E F S S A H A L L A T M C N O T S O B O D U Q H
I W I B N L O C N I L N L A N S I N G G L E B A
L R L C U Y V T P N F R A N K F O R T U R D P R
S A O B P D Y F C R V W C N O T S E L R A H C T
Q L P I Q X D V O N M Z E S I O B O E L H V V F
T E A D J L K N N O J V P Y R Y N I B B J X T O
I I N J W O C W C S W P P T T O P A A D C Q I R
G G A E C P O X O I Q U I H I N T H E E Z Z J D
V H I F C R R T R D G R C C N Y O E E N A W I A
U D D F O K E J D A N E Q A F N D E L N G Y E I
Q L N E L R L I G M K O D M R T A J E E E T L B
S E I R U F T A L A B U M O H T L W N Y C I L M
A I I S M A T J L E D Z U H N S N A A E V C I U
C F Q O B W I T U E P G X A C B M I Q H R N V L
R G D N U N L D C N E T L L R I G P T C Y O H O
A N S C S A O N E A E T N K L R R M E S H S S C
M I F I S K E S T S A A H O U R C Y I V U R A V
E R G T L D C S K P M E U B M T O L Q V U A N C
N P N Y I O U R H C F O S W R E V O D W M C O X
T S U V U G P O A A A I I E T L U A P T N I A S
O K O K U K E A T M R J N N M O N T G O M E R Y
N R P A Q N T N N R S T R D E N V E R H P Q A U
P G M K I Z A F A N O I J Z E S X P A K E P O T
X R X X C S L H G N A Y B Q M E L A S F G W B T

For Example desired output should be:
First : L1F1 character: [ Line 1 's Filed 1 ] , so to cover corner to corner as we progress.
Then : L1F2 + L2F1 [ Line 1 Field 2 + Line 2's Field 1 ]
Then : L1F3 + L2F2 + L3F1
Then : L1F4 + L2FF3 + L3F2 + L4F1
and so on ..

E
F I 
S W L
S I R S 

Thanks,

Interesting little problem! Try this:

awk     '       {for (i=1; i<=NF; i++) ALLAR [NR,i] = $i
                 for (j=NR; j>=1; j--) printf "%s ", ALLAR [NR-j+1,j]
                 printf "\n"
                }
        ' file
E 
F I 
S W L 
S I R S 
A B L A Q 
H N C O L T 
A L U B P E I 
L O Y P I A I G 
L C V D Q D N G V 
A N T Y X J J A H U 
T I P F D L W E I D Q 
M L N C V K O C F D L S 
C N F R O N C P C F N E A 
N L R V N N W O R O E I I C 
O A A W M O C X R K L R I F R 
T N N C Z J S O T E R U S Q G A 
S S K N E V W I R J L F M O D N M 
O I F O S P P Q D D I T A B N S I E 
B N O T I Y P U G A G A T W U C F R N 
O G R S O R T I R N M L J I N S I G P T 
D G T E B Y T H C E K A L T L A S T N S O 
U L U L O N O I C Q O B E U D O K L Y U K N 
Q E R R E I P N N A D U D E C N E D I V O R P 
H B D A L B A T Y F M M Z P N E S C O U K P G X 

You may want to append a loop for the descending branch - take it as an exercise!

1 Like

Thanks , RudiC very much.. , Checking ll update further.

---------- Post updated at 05:40 AM ---------- Previous update was at 05:11 AM ----------

RudiC it worked very well for the first part to print diagonal values to straight line.
I am checking next part, and then from the other side diagonals.

Thanks a lot.

---------- Post updated 04-15-13 at 01:21 AM ---------- Previous update was 04-14-13 at 05:40 AM ----------

RudiC , this is a great code in your solution in the first part, till middle portion getting diagonally fields to straight line. However I am getting hard time iterating end portion to middle portion, for the two dimensional array.

24,24
24,23 23,24
24,22 23,23 22,24
24,21 23,22 22,23 21,24
..
..
24,1 23,2 22,3 .... ...... 1,24

Can you please advise, ..

Thanks.

You've got it all there, in the ALLAR array. Introduce an END section, a loop counter, and you're there!

So - what solution did you end up with?

RudiC,
Thanks .. , Actually in the matrix there are all the name of the US states 'Capital cities' :
Example :

ATLANTA BOISE BOSTON CARSONCITY DENVER DOVER .... 

etc , I am trying to figure out their location with awk. Horizontal and Verticals are easy to compute in the matrix. However I have posted for the diagonals help.

Not yet end up with a solution yet, but the diagonal iterations are bit difficult to allginwith ALLAR [NR-j+1,j] code , both diagonal way , the solution you have given is just one way , 3 more way need to figure out , so I am still figuring it out.

Thanks...

Why do you need 3 more ways? Is this homework?

Crona688 ,
No this is not Homework. Perhaps you do not understand no one ll come up with such a bogus homework. It was my thinking to convert a crossword in a program. : ).
I made already horizontal and vertical lines to find the words ~35 out of 50 states located, remaing are hiding in the diagonal lines, Diagonal ways of crossword are tricky to match with, so I was checking for some ideas.
This was when in a place far away from my home and I was waiting 5+hrs doing nothing and someone handed me over a game paper to pass the time, I was thinking to program it. But seems it is not a good idea spending more time on it, as crosswords are meant for spending the time on that, not to be programmed. But if I spend some time I can iterate it in the other 3 sides , i am able to figured that out, from the code from RudiC. Thanks for visiting. :slight_smile:

You are probably right regarding the crosswords, but on the other hand if you can solve it with a program you will hone your programming skills, so the best solution might be to write the program first and then not to use it to solve crosswords. ;-))

I think "awk" and similar text filters are not well suited for this problem, because they generally read a file linewise from top to bottom. What you really need is a two-dimensional array of characters which you can search in every direction (not only downwards) using index-arithmetics. You can have such an array using "ksh93" or "bash" by using the substring function for the second index or you can use "perl" or similar languages (phyton, ruby, ...). Have fun programming.

I hope this helps.

bakunin

1 Like

Bakunin,
Many Thanks , I ll try with ksh93 or bash , or perl.
Python not yet experienced. 2D Array ll be helpful in this case as well . Thank you for the logic & excellent reply.