Skip to content

Instantly share code, notes, and snippets.

View primo-ppcg's full-sized avatar

primo-ppcg

  • Thailand
  • 23:36 (UTC +07:00)
View GitHub Profile
@primo-ppcg
primo-ppcg / bottles-nw.bf
Last active October 29, 2017 23:10
brainfuck 99 bottles of beer
; 99 bottles of beer in 835 instructions
; Author: Mike Tryczak (aka primo)
;
; Complete lyrics version
; byte sequence
; \n _ _ _ _ d \n comma space d o t l T
>++++++++++>>
>->+>----->--->---->+>++>++>++
>+[+++++[>++++++++++++++<-]<+]
@primo-ppcg
primo-ppcg / bf2c.pl
Last active April 2, 2019 07:34
brainfuck to C transpiler
#!/usr/bin/perl -p
# bf2c.pl
# a primitive brainfuck to C transpiler
#
# usage: perl bf2c.pl program.bf | gcc -O2 -o program -xc -
BEGIN {
%w = qw(
@primo-ppcg
primo-ppcg / hello.pasm
Created April 24, 2021 06:27
A rudimentary interpreter for a stack-based language with Piet-like commands.
#72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33
nop
push 3
dup
add
dup
mul
dup
dup
module builtin
[static]
fn is_atty(fd int) int
fn vcalloc(n int) byteptr
fn v_realloc(b byteptr, n int) byteptr
fn v_calloc(n int) byteptr
fn utf8_getchar() int
(use spork/test)
(use spork/misc)
(use spork/math)
(def- small-primes
"primes less than 212"
[2 3 5 7 11 13 17 19 23 29 31 37
41 43 47 53 59 61 67 71 73 79 83 89
97 101 103 107 109 113 127 131 137 139 149 151
157 163 167 173 179 181 191 193 197 199 211])
(defmacro timeit
``Similar to `loop`, but outputs performance statistics after completion.``
[head & body]
(with-syms [clk cnt elp run]
~(do
(var ,cnt 0)
(def ,clk (os/clock))
(loop ,head (++ ,cnt) ,;body)
(def ,elp (- (os/clock) ,clk))
(def ,run (/ ,elp ,cnt))
@primo-ppcg
primo-ppcg / cmath.c
Created July 19, 2023 12:38
cmath.c
/*
* Copyright (c) 2023 Calvin Rose
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
(use spork/test)
(use spork/math)
(def pseudoprimes
[1373653
1530787
1987021
2284453
3116107
5173601