Skip to content

Instantly share code, notes, and snippets.

View aaronryank's full-sized avatar

aaron ryan aaronryank

View GitHub Profile
@aaronryank
aaronryank / operations.bit
Last active December 28, 2017 19:14
arithmetic via bitwise operations
COMMENT add $1 and $2 into $3
.ADD:
LABEL &1
AND $1 $2 *1
XOR $1 $2 $1
SL *1 &1 $2
JMP @1 $2
RET $1
COMMENT increment $1 into $2
@aaronryank
aaronryank / gaussian-distribution.bas
Last active September 29, 2017 00:33
gaussian distribution in Applesoft BASIC (golf)
0TEXT:HOME:INPUTN:HGR:HCOLOR=3:W=279:H=159:L=W-100:Z=L/10:B=H-100:C=H-60:K=0.5:M=1/(2*3.14159265*N*N):FORI=0TO10STEPK:X=10*I+1:Y=10*I+B:HPLOTX,Y:FORJ=0TOL STEP1:O=10*J/L:D=ABS(5-I):E=ABS(5-O):R=(D*D+E*E)/(2*N*N):G=EXP(-R)*M:A=INT((C*G)/M):X=10*I+Z*O+1:Y=10*I+B-A:HPLOTTOX,Y:IF(I=0)GOTO4
1IF(J=L)GOTO3
2V=INT(J/10):IF((J/10)<>V)GOTO5
3D=ABS(5-I+K):E=ABS(5-O):R=(D*D+E*E)/(2*N*N):U=EXP(-R)/(2*3.14159*N*N):S=INT((C*U)/M):P=10*(I-K)+Z*O+1:Q=10*(I-K)+B-S:HPLOT TOP,Q:HPLOTX,Y
4IF(J=0)GOTO7:IF(I<10)GOTO5:IF(J=L)GOTO6:V=INT(J/10):IF((J/10)=V)GOTO6
5HCOLOR=0
6HPLOTTOX,10*I+B:HCOLOR=3:HPLOTX,Y
7NEXTJ:NEXTI:HPLOTW+1,H:HPLOTTO101,H:HPLOTTO0+1,H
@aaronryank
aaronryank / interpreter.c
Last active October 4, 2017 01:35
bitwise interpreter - now with working functions
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <ctype.h>
enum { TYPE_NEG = -1, TYPE_REG = 0, TYPE_FRAME_REG = 1, TYPE_LITERAL = 2, TYPE_LABEL = 3, TYPE_REF = 4, TYPE_ARG = 5 };
int exec_cmd(char *, char *, char *, char *);
int type(char *);
@aaronryank
aaronryank / popularity-contest.md
Last active October 4, 2017 04:09
A draft for a pop-con on PPCG SE

Design a One Instruction Set Computer

Yes, it's a [tag:popularity-contest]. Please read the entire question before downvoting or close-voting. The three headers make up the spec, and the bullet points below them make up the rules.

Your challenge is to design a [one instruction set computer][1] (OISC):

An [OISC] is an abstract machine that uses only one instruction – obviating the need for a machine language opcode. With a judicious choice for the single instruction and given infinite resources, an OISC is capable of being a universal computer in the same manner as traditional computers that have multiple instructions.

For the purposes of this challenge, an OISC is a [Turing-complete][2] programming language with a single command that takes at least one argument. It must take at least one argument to prevent it from being a [ZISC][5] or a [Lenguage][6]-equivalent.. You may take as many arguments as you want, as long as rule #1 is followed.

@aaronryank
aaronryank / simple-tc-languages.md
Last active October 3, 2017 04:19
Turing-complete esoteric languages that are easily to implement -- for https://gist.github.com/aaronryank/5eff98fe13c4d05c091982daa56d0c23

Subtract and branch if less than or equal to zero (SUBLEQ)

Subtract the contents of address a from the contents of address b, store the result in address b, and if the result is non-positive, transfer control to address c. If the result is positive, execution continues to the next instruction in the code. So subleq a, b, c would be equivalent to:

mem[b] -= mem[a];
if (mem[b] <= 0)
    goto c;

A variant of subleq is subneg, which is equivalent to subleq except instead of mem[b] <= 0 it performs mem[b] < 0.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <limits.h>
// Sort it like a human!
// O(2n)
void humansort(int **list, int size)
{
@aaronryank
aaronryank / setup.bash
Last active December 8, 2017 03:16
Set up a new PC/workstation: wget -qO- https://xf-technologies.github.io/setup | xargs wget
#!/usr/bin/env bash
# test internet connection
wget -q --spider http://google.com
if [ ! $? -eq 0 ]; then
echo "No internet connection, exiting..."
exit $?
fi
@aaronryank
aaronryank / quine.exe
Last active December 7, 2017 04:08
Windows Executable error quine
The version of this file is not compatible with the version of Windows you're running. Check your computer's system information to see whether you need an x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher.
@aaronryank
aaronryank / oeis.bash
Last active December 21, 2017 01:47
Downloads all OEIS sequence lists and formats them into C arrays
#!/usr/bin/env bash
# Downloads all OEIS sequence lists and formats them into C arrays
for i in `seq 1 296700`; do
printf -v s "A%.6d" $i
echo $s >/dev/stderr
echo -n "long long int $s[] = {"
wget -qO- https://oeis.org/$s/list | tr -d '\n' | sed 's/^.*<pre>/<pre>/' | cut -c 7- | cut -f1 -d"]" | tr -d '\n'
echo "};"
done