Skip to content

Instantly share code, notes, and snippets.

@yshl
yshl / crc-16.bf
Last active December 11, 2015 09:28
-> # dec{0} @1
++++[->++++<]> # {2}=16 @2
[-[->>+<<]>>] # @34
->> # dec{34} @36
, # {36}=getchar()
+[- # while({36}!=neg 1){
<++++++++ # {35}=8 @35
[ # while({35}){
-> # dec{35} @36
[ # while({36}){
-> # dec{0} @1
++++[->++++<]> # {2}=16 @2
[-<+>[->>+<<]>>] # {1::31::2}=1 @34
-> # dec{34} @35
, # {35}=getchar()
+[- # while({35}!=EOF)
# p=35
[ # while({p#0})
# {p#1}={p#0}%2 {p#2}={p#0}/2
[ # while({p#0}){
@yshl
yshl / fizzbuzz-1.scm
Last active December 19, 2015 17:39
FizzBuzz in Scheme
(define (fizzbuzz n c)
((lambda(d m g)
(g g 1
(lambda(l)
(m m l
(lambda(i c)
(d i 15
(lambda(b)
(if b
(c "FizzBuzz")
@yshl
yshl / Makefile
Last active December 19, 2015 18:29
test of loop unrolling for matrix vector product in D
CC=gcc
CFLAGS=-Wall -O3 -march=native
DC=dmd
DFLAGS=-O -release -inline -m64
PROG=gemv1_c gemv2_c gemv3_c gemv4_c gemv1_d gemv2_d gemv3_d gemv4_d
all: $(PROG)
gemv1_c: gemv1_c.c
@yshl
yshl / bfi-0.c
Created July 27, 2013 17:11
Brainfuck Interpreter. bfi-0.c : ',' doesn't change memory cells at EOF. bfi-1.c : ',' returns -1 at EOF.
c['~~'];d['~~'];*p=d;n;main(i,a,q)char**a,*q;{for(read(open(a[1],0),q=c,-1);*q;n<0?q--:q++)i=*q-44,i-49?i-47?n?0:i-2?p+=i-16?i?*p-=~i?i==1:i:read(0,p,1),i==18:-1:putchar(*p):(n+=!!n)|*p||n++:n--;}
@yshl
yshl / Makefile
Last active May 1, 2019 01:36
Ping
CC=gcc
CFLAGS=-Wall -g -O2
all: ping
ping: ping.o
$(CC) $(CFLAGS) -o $@ $^
ping.o: ping.c
@yshl
yshl / crc32quine.c
Last active August 29, 2015 14:15
Search CRC-32 Quine
#include<stdio.h>
#include<stdint.h>
#ifdef CAPITAL
#define CHAR_A 'A'
#define FORMAT "%08X\n"
#else
#define CHAR_A 'a'
#define FORMAT "%08x\n"
#endif
@yshl
yshl / aaa_parser.rb
Last active May 15, 2016 07:57
パーサーの練習
#!/usr/bin/ruby
require 'parslet'
class AAAParser < Parslet::Parser
root :all
rule(:all){
# 全体は line の 0 回以上の繰り返しの後に
line.repeat >>
# statement があるかもしれない
statement.maybe
: 0 ." This is 1." 1 cr ;
: 𝟶 ." This is 2." 2 cr ;
: 𝟢 ." This is 3." 3 cr ;
0 . cr
𝟶 . cr
𝟢 . cr