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
import Data.List | |
import Control.Monad | |
valid xs = any ((== max) . sum) $ filterM (const [True, False]) left where | |
max = maximum xs | |
left = delete max xs | |
main = do | |
print $ valid [4, 6, 23, 10, 1, 3] | |
print $ valid [5, 7, 16, 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
(let ((yin ((lambda (foo) (newline) foo) (call/cc (lambda (bar) bar)))) | |
(yang ((lambda (foo) (write-char #\*) foo) (call/cc (lambda (bar) bar))))) | |
(yin yang)) | |
(define (id x) x) | |
(define (f x) (display "O") x) | |
(define (g x) (display "-") x) | |
((f (call/cc id)) (g (call/cc id))) |
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
书后标的是原价 | |
以下4折: | |
「·已出·」深入理解计算机系统 (第一版) http://book.douban.com/subject/1230413/ 定价: 85.00元 | |
「·已出·」实用Common Lisp编程 (伞哥翻译的,全新,书的封膜还没撕) http://book.douban.com/subject/6859720/ 定价: 89.00元 | |
「·已出·」编程的本质 : 英文版 http://book.douban.com/subject/4722718/ 定价: 49.00元 | |
「·已出·」汇编语言(王爽) http://book.douban.com/subject/3037562/ 定价: 33.00元 | |
「·已出·」卓有成效的程序员(影印版) http://book.douban.com/subject/3558788/ 定价: 45.00元 | |
「·已出·」ML程序设计教程 http://book.douban.com/subject/1316040/ 定价: 45.00元 |
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
data Color = R | B | M | F deriving (Show, Ord, Eq, Read) | |
cards = concat $ zipWith (zip.repeat) [R,B,M,F] ["4AQ", "23478J", "456QK", "5A"] | |
only f cs cp = filter (\x -> filter (f x ==) (map f cs) `cp` [f x]) cs | |
p1 = only snd cards (/=) | |
q1 = filter many cards where | |
many(c,n) = all number (filter ((==c).fst) cards) | |
number(c,n) = filter ((==n).snd) cards /= [(c,n)] | |
p2 = only snd q1 (==) |
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
import Control.Monad | |
import Control.Concurrent | |
chans = sequence $ replicate 100001 newEmptyMVar | |
whisper chans = do | |
forM_ (zip chans (tail chans)) $ \(left,right) -> forkIO $ do | |
msg <- readMVar right | |
putMVar left (msg + 1) | |
forkIO $ putMVar (last chans) 1 |