This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import random | |
def producer(): | |
while True: | |
data = random.randint(0, 9) | |
print('生產了:', data) | |
yield data | |
def consumer(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 函式 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Prolog … 快速排序法 … 白話版… XD | |
/* | |
* [] 附加 Result 的 結果為 Result | |
*/ | |
append([], Result, Result). | |
/* | |
* Tail 附加 Other 的結果為 Subappend => [Head | Tail] 附加 Other 的結果為 [Head | Subappend] | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''碎形數列之一…每隔 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 .... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |