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 -*- | |
| import Test.HUnit | |
| deal :: Int -> String -> [String] | |
| deal n s = deal_ 0 (take n $ repeat "") (take ((length s) - (length s `mod` n)) s) | |
| where deal_ _ ys [] = ys | |
| deal_ m ys (x:xs) = deal_ ((m + 1) `mod` n) ((take m ys) ++ [(ys!!m) ++ [x]] ++ (drop (m + 1) ys)) xs | |
| tests = test [ | |
| ["111", "222", "333"] ~=? deal 3 "123123123", |
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
| hello, public gist\n |
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 -*- | |
| # | |
| # cat <<'EOD' | python sort-regexp-fields.py '[^;]+' | |
| # using System; | |
| # using System.Collections.Generic; | |
| # using System.Web; | |
| # using System.Web.UI; | |
| # using System.Web.UI.WebControls; | |
| # using System.Web.UI.HtmlControls; | |
| # using System.Linq; |
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
| (define (dfs tree) | |
| (display (car tree)) | |
| (newline) | |
| (let loop ((xs (cdr tree))) | |
| (if (not (null? xs)) | |
| (begin | |
| (dfs (car xs)) | |
| (loop (cdr xs)))))) | |
| (dfs '(1 (2 (3 (4)) (5) (6)) (7 (8 (9) (10) (11)) (12 (13 (14)))))) |
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
| (define (bfs tree) | |
| (if (not (null? tree)) | |
| (let loop ((p (list tree)) (q '())) | |
| (if (null? p) | |
| (if (not (null? q)) | |
| (loop q '())) | |
| (begin | |
| (display (caar p)) | |
| (newline) | |
| (loop (cdr p) (append q (cdar p)))))))) |
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
| fizzbuzz n = map | |
| (\p -> (if fst p /= "" then fst else snd) p) | |
| (zip | |
| (zipWith (++) (cycle ["", "", "Fizz"]) (cycle ["", "", "", "", "Buzz"])) | |
| (map show [1..n])) |
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
| #! /bin/bash | |
| # | |
| # exec-objc.sh <<'EOD' | |
| # NSLog(@"this script compile and execute objective-c code fragment"); | |
| # EOD | |
| # | |
| SRC=$(mktemp exec-objc-src.XXXXXXXX) | |
| OUT=$(mktemp exec-objc-out.XXXXXXXX) | |
| trap 'rm -f ${SRC} ${OUT}' EXIT |
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
| TARGET = main | |
| OBJS = main.o | |
| CC = clang | |
| CFLAGS = -fobjc-arc -O2 -Wall | |
| LDFLAGS = -framework Foundation | |
| .m.o: | |
| $(CC) $(CFLAGS) -c $< -o $*.o |
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 -*- | |
| from struct import unpack | |
| def do(f): | |
| (tag1, size, tag2) = unpack('<4sI4s', f.read(12)) | |
| if not (tag1 == 'RIFF' and tag2 == 'WAVE'): | |
| print 'not wave file.' | |
| return |
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
| <?php $quine = '<?php $quine = %s%s%s; printf($quine, chr(39), $quine, chr(39));'; printf($quine, chr(39), $quine, chr(39)); |