after coffee

Started by newdep, December 24, 2021, 02:46:34 PM

Previous topic - Next topic

newdep

..just to keep the brain awake...

http://newlisp.digidep.net/magic.lsp">//http://newlisp.digidep.net/magic.lsp



;
; Magic (odd, not even) square solver by nodep.
;
;     0   1   2  
;   ------------+
; 0 | a | c | b |
;   |-----------|  
; 1 | d | e | f |
;   |-----------|
; 2 | g | h | i |
;   +-----------+    
;
; The trick..
;          ..is very simple
;

 ;;-- 1..9
 ;;(setq numbers (sequence 1 9))

 ;;-- 4096..5104
 (setq numbers (sequence 4096 5104))
 
 ;;-- determine the middle
 (setq middle (numbers 4))

 ;;-- calculate the sum
 (setq sum (add (numbers 0) (numbers -1) middle))

 ;;-- listy 3x3 square
 (setq s '( () () () ))

 ;;-- solve
 (push middle (s 1))
 (push (numbers  0) (s 0))
 (push (numbers -1) (s 2))
 (push (numbers  1) (s 2) -1)
 (push (numbers -2) (s 0))    
 (push (numbers  2) (s 1))
 (push (numbers -3) (s 1) -1)
 (push (numbers  3) (s 2))
 (push (numbers -4) (s 0) -1)
 
 ;;-- display
 (println "The Magic = " sum)
 (map println (map string s))
 
 ;;-- Enjoy.. ;-)
 
 (exit)
 
-- (define? (Cornflakes))