Skip to content

Instantly share code, notes, and snippets.

View dannypsnl's full-sized avatar

Lîm Tsú-thuàn dannypsnl

View GitHub Profile
@dannypsnl
dannypsnl / bloom-filter.rkt
Last active July 2, 2022 06:33
A simple bloom filter for racket
#lang curly-fn racket/base
(require data/bit-vector)
(define (((make-hash-func init mult) size) key)
(modulo
(+ init
(for/sum ([char key]) (* mult (char->integer char))))
size))
(define (make-bloom-filter make-hash-functions size)
@dannypsnl
dannypsnl / exponential.rkt
Created May 23, 2022 05:55
define exponential by myself
(define (^ a n)
(cond
[(= 0 n) 1]
[(positive-integer? n) (apply * (make-list n a))]
[(negative-integer? n) (/ 1 (^ a (- n)))]
[(and (rational? n) (= 1 (numerator n)))
(let loop ([answer 1])
(define ans^n (^ answer (denominator n)))
(cond
[(< (abs (- ans^n a)) 0.001) answer]
#lang rhombus
1+1
val x :: Integer : 1
x+1
val mutable ha: 1
ha := 2
ha
begin:
@dannypsnl
dannypsnl / insertion-sort.c
Created May 10, 2022 13:44
insertion sort
#include <stdio.h>
void swap(int *x, int *y) {
long tmp = *x;
*x = *y;
*y = tmp;
}
void insertion_sort(int s[], int len) {
for (int i = 1; i < len; i++) {
@dannypsnl
dannypsnl / knapsack.rkt
Created May 10, 2022 11:30
knapsack problem
#lang racket
(define object-weight second)
(define object-price third)
(define c (make-hash))
(define (knapsack pool w)
(for ([obj pool]
[n (length pool)])
(for ([w (range 1 (add1 w))])
@dannypsnl
dannypsnl / recurring-decimal->rational.rkt
Created May 10, 2022 06:16
convert recurring decimals string to rational number
#lang racket
1/11
(exact->inexact 1/11)
(define (recurring-decimal->rational n)
(/ (string->number n) (sub1 (expt 10 (string-length n)))))
(recurring-decimal->rational "12345")
(recurring-decimal->rational "09")
@dannypsnl
dannypsnl / rackcheck.rkt
Created March 1, 2022 14:24
library: rackcheck
#lang racket
(require rackcheck
rackunit)
(check-property
(property ([xs (gen:list gen:natural)])
(check-equal? (reverse (reverse xs)) xs)))
@dannypsnl
dannypsnl / octal_x86.txt
Created February 18, 2022 15:45 — forked from seanjensengrey/octal_x86.txt
x86 is an octal machine
# source:http://reocities.com/SiliconValley/heights/7052/opcode.txt
From: mark@omnifest.uwm.edu (Mark Hopkins)
Newsgroups: alt.lang.asm
Subject: A Summary of the 80486 Opcodes and Instructions
(1) The 80x86 is an Octal Machine
This is a follow-up and revision of an article posted in alt.lang.asm on
7-5-92 concerning the 80x86 instruction encoding.
The only proper way to understand 80x86 coding is to realize that ALL 80x86
@dannypsnl
dannypsnl / shell-progress-bar.ss
Created February 9, 2022 10:16
shell: progress bar
(import (rnrs))
(define (generate-bar tick percent total-width)
(let ([num-equals (if (= tick 0) 0 (- tick 1))]
[arrow (if (= tick 0) "" ">")]
[width (- total-width 6)]
[places-string
(cond
[(< percent 10) " "]
[(< percent 100) " "]
@dannypsnl
dannypsnl / core.rkt
Last active May 16, 2022 16:13
proof by rule rewrittern
#lang racket
(provide proof
define-rewrite)
(require (for-syntax racket/match)
syntax/parse/define)
(define-syntax-parser proof
[(_ form-a ≡ form-b)
#'(unless (equal? form-a 'form-b)