Skip to content
View in the app

A better way to browse. Learn more.

Opusmodus

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Multi-state Cellular Automata

Featured Replies

I'm new to Opusmodus and Lisp programming. It will be awhile before I can implement some of the ideas that I have. In the meantime I've discovered that the Opusmodus GPT can do some programming for me. Here are two functions that it generated for me. A one dimensional totalistc CA with an arbitrary number of states, and a function to generate random rule sets. It took some prompting to get them to this stage. Totalistic CA rules are symmetrical, so if your initial state is a palindrome all generations will be.

 

(defun totalistic-cellular-automaton (states rules initial-state generations)
  "Generates a multi-state totalistic cellular automaton.
   STATES: the number of possible states (e.g., 0, 1, 2, ...).
   RULES: a list of rules that map the sum of neighborhood states to a new state.
   INITIAL-STATE: a list representing the initial state of the automaton.
   GENERATIONS: the number of generations to evolve.
   Returns a list of all generations."
  (let* ((length (length initial-state))  ; Calculate the length from the initial-state
         (current-state initial-state)
         (next-state (make-list length))
         (all-generations (list current-state))) ; Initialize list with initial state
    (loop for gen from 1 to (1- generations)
          do (progn
               (loop for i from 0 below length
                     do (let* ((left (nth (mod (- i 1) length) current-state))  ; Left neighbor (wrap-around)
                               (center (nth i current-state))                 ; Current cell
                               (right (nth (mod (+ i 1) length) current-state)) ; Right neighbor (wrap-around)
                               (neighborhood-sum (+ left center right)))      ; Calculate the sum of neighbors
                          ;; Apply the totalistic rule based on the neighborhood sum
                          (setf (nth i next-state) (nth neighborhood-sum rules))))
               ;; Append the new state to the list of all generations
               (push (copy-list next-state) all-generations)
               ;; Move to the next state
               (setf current-state (copy-list next-state))))
    ;; Return the list of all generations
    (reverse all-generations)))  ; Return in the correct order

(defun generate-random-rule-set (states &key seed)
  "Generates a random rule set for a totalistic cellular automaton with the given number of STATES.
   The rule set maps sums (from 0 to 3 * (states - 1)) to a random state.
   The SEED parameter allows reproducibility of random output."
  (let ((max-sum (* 3 (1- states))))
    ;; Generate the entire rule set in one go using rndn with the seed parameter
    (rndn (1+ max-sum) 0 (1- states) :seed seed)))  ;; Generate integers between 0 and states-1

;; usage
(setf states 8)
(setf rule (generate-random-rule-set states :seed 12))
(totalistic-cellular-automaton states rule '(0 1 2 7 7 2 1 0) 4)
=> ((0 1 2 7 7 2 1 0)
    (7 3 6 2 2 6 3 7)
    (2 2 6 6 6 6 2 2)
    (3 6 7 4 4 7 6 3))

 

Create an account or sign in to comment


Copyright © 2014-2026 Opusmodus™ Ltd. All rights reserved.
Product features, specifications, system requirements and availability are subject to change without notice.
Opusmodus, the Opusmodus logo, and other Opusmodus trademarks are either registered trademarks or trademarks of Opusmodus Ltd.
All other trademarks contained herein are the property of their respective owners.

Powered by Invision Community

Important Information

Terms of Use Privacy Policy

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.