after coffee

Q&A's, tips, howto's
Post Reply
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

after coffee

Post by newdep »

..just to keep the brain awake...
http://newlisp.digidep.net/magic.lsp

Code: Select all

;
; 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))

Post Reply