home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 3.ddi / DEMOS.DI$ / PUZZLE.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  1.9 KB  |  58 lines

  1. function puzzle(n)
  2. %PUZZLE    Mathematical riddles and MATLAB puzzles.
  3. %    puzzle(n) is the n-th puzzle.
  4. %    puzzle with no arguments picks a random one.
  5. %    All the answers can be obtained with MATLAB commands
  6. %    and functions, but we hope some are a challenge to find.
  7. %
  8. %    See also HINT.
  9.  
  10. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  11.  
  12. global ans
  13. global HINTNUM
  14.  
  15. R = ['  Zs    rWi    i     eh    it?   kam    t     Q     ehc     l '
  16.      'ocnaAeWnT?a deamttuocMte toB Ayaw i ny eheng odcMhh L  u ttaaa'
  17.      'iWm  csi o  alyh   ntio hlado ?t ox  iws e f hpc ie am   lee  '
  18.      'in    ts    ?a     h      (    is     W      f    rq    )t    '
  19.      '   bt     ai    ao     s    ?W     ic    l     a      hn     g'
  20.      'u   o au  s, d   lWe   nt ?  mmsm   paa    hr   cslt  eli    p'
  21.      'cingeWnatw de ln uys pl tor oyawlhho  a engortaihh t? u taeaso'
  22.      '  tK    jt     ao     h    ''s    eW?    is    un           hk '
  23.      '    16    ?i     W           1.     t     a      0    5s     h'
  24.      '  nudee  s y s ntamc aoho  oe ni  neott a WcM ip d  ?ouoch o t'
  25.      'cta e ?tcaa  hed m inWdn me na  ctoi  vttho   ha  oVog   nn an'
  26.      '         elob   fte   rWo   ns''   ?r u   vhi   taa   mMer   si'
  27.      '   uss    '' m   oht   eta   eetr   f     iWr   ni    ?ePb   va'];
  28.  
  29. A = ['  sro   lZe   mo    .''nn'
  30.      'c  eiaAca.nt pearbmoAgpl'
  31.      'QAZ.  s cf  iohh  t d   '];
  32.  
  33. [m,k] = size(R);
  34. if nargin == 0
  35.     c = clock;
  36.     n = fix(m*rem(c(6),1)+1);
  37. end
  38.  
  39. disp(' ')
  40. if (n >= 1) & (n <= m)
  41.   HINTNUM = n;
  42.   [ignore,j] = sort(sin(n*n+(1:k)));
  43.   disp(R(n,j));
  44.   
  45.   if ((rem(n,3) == 0) & (n <= 9))
  46.      n = n/3;
  47.      [m,k] = size(A);
  48.      [ignore,j] = sort(sin(n*n+(1:k)));
  49.      ans = A(n,j);
  50.   else
  51.      % You'll have to go hunting for the other answers.  Good luck.
  52.      ans = '';
  53.   end
  54. else
  55.   disp(['puzzle(' int2str(rem(abs(n-1),m)+1) ')'])
  56. end
  57. disp(' ')
  58.