This file contains hidden or 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
test for gisty |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
def rotate_arr(arr, t): | |
"""programming peals | |
rotate array algorithm(destructive)""" | |
l = len(arr) | |
tmp = arr[0] | |
k = 0 | |
while True: | |
j = k |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
def rotate_arr(arr, t): | |
"""programming peals | |
rotate array algorithm(destructive)""" | |
l = len(arr) | |
tmp = arr[0] | |
k = 0 | |
while True: | |
j = k |
This file contains hidden or 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
#!/usr/bin/env python | |
from time import sleep | |
def do_heavy_process(): | |
sleep(3) | |
return 10 | |
class myclass(): | |
def __init__(self): | |
self.__val = None |
This file contains hidden or 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
#!/usr/bin/env python | |
# coding: utf8 | |
def hanoi(n, from_, to, via): | |
"tower of hanoi" | |
if n == 1: | |
print "move %d: %s => %s" % (n, from_, to) | |
else: | |
hanoi(n-1, from_, via, to) | |
print "move %d: %s => %s" % (n, from_, to) | |
hanoi(n-1, via, to, from_) |
This file contains hidden or 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
#!/usr/bin/env python | |
# coding: utf8 | |
def comb(n, r): | |
"calc combination" | |
if n == 0 or r == 0: return 1 | |
# return (n - r + 1) / r * comb(n, r - 1) | |
# 先にrで割ると,小数点を切り捨ててしまう | |
return comb(n, r - 1) * (n - r + 1) / r | |
#print comb(10, 2) # 45 |
This file contains hidden or 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
;; はてな記法のリスト(-)をいい感じに挿入してくれる | |
;; C-lを押すたびに深いリストになっていく | |
(defun insert-list() | |
(interactive) | |
(let* ((end-point (point)) | |
(start-point (- end-point 2)) | |
(str (buffer-substring start-point end-point))) | |
(if (string-equal "- " str) | |
(delete-backward-char 1)) | |
(insert "- "))) |
This file contains hidden or 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
(* fibonacci *) | |
let fib(x:int) = | |
let rec fib_i(n, a, b) = | |
if n = 1 || n = 2 then a | |
else fib_i(n-1, a+b, a) | |
in fib_i(x, 1, 1);; | |
(* 実行: | |
# #trace fib;; | |
fib is now traced. | |
# fib 4;; |
This file contains hidden or 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
#!/usr/bin/env python | |
# coding: utf-8 | |
def _upheap(heap, x): | |
heap += [x] | |
l = len(heap) - 1 # 挿入する要素のindex | |
while (l-1)/2 >= 0: # 親がいる場合 | |
if heap[(l-1)/2] > heap[l]: | |
heap[(l-1)/2], heap[l] = heap[l], heap[(l-1)/2] | |
l = (l-1)/2 |
This file contains hidden or 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
type student = { name: string; id: int };; | |
type hoge = { name: string; age: int };; | |
{ name = "hi"; id = 12 };; | |
(* | |
# type student = { name: string; id: int };; | |
type student = { name : string; id : int; } | |
# type hoge = { name: string; age: int };; | |
type hoge = { name : string; age : int; } | |
# { name = "hi"; id = 12 };; |