home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c      Meh, in C you gotta define EVERYTHING      243,370 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 243,370 of 243,370   
   DFS to Bart   
   Re: Sort of trivial code challenge - may   
   06 Mar 26 22:14:15   
   
   From: nospam@dfs.com   
      
   On 3/6/2026 4:53 PM, Bart wrote:   
   > On 06/03/2026 17:11, DFS wrote:   
   >> On 3/6/2026 11:02 AM, Bart wrote:   
   >>   
   >>> I assume it works according to the spec, where I admit I don't fully   
   >>> understand the conditions. So input of '10 10 90' is fine (prints   
   >>> 1-90 within 10x10 matrix) omits final column), but input of '90'   
   >>> fails, even though it's the same square matrix.   
   >>   
   >>   
   >> The condition is "Can a square matrix contain only 1-N?"   
   >>   
   >> Only a non-square matrix of 10x9 or 9x10 can contain 1-90.   
   >>   
   >> Only a square matrix of 10x10 can contain 1-91.   
   >>   
   >   
   > I still don't get it. Doesn't an input of '10 10 90' specify a square   
   > matrix? But it still prints the numbers 1-90:   
   >   
   >   c:\cx>t 10 10 90                      # run LP's   
   program   
   >   1  11 21 31 41 51 61 71 81   
   >   2  12 22 32 42 52 62 72 82   
   >   3  13 23 33 43 53 63 73 83   
   >   4  14 24 34 44 54 64 74 84   
   >   5  15 25 35 45 55 65 75 85   
   >   6  16 26 36 46 56 66 76 86   
   >   7  17 27 37 47 57 67 77 87   
   >   8  18 28 38 48 58 68 78 88   
   >   9  19 29 39 49 59 69 79 89   
   >   10 20 30 40 50 60 70 80 90   
      
      
   That's a 10x9 matrix.   
      
      
      
   > But this fails:   
   >   
   >   c:\cx>t 90   
   >   Cut off value 90 not possible where rows=cols   
   >   Usage:  t #_rows #_cols [ cut-off ]   
   >   or      t cut-off   
   >   
   > This second invocation couldn't print 1-90 within a 10x10 matrix, but   
   > the first one could. Or is that first one not considered square; it's a   
   > rectangle where height and width happen to be the same?   
      
      
   Every number N can be contained *somewhere within* a square matrix.   
      
   But the question is: is there a 'row equals columns' matrix that can   
   contain *only* 1 thru N.   
      
   For 90 that answer is no.  Only matrices where row != column stop at 90.   
      
   r  c   
   1  90   
   2  45   
   3  30   
   4   
   5  18   
   6  15   
   7   
   8   
   9  10   
   10  9   
      
      
   For 91 the answer is Yes: it is possible to construct a rows=columns   
   matrix containing only 1-91.   
      
   ------------------------------   
      1  2  3  4  5  6  7  8  9 10   
   ------------------------------   
      1 11 21 31 41 51 61 71 81 91   
      2 12 22 32 42 52 62 72 82   
      3 13 23 33 43 53 63 73 83   
      4 14 24 34 44 54 64 74 84   
      5 15 25 35 45 55 65 75 85   
      6 16 26 36 46 56 66 76 86   
      7 17 27 37 47 57 67 77 87   
      8 18 28 38 48 58 68 78 88   
      9 19 29 39 49 59 69 79 89   
     10 20 30 40 50 60 70 80 90   
      
      
   I think your initial BartScript code got it exactly right, using a   
   simple formula.   
      
      
   For another view:   
      
   Input   Sqr Matrix?    sqrt(Input)   
   ----------------------------------   
       1    possible        1.00   
       2    not possible    1.41   
       3    possible        1.73   
       4    possible        2.00   
       5    not possible    2.24   
       6    not possible    2.45   
       7    possible        2.65   
       8    possible        2.83   
       9    possible        3.00   
      10    not possible    3.16   
      11    not possible    3.32   
      12    not possible    3.46   
      13    possible        3.61   
      14    possible        3.74   
      15    possible        3.87   
      16    possible        4.00   
      17    not possible    4.12   
      18    not possible    4.24   
      19    not possible    4.36   
      20    not possible    4.47   
      21    possible        4.58   
      22    possible        4.69   
      23    possible        4.80   
      24    possible        4.90   
      25    possible        5.00   
      26    not possible    5.10   
      27    not possible    5.20   
      28    not possible    5.29   
      29    not possible    5.39   
      30    not possible    5.48   
      31    possible        5.57   
      32    possible        5.66   
      33    possible        5.74   
      34    possible        5.83   
      35    possible        5.92   
      36    possible        6.00   
      37    not possible    6.08   
      38    not possible    6.16   
      39    not possible    6.24   
      40    not possible    6.32   
      41    not possible    6.40   
      42    not possible    6.48   
      43    possible        6.56   
      44    possible        6.63   
      45    possible        6.71   
      46    possible        6.78   
      47    possible        6.86   
      48    possible        6.93   
      49    possible        7.00   
      50    not possible    7.07   
      51    not possible    7.14   
      52    not possible    7.21   
      53    not possible    7.28   
      54    not possible    7.35   
      55    not possible    7.42   
      56    not possible    7.48   
      57    possible        7.55   
      58    possible        7.62   
      59    possible        7.68   
      60    possible        7.75   
      61    possible        7.81   
      62    possible        7.87   
      63    possible        7.94   
      64    possible        8.00   
      65    not possible    8.06   
      66    not possible    8.12   
      67    not possible    8.19   
      68    not possible    8.25   
      69    not possible    8.31   
      70    not possible    8.37   
      71    not possible    8.43   
      72    not possible    8.49   
      73    possible        8.54   
      74    possible        8.60   
      75    possible        8.66   
      76    possible        8.72   
      77    possible        8.77   
      78    possible        8.83   
      79    possible        8.89   
      80    possible        8.94   
      81    possible        9.00   
      82    not possible    9.06   
      83    not possible    9.11   
      84    not possible    9.17   
      85    not possible    9.22   
      86    not possible    9.27   
      87    not possible    9.33   
      88    not possible    9.38   
      89    not possible    9.43   
      90    not possible    9.49   
      91    possible        9.54   
      92    possible        9.59   
      93    possible        9.64   
      94    possible        9.70   
      95    possible        9.75   
      96    possible        9.80   
      97    possible        9.85   
      98    possible        9.90   
      99    possible        9.95   
     100    possible        10.00   
      
   Look at the square roots, and you'll see a pattern that determines   
   whether the square matrix is possible or not.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca