全角を半角に変換するのは「-Z4」オプション。そんなオプションまであんのかい。大好きだわnkf。
2013/07/10
zshのテーマ
zshを使っているけどカスタマイズはほとんどしていない。最初にzshを起動した時に出てくる「取りあえずオススメ設定の.zshrc使っちゃう?」的なのものに、いくつか設定やaliasを追加して使っている。
家もVPSも会社も会社のサーバーも同じ.zshrcなんだけど、会社のローカルと会社のサーバーで区別がつかないのは流石に紛らわしいと感じていた。ぐーぐる先生に尋ねてみたら、zshって予めプロンプトのテーマが用意されているんですね。なので、サーバーだけプロンプトのテーマを替えました。
家もVPSも会社も会社のサーバーも同じ.zshrcなんだけど、会社のローカルと会社のサーバーで区別がつかないのは流石に紛らわしいと感じていた。ぐーぐる先生に尋ねてみたら、zshって予めプロンプトのテーマが用意されているんですね。なので、サーバーだけプロンプトのテーマを替えました。
2013/07/07
スーツ用のシャツを新調した
しばらく前にスーツを2着ほど新調した。最近のスーツは細身で、特にパンツがすごく細い。いいと思う。でも着てみるとなぜかシャツに違和感がある。どうもダブついて見える。サイズはMで合っている。だけどウエスト周りがどこか不恰好だ。妻のススメでスリムタイプのシャツを買ってみた。Oh、シャレオツ。スーツと合わせてみるといい感じじゃないか。これは非常に気分がいい。気分が良くて人生が豊かになった。出張に行きたくなった。しかし、珍しくもしばらく出張の予定がないのであった。
追記
そういえば、もうひとつ些細なことだけど気分の良いことがあったんだった。ひげ剃り用のシェーバーを買い換えた。ラムダッシュってやつ。安いんだけど、剃り心地が良くてご機嫌である。ずっとカミソリ派だったけど、1年ほど前からシェーバーを使うようになった。取りあえずはとんでもなく安いシェーバーを使ってたんだけど、もう少しだけまともなものを試しに買ってみたわけ。
labels :
diary
2013/07/06
このページなんでこんなにアクセスが多いのかわからない
この二つの記事、なぜかすごくアクセス数が多い。はてブされてるわけでもないし。わからん。
そういえば来週の金曜日、7/12はJ.P.ホーガンの命日ですね。もう3年も経つのか。幼年期の終わりはホーガンじゃないけどな。
Gaucheで各種ソートアルゴリズム
ソートアルゴリズムって、ふざけたもの含めて結構あるんだなー。ふざけてる系がすごく面白い。ボゴソートとかボゾソートとかパーミューテーションソートとか(笑)あとは基数ソート、ビーズズートなんかのバケツっぽいのが好きだなあ。スパゲティソートもいいなあ(w
Wikipediaにあったソート。ソートじゃないのも入ってるかも。
ところでGaucheのsortはイントロソートの親戚なのかな?
Wikipediaにあったソート。ソートじゃないのも入ってるかも。
- American flag sort - Wikipedia, the free encyclopedia
- Batcher odd–even mergesort - Wikipedia, the free encyclopedia
- Bead sort - Wikipedia, the free encyclopedia
- Bitonic sorter - Wikipedia, the free encyclopedia
- Bogosort - Wikipedia, the free encyclopedia
- Bubble sort - Wikipedia, the free encyclopedia
- Bucket sort - Wikipedia, the free encyclopedia
- Burstsort - Wikipedia, the free encyclopedia
- Cartesian tree - Wikipedia, the free encyclopedia
- Cascade merge sort - Wikipedia, the free encyclopedia
- Cocktail sort - Wikipedia, the free encyclopedia
- Comb sort - Wikipedia, the free encyclopedia
- Counting sort - Wikipedia, the free encyclopedia
- Cycle sort - Wikipedia, the free encyclopedia
- Flashsort - Wikipedia, the free encyclopedia
- Gnome sort - Wikipedia, the free encyclopedia
- Heapsort - Wikipedia, the free encyclopedia
- Insertion sort - Wikipedia, the free encyclopedia
- Introsort - Wikipedia, the free encyclopedia
- JSort - Wikipedia, the free encyclopedia
- Library sort - Wikipedia, the free encyclopedia
- Merge sort - Wikipedia, the free encyclopedia
- Odd–even sort - Wikipedia, the free encyclopedia
- Oscillating merge sort - Wikipedia, the free encyclopedia
- Pairwise sorting network - Wikipedia, the free encyclopedia
- Pancake sorting - Wikipedia, the free encyclopedia
- Patience sorting - Wikipedia, the free encyclopedia
- Pigeonhole sort - Wikipedia, the free encyclopedia
- Polyphase merge sort - Wikipedia, the free encyclopedia
- Bucket sort - Wikipedia, the free encyclopedia
- Proxmap sort - Wikipedia, the free encyclopedia
- Quicksort - Wikipedia, the free encyclopedia
- Radix sort - Wikipedia, the free encyclopedia
- Samplesort - Wikipedia, the free encyclopedia
- Selection sort - Wikipedia, the free encyclopedia
- Shellsort - Wikipedia, the free encyclopedia
- Shellsort - Wikipedia, the free encyclopedia
- Smoothsort - Wikipedia, the free encyclopedia
- Sorting algorithm - Wikipedia, the free encyclopedia
- Spaghetti sort - Wikipedia, the free encyclopedia
- Spreadsort - Wikipedia, the free encyclopedia
- Stooge sort - Wikipedia, the free encyclopedia
- Strand sort - Wikipedia, the free encyclopedia
- Timsort - Wikipedia, the free encyclopedia
- Topological sorting - Wikipedia, the free encyclopedia
- Tournament sort - Wikipedia, the free encyclopedia
- Tree sort - Wikipedia, the free encyclopedia
- UnShuffle sort - Wikipedia, the free encyclopedia
Gauche
Gaucheで書いてみたのが、今んとこ以下のもの。- vallog: scheme(gauche)でもsleep-sort
- vallog: Gaucheでbubble sort
- vallog: Gaucheでbucket sort
- vallog: Gaucheでradix sort
- vallog: Gaucheでquick sort
- vallog: Gaucheでbogo sort
- vallog: Gaucheでmerge sort
- vallog: Gaucheでselection sort
- vallog: Gaucheでbozo sort
- vallog: Gaucheでstooge sort
- vallog: Gaucheでstrand sort
- vallog: Gaucheでpermutation sort
- vallog: Gaucheでbead sort(ビーズソート)
ところでGaucheのsortはイントロソートの親戚なのかな?
Gaucheの組み込みの(Cで実装された)ソートはデフォルトではQuick Sortで始めて、 再帰の深さが ceiling(2*log(N)) を越えた時にHeap Sortにスイッチするように してる。
参考
- Sorting algorithm - Wikipedia, the free encyclopedia
- Category:Sorting Algorithms - Rosetta Code
- いろいろなソートアルゴリズム
- Sorting Algorithm Animations
「リストをn個ずつのサブリストに分割 (Python)」をGaucheで
Gaucheにはそのものズバリなslicesという手続きがある。
Gaucheだとgeneratorを使って実現できるんじゃないかな。Gaucheにもzip手続きはあるけど、gzipはない。gzipなしで書くとこんな感じのことかな。
(slices '(a b c d e f g) 3) ⇒ ((a b c) (d e f) (g)) (slices '(a b c d e f g) 3 #t 'z) ⇒ ((a b c) (d e f) (g z z))で、それは置いといて、Pythonのzip(*[iter(s)]*n)ってのは、n個のiteraterを作ってzipしてるってことだと思う(python知らね)。
Gaucheだとgeneratorを使って実現できるんじゃないかな。Gaucheにもzip手続きはあるけど、gzipはない。gzipなしで書くとこんな感じのことかな。
(use gauche.generator) (generator->list (apply gmap list (make-list 3 (giota 15)))) ;; => ((0 1 2) (3 4 5) (6 7 8) (9 10 11) (12 13 14))gzipを定義するとしたらこんなんでいいのかな。
(use gauche.generator) (define (gzip . list-of-list) (apply gmap list list-of-list)) (generator->list (apply gzip (make-list 3 (giota 15)))) ;; => ((0 1 2) (3 4 5) (6 7 8) (9 10 11) (12 13 14))
Gaucheでstrand sort
その他のソート
ソース
(define (strand-sort ls) (define (merge ls1 ls2) (let rec ((ls1 ls1)(ls2 ls2)(acc '())) (cond ((null? ls1) (reverse (append (reverse ls2) acc))) ((null? ls2) (reverse (append (reverse ls1) acc))) ((< (car ls1)(car ls2)) (rec (cdr ls1) ls2 (cons (car ls1) acc))) (else (rec ls1 (cdr ls2)(cons (car ls2) acc)))))) (define (filter-sorted-elements ls) (if (null? ls) '() (let rec ((ls (cdr ls))(sorted (list (car ls)))(acc '())) (if (null? ls) (values (reverse sorted) (reverse acc)) (let1 sorted? (< (car sorted)(car ls)) (rec (cdr ls) (if sorted? (cons (car ls) sorted) sorted) (if sorted? acc (cons (car ls) acc)))))))) ;; body (let rec ((ls ls)(acc '())) (if (null? ls) acc (receive (sorted rest) (filter-sorted-elements ls) (rec rest (merge sorted acc)))))) (use gauche.sequence) (define (test sorter n) (for-each (^i (let1 ls (shuffle (iota (expt 10 i))) (print "; length = " (expt 10 i)) (time (sorter ls)) (print))) (iota n 2))) (test strand-sort 5) ; length = 100 ;(time (sorter ls)) ; real 0.000 ; user 0.000 ; sys 0.000 ; length = 1000 ;(time (sorter ls)) ; real 0.005 ; user 0.000 ; sys 0.000 ; length = 10000 ;(time (sorter ls)) ; real 0.215 ; user 0.210 ; sys 0.010 ; length = 100000 ;(time (sorter ls)) ; real 6.727 ; user 6.710 ; sys 0.000 ; length = 1000000 ;(time (sorter ls)) ; real 205.260 ; user 204.550 ; sys 0.100
Gaucheでbogo sort
これはsleep sortを見て以来の衝撃だな・・・。
その他のソート
ソース
(use gauche.sequence) (define (bogo-sort ls) (if (apply < ls) ls (bogo-sort (shuffle ls)))) (define data-5 (shuffle (iota 5))) (define data-10 (shuffle (iota 10))) (define data-15 (shuffle (iota 15))) (time (bogo-sort data-5)) ;(time (bogo-sort data-5)) ; real 0.001 ; user 0.000 ; sys 0.000 (time (bogo-sort data-10)) ;(time (bogo-sort data-10)) ; real 12.053 ; user 12.010 ; sys 0.000
Gaucheでmerge sort
その他のソート
ソース
(use srfi-1) (define (merge-sort ls) (define (merge ls1 ls2) (let rec ((ls1 ls1)(ls2 ls2)(acc '())) (cond ((null? ls1) (reverse (append (reverse ls2) acc))) ((null? ls2) (reverse (append (reverse ls1) acc))) ((< (car ls1)(car ls2)) (rec (cdr ls1) ls2 (cons (car ls1) acc))) (else (rec ls1 (cdr ls2)(cons (car ls2) acc)))))) (if (or (null? ls) (null? (cdr ls))) ls (let1 split-index (quotient (length ls) 2) (receive (head tail) (split-at ls split-index) (merge (merge-sort head) (merge-sort tail)))))) (use gauche.sequence) (define (test sorter n) (for-each (^i (let1 ls (shuffle (iota (expt 10 i))) (print "; length = " (expt 10 i)) (time (sorter ls)) (print))) (iota n 2))) (test merge-sort 6) ; length = 100 ;(time (sorter ls)) ; real 0.000 ; user 0.000 ; sys 0.000 ; length = 1000 ;(time (sorter ls)) ; real 0.002 ; user 0.010 ; sys 0.000 ; length = 10000 ;(time (sorter ls)) ; real 0.025 ; user 0.030 ; sys 0.000 ; length = 100000 ;(time (sorter ls)) ; real 0.288 ; user 0.280 ; sys 0.000 ; length = 1000000 ;(time (sorter ls)) ; real 3.422 ; user 3.370 ; sys 0.030 ; length = 10000000 ;(time (sorter ls)) ; real 40.993 ; user 40.620 ; sys 0.240
Gaucheでselection sort
その他のソート
ソース
(use srfi-43) (define (selection-sort ls) (define (vector-min-index vect start-index) (do ((i start-index (+ i 1)) (min-value +inf.0) (min-index 0)) ((= i (vector-length vect))(values min-index min-value)) (when (< (vector-ref vect i) min-value) (set! min-value (vector-ref vect i)) (set! min-index i)))) ;; body (do ((i 0 (+ i 1)) (vect (list->vector ls))) ((= i (length ls))(vector->list vect)) (vector-swap! vect i (vector-min-index vect i)))) (use gauche.sequence) (define (test sorter n) (for-each (^i (let1 ls (shuffle (iota (expt 10 i))) (print "; length = " (expt 10 i)) (time (sorter ls)) (print))) (iota n 2))) (test selection-sort 4) ; length = 100 ;(time (sorter ls)) ; real 0.001 ; user 0.000 ; sys 0.000 ; length = 1000 ;(time (sorter ls)) ; real 0.030 ; user 0.030 ; sys 0.000 ; length = 10000 ;(time (sorter ls)) ; real 2.614 ; user 2.610 ; sys 0.000 ; length = 100000 ;(time (sorter ls)) ; real 255.403 ; user 254.710 ; sys 0.020
登録:
投稿 (Atom)