Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / prime.ss
Created September 6, 2017 01:28
almost a primality tester
$:
(
-1
?{
[:]:,1,
_%;
}
)
@aaronryank
aaronryank / something.ss
Created September 5, 2017 20:15
simplestack program
ZYXWVUTSRQPONMLKJIHGFEDCBA"^(-(@32-);%-^)
ZYXWVUTSRQPONMLKJIHGFEDCBA push ASCII codes for the backwards alphabet
" turn stack into string
^ push string length
( open do-while loop (do ... while top of stack truthy)
- decrement string length
( do while top of stack truthy
@32 print a space
- decrement string length
) end do-while loop
@aaronryank
aaronryank / whats-my-name.bash
Last active August 1, 2017 23:51
What's my name on PPCG?
#!/bin/bash
wget https://codegolf.stackexchange.com/users/$1 2>y
sed -nr 's/.*>User (.*) -.*/\1/p' $1
rm $1 y
@aaronryank
aaronryank / forked-functions.md
Last active July 19, 2017 20:35
prototype for Forked function syntax

Functions (but probably not)

Functions are declared like so:

>>>>>function name>>>>>

with the code trailing off to the right. Functions are exited with five less-than signs.

Functions must be declared inline with code. Any code not inside a function (`>>>>>f>>>>>-----<<<<

A
. .
. B .
. . . .
. . C . .
When travelling North, the IP will jump from C to B to A.
When travelling South, the IP will jump from A to B to C.
/* 3344 bytes, not including the unnecessary newlines nor this comment. Newlines exist only for prettiness. */
#include<array>
#include<cmath>
#include<vector>
#include<string>
#include<fstream>
#include<algorithm>
#include<functional>
#define L for
#define A auto