Skip to content

Instantly share code, notes, and snippets.

View patham9's full-sized avatar

Patrick Hammer patham9

View GitHub Profile
@patham9
patham9 / airis.py
Last active December 27, 2023 17:28
Berick Cook's AIRIS replicated by Patrick Hammer from his video and discussions with him.
from collections import deque
from copy import deepcopy
import sys
import time
import random
# THE WORLD
world = """
oooooooooooo
o o f o
@patham9
patham9 / parallel-amb.scm
Last active November 30, 2023 18:51
Parallel amb (Chicken Scheme)
(define-syntax amb-parallel
(syntax-rules ()
((_ arg1 arg2)
(receive (pipefd0 pipefd1) (create-pipe)
(let ((pid (process-fork)))
(if (eq? pid 0)
(let ((pipefd1_port (open-output-file* pipefd1)))
(write (amb-collect arg2) pipefd1_port) ;we can't backtrack into parent so we collect all of this level's results
(close-output-port pipefd1_port)
(exit 0)) ;child is done
@patham9
patham9 / parallel-list.scm
Last active November 30, 2023 18:17
Parallel list (Chicken Scheme)
(import (chicken process) (chicken file posix))
(define-syntax parallel-list
(syntax-rules ()
((_ arg1 arg2)
(receive (pipefd0 pipefd1) (create-pipe)
(let ((pid (process-fork)))
(if (eq? pid 0)
(begin (write arg1 (open-output-file* pipefd1))
(exit 0)) ;child is done
@patham9
patham9 / parallel-amb.scm
Last active November 30, 2023 18:05
Parallel amb
(import (chicken process) (chicken string) (chicken file posix) amb)
(define-syntax amb-parallel
(syntax-rules ()
((_ arg1 arg2)
(let-values (((pipefd0 pipefd1) (create-pipe)))
(let ((pid (process-fork)))
(begin (if (eq? pid 0)
(begin (file-write pipefd1 (string-append (->string arg1) "\n"))
(exit 0)) ;child is done
@patham9
patham9 / gist:9af1fb750ed37dd3b0c31c3740e7ccd9
Last active November 7, 2023 18:52
Mettamorph speedup (Processor: 1,6 GHz Dual-Core Intel Core i5, OS: macOS Monterey)
python3 timing.py
Starting 4 tests with 10 runs each, grab a coffee!
==
Compilation started.
Compilation complete.
TEST: !(factorial 30)
[265252859812191058636308480000000]
[265252859812191058636308480000000]
........
Time MeTTa: avg=3.9196492433547974 seconds, var=0.019423207564014434
(! (add-atom '&self ('coffee 'moka)))
(! (add-atom '&self ('coffee 'turkish)))
(= (myMultiFunction 'moka) ('moka 'good))
(= (myMultiFunction 'moka) ('moka 'excellent))
(! (Let w (superpose ('big 'small myMultiFunction))
(Match '&self ('coffee x) (w x))))
Output:
;[((big turkish)), ((big moka)), ((small turkish)), ((small moka)), ((moka excellent)), ((moka good))]
(coffee moka)
(coffee turkish)
(coffee expresso)
(coffee cappuccino)
(coffee latte)
!(match &self (coffee $1) $1)
(define %coffee
(%rel ()
[('moka)]
[('turkish)]
[('expresso)]
[('cappuccino)]
[('latte)]))
(define (test data)
(if data
@patham9
patham9 / gist:d8615121e1b5c1f18a7c66be34ab5b23
Created October 28, 2023 07:26
Simple dll usage (never use dlopen if your program just needs to load the library at startup!!)
/* add.c */
#include <stdio.h>
float add(float a, float b) { return a + b; }
//gcc -shared -o libadd.so add.c -fPIC
/* main.c */
#include <stdio.h>
extern float add(float a, float b);
int main() { printf("Result: %f\n", add(3.0, 4.0)); return 0; }
//gcc main.c -L. -ladd
(let ((r392874
(##core#inline_allocate
("C_a_i_list3" 9)
'Sentence
r393386
r393390)))
(let ((r393221
(##core#inline_allocate
("C_a_i_list2" 6)
'ExtSet