Jump to content

Tom Johnson / Pascal's Triangle Modulo Seven ... and more


Recommended Posts

here is a short program (based on JOHNSON's writing... pascal-code found in www and modified) to generate TOM JOHNSON's series of numbers for "pascal's triangle ...".

 

maybe interesting to play with the MODULO like JOHNSON did (mod 7)... try it!

 

greetings

andré

 

;;; SUB
(defun pascal-next-row (a &key (johnson-modulo nil))
    (loop :for q :in a
          :and p = 0 :then q
          :as s = (if (null johnson-modulo)
                    (list (+ p q))
                    (list (mod (+ p q) johnson-modulo)))
          :nconc s :into a
          :finally (rplacd s (list 1))
                  (return a)))
 
;;; MAIN
(defun pascal-triangle (n &key (johnson-modulo nil))
    (loop :for a = (list 1) :then (pascal-next-row a :johnson-modulo johnson-modulo)
          :repeat n
          :collect a))


;;; => pascal-triangle 
(pascal-triangle 7)
=> ((1) (1 1) (1 2 1) (1 3 3 1) (1 4 6 4 1) (1 5 10 10 5 1) (1 6 15 20 15 6 1))

;;; => pascal-triangle with MODULO like tom johnson in PASCAL'S TRIANGLE MODULO SEVEN
(pascal-triangle 21 :johnson-modulo 7)
=> ((1) (1 1) (1 2 1) (1 3 3 1) (1 4 6 4 1) (1 5 3 3 5 1) (1 6 1 6 1 6 1) (1 0 0 0 0 0 0 1) (1 1 0 0 0 0 0 1 1) (1 2 1 0 0 0 0 1 2 1) (1 3 3 1 0 0 0 1 3 3 1) (1 4 6 4 1 0 0 1 4 6 4 1) (1 5 3 3 5 1 0 1 5 3 3 5 1) (1 6 1 6 1 6 1 1 6 1 6 1 6 1) (1 0 0 0 0 0 0 2 0 0 0 0 0 0 1) (1 1 0 0 0 0 0 2 2 0 0 0 0 0 1 1) (1 2 1 0 0 0 0 2 4 2 0 0 0 0 1 2 1) (1 3 3 1 0 0 0 2 6 6 2 0 0 0 1 3 3 1) (1 4 6 4 1 0 0 2 1 5 1 2 0 0 1 4 6 4 1) (1 5 3 3 5 1 0 2 3 6 6 3 2 0 1 5 3 3 5 1) (1 6 1 6 1 6 1 2 5 2 5 2 5 2 1 6 1 6 1 6 1))

;;; look!!

(list-plot (flatten (pascal-triangle 50 :johnson-modulo 7))
           :point-radius 0 :style :fill)

(list-plot (flatten (pascal-triangle 50 :johnson-modulo 11))
           :point-radius 0 :style :fill)

(list-plot (flatten (pascal-triangle 80 :johnson-modulo 17))
           :point-radius 0 :style :fill)

(list-plot (flatten (pascal-triangle 50 :johnson-modulo 3))
           :point-radius 0 :style :fill)

;;; rnd-testing
(list-plot (flatten (pascal-triangle 80 :johnson-modulo (1+ (random 23))))
           :point-radius 0 :style :fill)

 

 

 

Link to comment
Share on other sites

listen to the processes...

 

(make-omn :pitch (integer-to-pitch (pascal-triangle 50 :johnson-modulo (1+ (random 23))))
          :length '(t)
          :span :pitch)

 

an example with parallel processes (chordized)..


(setf chordlist (loop 
                  for i in (flatten (integer-to-pitch (pascal-triangle 20 :johnson-modulo (1+ (random 23)))))
                  for j in (flatten (integer-to-pitch (pascal-triangle 20 :johnson-modulo (1+ (random 23)))))
                  for k in (flatten (integer-to-pitch (pascal-triangle 20 :johnson-modulo (1+ (random 23)))))
                  append (chordize (list i j k))))



(make-omn :pitch chordlist
          :length '(t)
          :span :pitch)

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

Terms of Use Privacy Policy