Get 20M+ Full-Text Papers For Less Than $1.50/day. Start a 14-Day Trial for You or Your Team.

Learn More →

New problem: some diagonal fun

New problem: some diagonal fun SM_onion 5 21 22 23 24 25 20 7 8 9 10 19 6 1 2 11 18 5 4 3 12 17 16 15 14 13 New Problem: Some Diagonal Fun Let us have some fun selecting out diagonals from rank 2 and 3 arrays. It is really an exercise in using some of the lesser-used but powerful primitive APL functions. There are probably several ways to arrive at the solutions. Let’s see what we get. 1. Find the sum of the main and reverse diagonals of an arbitrary simple square numeric matrix. Only one of the common numbers is to be summed. For example with M 5 5æì25 Finally there is my rather different approach. We all noted that there were only 500 matrices since each spiral square matrix was odd. Take the integers on the diagonal and reverse diagonal and arrange them is ascending order. For a 5 by 5 matrix the values are Diagonal: 1 3 7 13 21 Reverse Diagonal: 1 5 9 17 25 Taking the differences between the adjacent integers yields Diagonal: 1 3 7 13 21 Difference: 2 4 6 8 Reverse Diagonal: 1 5 9 17 25 Difference: 4 4 8 8 The values along these diagonals can be built from the difference vectors through sum scanning. These patterns lead to the solution via the following function: [0] Z SPIRALSUM N;÷IO;D;I;R [1] äN: INTEGER SIZE OF SPIRAL MATRIX [2] äZ: SUM OF DIAG SUMS OF THE MATRIX N [3] ÷IO 1 [4] ¸(1=2|N)/L1 [5] 'N must be an odd integer' [6] ¸0 [7] L1: [8] I N-1 [9] D +\1,2õìI [10] R 2/4õì0.5õI [11] Z ý1+(+/D)++/+\1,R · SPIRALSUM 1001 669171001 SPIRALSUMþ 1,1+2õì5 1 1 25 101 261 537 The sum of the two diagonals is 117. 2. Consider a numeric rank 3 cubic array. For example, A3 4 4 4æì64. If one starts from the four corners of the first (front) plane, four diagonals can be created that penetrate the cube. Write an expression for each of these diagonals. For the above array A3, the starting numbers would be 1, 4, 13, and 16, and the four diagonal values would be: 3. Actually there many other diagonals that one could extract from a cubic array. How many unique diagonals can one derive from a cubic array? Do not count ones that wrap around. Just count the diagonals starting with corner points and points on the edges of the cube. These problems are meant to have a little APL fun. However, if any reader has a real life application needing the extraction of any such diagonals, we would like to hear of it. There you have a summary of the various submissions. It looks like this was a problem with which several had fun. We always welcome further comments and solutions. December 2007, Volume 35, Number 4 http://www.deepdyve.com/assets/images/DeepDyve-Logo-lg.png ACM SIGAPL APL Quote Quad Association for Computing Machinery

New problem: some diagonal fun

ACM SIGAPL APL Quote Quad , Volume 35 (4) – Dec 1, 2007

Loading next page...
 
/lp/association-for-computing-machinery/new-problem-some-diagonal-fun-70gTisFND3

References

References for this paper are not available at this time. We will be adding them shortly, thank you for your patience.

Publisher
Association for Computing Machinery
Copyright
Copyright © 2007 by ACM Inc.
ISSN
0163-6006
DOI
10.1145/1354923.1354928
Publisher site
See Article on Publisher Site

Abstract

SM_onion 5 21 22 23 24 25 20 7 8 9 10 19 6 1 2 11 18 5 4 3 12 17 16 15 14 13 New Problem: Some Diagonal Fun Let us have some fun selecting out diagonals from rank 2 and 3 arrays. It is really an exercise in using some of the lesser-used but powerful primitive APL functions. There are probably several ways to arrive at the solutions. Let’s see what we get. 1. Find the sum of the main and reverse diagonals of an arbitrary simple square numeric matrix. Only one of the common numbers is to be summed. For example with M 5 5æì25 Finally there is my rather different approach. We all noted that there were only 500 matrices since each spiral square matrix was odd. Take the integers on the diagonal and reverse diagonal and arrange them is ascending order. For a 5 by 5 matrix the values are Diagonal: 1 3 7 13 21 Reverse Diagonal: 1 5 9 17 25 Taking the differences between the adjacent integers yields Diagonal: 1 3 7 13 21 Difference: 2 4 6 8 Reverse Diagonal: 1 5 9 17 25 Difference: 4 4 8 8 The values along these diagonals can be built from the difference vectors through sum scanning. These patterns lead to the solution via the following function: [0] Z SPIRALSUM N;÷IO;D;I;R [1] äN: INTEGER SIZE OF SPIRAL MATRIX [2] äZ: SUM OF DIAG SUMS OF THE MATRIX N [3] ÷IO 1 [4] ¸(1=2|N)/L1 [5] 'N must be an odd integer' [6] ¸0 [7] L1: [8] I N-1 [9] D +\1,2õìI [10] R 2/4õì0.5õI [11] Z ý1+(+/D)++/+\1,R · SPIRALSUM 1001 669171001 SPIRALSUMþ 1,1+2õì5 1 1 25 101 261 537 The sum of the two diagonals is 117. 2. Consider a numeric rank 3 cubic array. For example, A3 4 4 4æì64. If one starts from the four corners of the first (front) plane, four diagonals can be created that penetrate the cube. Write an expression for each of these diagonals. For the above array A3, the starting numbers would be 1, 4, 13, and 16, and the four diagonal values would be: 3. Actually there many other diagonals that one could extract from a cubic array. How many unique diagonals can one derive from a cubic array? Do not count ones that wrap around. Just count the diagonals starting with corner points and points on the edges of the cube. These problems are meant to have a little APL fun. However, if any reader has a real life application needing the extraction of any such diagonals, we would like to hear of it. There you have a summary of the various submissions. It looks like this was a problem with which several had fun. We always welcome further comments and solutions. December 2007, Volume 35, Number 4

Journal

ACM SIGAPL APL Quote QuadAssociation for Computing Machinery

Published: Dec 1, 2007

There are no references for this article.