Skip to content

Instantly share code, notes, and snippets.

@apaap
apaap / lca.py
Last active November 7, 2019 09:58
Simulator for ECA rules 18, 90, and 150
class LCA:
"""Simulate the Linear CA (XOR CA rule) known as Rule 90 on a circular grid
Usage: l = LCA(width) OR l = LCA(width, rule)
where width is an integer > 1 and rule is one of [18, 90, 150]"""
maxbuf = 8
def __init__(self, width, rule=90):
if rule == 18:
self.stepfun = LCA.step18
@apaap
apaap / p392_pairs.py
Last active November 4, 2019 05:16
c/98 spaceship generator for Omosso
#p392_pairs.py
# c/98 spaceship generator
# Usage: python p392_pairs.py [<start> [<stop>]]
# where <start> is the starting value and <stop> is the final value for the
# phase of the LHS (default is 0 <= phase < 196)
#
# Example usage with apgluxe:
# $ cd apgmera
# $ ./recompile.sh --rule b2k3acijr4ijqy6i7cs2aek3ijnqr4it5n --symmetry stdin_c98_pairs
# $ mv apgluxe apgluxe-stdin_c98_pairs
@apaap
apaap / sort-collisions.py
Last active December 9, 2019 08:51
Filter glider collisions and output in format used by synthesise-constellation.py
#sort-collisions.py
# Read in unsorted glider collisions lines from all files on command line
# Output sorted collisions to first file in synthesise-constellation.py format
# Collisions are in a modified version of Shinjuku's component format:
# - single line containing apgcode of output constellation, followed by
# - multiple lines containing components producing that constellation with
# the out_apgcode omitted
# Input files can be in either format
# For Python3 print function
@apaap
apaap / 4Gconstellation-gsets.py
Last active December 9, 2019 08:46
Generate 4G collisions which result in constellations of stationary objects (p1, p2, p3, or p6)
#4Gconstellation-gsets.py
"""Generate a batch of 4 glider collisions and report those which result
in stable constellations. Converts collisions to Shinjuku's gliderset format
and outputs comp lines. This version generates a subset of 4G collisions for
use with synthesise-constelation.py v2.0
Usage:
$ python 4Gconstellation-gsets.py > <compfile>.sjk
Based on popseq.c by Chris Cain
Includes a (slightly modified) version of shinjuku/glidersets.py and the
@apaap
apaap / 4Gconstellations.cpp
Last active October 12, 2019 16:06
Generate 4G collisions which result in constellations of stationary objects (p1, p2, p3, or p6)
#include <iostream>
#include <cstring>
#include "LifeAPI.h"
int main(int argc, char *argv[]) {
int pops[16], allpops[256];
char s[1024], line[1024];
s[0] = 0;
@apaap
apaap / count_active.py
Created October 10, 2019 08:29
# Python script for Golly to count active cells within the envelope of a moving pattern
#count_active.py
# Count active cells within the envelope of a moving pattern
import golly as g
import numpy as np
r = g.getrect()
if not r:
g.exit('No pattern')
patt = g.getcells(r)
@apaap
apaap / make_lls_grid.py
Last active August 9, 2019 08:40 — forked from vyznev/make_lls_grid.py
Generate Logic Life Search (LLS) input grid for finding spaceships and oscillators, with additional features not yet supported natively by LSS (like strobing background and gradually moving search area).
#!/usr/bin/python
import re
import sys
import argparse
def fail(msg):
sys.stderr.write(sys.argv[0] + ": " + msg + "\n")
sys.exit(1)
@apaap
apaap / sssViewer.py
Last active July 31, 2019 06:09
A rudimentary sss pattern viewer for Golly
# sssViewer.py v0.3
# Golly Python script to peview patterns in sss format
# Author: Arie Paap
import re
import time
from timeit import default_timer as timer
import golly as g
# Check if pattern is in view and shift view / resize if necessary
@apaap
apaap / README.txt
Last active October 10, 2019 09:28
Random state distribution rule
# Random State Distribution
A rule generator for Golly to create a random state distributor rule
The rule is intended to convert a two state random soup pattern into an n-state random soup. The rule has (n+1)-states where the additional state is state 1. All state 1 cells will become cells with state 2 -> n after the first generation, with the resulting state being dependent on the neighbourhood configuration of the cell.
This could potentially be used with apgsearch to generate multi-state soups in rules where 2-sate soups don't show the full dynamics of the rule.
This project contains three separate files:
- rand_state_distribution.py
A Golly Python script to generate a rule file (can be run from clipboard).
- test_rand_state_distribution.py