Skip to content

Instantly share code, notes, and snippets.

View JustinSDK's full-sized avatar
👨‍👩‍👧
Working from home

Justin Lin JustinSDK

👨‍👩‍👧
Working from home
View GitHub Profile
@JustinSDK
JustinSDK / hoc.py
Created July 18, 2016 08:43
Python - High Order Components?
def total_ordering(eq, gt):
def inner(clz):
class Ordering:
def __init__(self, *arg1, **arg2):
clz.__init__(self, *arg1, **arg2)
def __eq__(self, other):
return eq(self, other)
def __gt__(self, other):
@JustinSDK
JustinSDK / producer_consumer.py
Created July 26, 2016 02:36
producer_consumer
import sys
import random
def producer():
while True:
data = random.randint(0, 9)
print('生產了:', data)
yield data
def consumer():
@JustinSDK
JustinSDK / maximum.scad
Last active August 30, 2016 08:02
OpenSCAD max
function maximum(lt, num = 0, index = 0) =
index == len(lt) ? num : (
lt[index] > num ? maximum(lt, lt[index], index + 1) : maximum(lt, num, index + 1)
);
echo(maximum([1,3,5,7,6,4,2]));
echo(max([1,3,5,7,6,4,2])); // OpenSCAD 內建的 max 函式
@JustinSDK
JustinSDK / sort.pl
Last active December 5, 2016 16:11
Prolog … 快速排序法 … 白話版… XD
Prolog … 快速排序法 … 白話版… XD
/*
* [] 附加 Result 的 結果為 Result
*/
append([], Result, Result).
/*
* Tail 附加 Other 的結果為 Subappend => [Head | Tail] 附加 Other 的結果為 [Head | Subappend]
*
@JustinSDK
JustinSDK / fractal_sequence.py
Last active April 14, 2020 07:57
碎形數列
'''碎形數列之一…每隔 n 個空格填入數字1、2、3、4、5 ....,例如 n 為 2 時…
1 _ _ 2 _ _ 3 _ _ 4 _ _ 5 _ _ 6 _ _ 7 _ _ 8 _ _ 9 _ _ ....
接著,在上面的數列中,每隔 2 個空格填入數字1、2、3、4、5 ....
1 1 _ 2 _ 2 3 _ _ 4 3 _ 5 _ 4 6 _ _ 7 5 _ 8 _ 6 9 _ _ ....
繼續在上面的數列中,每隔 2 個空格填入數字1、2、3、4、5 ....
@JustinSDK
JustinSDK / hanoi_using_stack_no_recursion.py
Last active June 2, 2019 15:02
河內塔使用堆疊的非遞迴版本
def hanoi(n, a, b, c):
param_stack_recursion2 = [[n, a, b, c]]
while param_stack_recursion2:
m, pa, pb, pc = param_stack_recursion2.pop()
param_stack_recursion1 = []
while True:
if m == 1:
print(pa, pc) # hanoi(1, A, B, C)
@JustinSDK
JustinSDK / hanoi_no_stack_no_recursion.py
Created January 12, 2017 05:46
河內塔不使用堆疊的非遞迴版本
def is_even(n):
return n % 2 == 0
def which_disk(n):
c = n ^ (n + 1)
i = 0
while c != 0:
c = c >> 1
i = i + 1
return i
//radius determines the size of the hexagon
radius = 20;
levels = 15;
spacing = 2;
thickness = 20;
module hexagons(radius, spacing, levels) {
beginning_n = 2 * levels - 1;
offset_x = radius * cos(30);
$fn = 48; // 圓的邊數
r1 = 15; // 半徑 1.5 cm
r2 = 15; // 也就是直徑 3 cm
thickness = 5; // 厚度 0.5 cm
length = 50; // 長度 5 cm
function __frags(radius) = $fn > 0 ?
($fn >= 3 ? $fn : 3) :
max(min(360 / $fa, radius * 6.28318 / $fs), 5);
@JustinSDK
JustinSDK / lambda-calculus-1.js
Last active March 19, 2018 06:02
console.log([1, 2, 3].map(elem => elem - 2))?(part 1)
function array(lt) {
let pair = l => r => f => f(l)(r);
let left = p => p(l => r => l);
let right = p => p(l => r => r);
let nil = pair(undefined)(undefined);
let con = head => tail => pair(head)(tail);
let head = lt => left(lt)
let tail = lt => right(lt);