<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>Latest comments for language 'Clean' on doukaku.org</title><link>http://ja.doukaku.org/lang/clean/</link><description>Latest comments for language 'Clean' on doukaku.org(long)</description><language>ja</language><lastBuildDate>Sat, 22 Nov 2008 19:51:02 -0000</lastBuildDate><item><title>lethevert's comment on 必ず解ける迷路
</title><link>http://ja.doukaku.org/comment/5295/</link><description>



&lt;a href="http://ja.doukaku.org/123/"&gt;必ず解ける迷路&lt;/a&gt;
(&lt;a href="http://ja.doukaku.org/123/nested/"&gt;Nested&lt;/a&gt; 
 &lt;a href="http://ja.doukaku.org/123/flatten/"&gt;Flatten&lt;/a&gt;)


&lt;hr&gt;
  &lt;p&gt;「1024 x 1024」くらいならメモリ使用量が問題になることはないのかなと、あまり考えずに普通に書きました。&lt;/p&gt;
&lt;p&gt;「1024 x 1024」で6秒くらい。CPUスペックは、AMD Athlon 64 X2の2GHzだったと思います。&lt;/p&gt;
&lt;p&gt;アルゴリズムは、迷路の盤面を配列で用意して、１箇所から始めてランダムに少しずつ迷路を広げていく方法を取っています。&lt;/p&gt;
&lt;p&gt;「10 x 10」のサンプル出力は次の通りです。&lt;/p&gt;
&lt;pre class="literal-block"&gt;
#####################
#     # #       #   #
# ### # # ####### ###
# #         #       #
# # # # # ### ### ###
# # # # #       # # #
# ### ##### # # ### #
# # #     # # #   # #
### # ### # ### ### #
#       # # #       #
# ### ######### ### #
# #           # # # #
### ### # ##### # ###
#     # #     #     #
# ##### # ####### ###
# #     #       # # #
####### # # # # ### #
#   #   # # # # # # #
# ##### ### # ### # #
#         # #       #
#####################
&lt;/pre&gt;

&lt;hr&gt;
  
    &lt;table&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;pre&gt;  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114&lt;/pre&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;module Main

import Bool, Int, String, StringCast, Array
import System, Misc, StdIO, OptRandom, MersenneTwister, Trace

:: MazeCell = Cell !Bool !Bool //right, bottom

Start w
  # (t,w) = tickCount w
    (f,w) = stdio w
    (_,f) = writeLine 0 f
    (_,f) = writeMaze (maze n m (genRandInt t)) f
    (_,w) = close f w
  = w
  where
  cmd = getCommandLine
  n = toInt cmd.[1]
  m = toInt cmd.[2]
  get maze row col = maze.[row * n + col]

  writeMaze maze f = writeMaze maze 0 f
    where
    writeMaze maze row f
      | row == m = (PassV, f)
      = f |&amp;gt; write &amp;quot;#&amp;quot;
          $&amp;gt; printRoom 0
          $&amp;gt; write &amp;quot;\r\n#&amp;quot;
          $&amp;gt; printWall 0
          $&amp;gt; write &amp;quot;\r\n&amp;quot;
          $&amp;gt; writeMaze maze (row + 1)
      where
      m = size maze / n
      printWall col f
        | col == n = (PassV, f)
        = case get maze row col of
            Cell _ False = f |&amp;gt; write &amp;quot;##&amp;quot; $&amp;gt; printWall (col + 1)
            _            = f |&amp;gt; write &amp;quot; #&amp;quot; $&amp;gt; printWall (col + 1)

      printRoom col f
        | col == n = (PassV, f)
        = case get maze row col of
            Cell False _ = f |&amp;gt; write &amp;quot; #&amp;quot; $&amp;gt; printRoom (col + 1)
            _            = f |&amp;gt; write &amp;quot;  &amp;quot; $&amp;gt; printRoom (col + 1)

  writeLine col f
    | col == n = f |&amp;gt; write &amp;quot;#\r\n&amp;quot;
    = f |&amp;gt; write &amp;quot;##&amp;quot; $&amp;gt; writeLine (col + 1)

::*CellPool = CellPool !*{!(!Int,!Int)} !Int
isEmptyPool c=:(CellPool _ 0) = (True, c)
isEmptyPool c = (False, c)
getNextCell (CellPool ls sz) [r:rand]
    | sz == 1
      # (e1,ls) = ls![0]
      = (e1, CellPool ls 0, rand)
    # i = (abs r) rem sz
      (e1,ls) = ls![i]
      (e2,ls) = ls![sz-1]
      ls = {ls &amp;amp; [i] = e2}
    = (e1, CellPool ls (sz - 1), rand)
addCell x y (CellPool ls sz)
    # ls = {ls &amp;amp; [sz] = (x,y)}
    = CellPool ls (sz + 1)

maze n m rand =
    let
      sz = n * m
      marks = asUnboxedArray $ createArray sz False
      cells = asStrictArray $ createArray sz (Cell False False)
      pool = addCell 0 0 (CellPool (createArray sz (0,0)) 0)
    in
      expand marks cells pool rand
  where
    get x y arr = arr![x*n+y]
    put e x y arr = {arr &amp;amp; [x*n+y] = e}

    expand marks cells pool rand
      # (b,pool) = isEmptyPool pool
      | b = cells
      # ((x,y), pool, rand) = getNextCell pool rand
        (cand, marks) = filterCells marks [(x-1,y),(x,y-1),(x+1,y),(x,y+1)]
        (sel, rest, rand) = selectCells cand rand
      #! cells = updateCells x y sel cells
         marks = foldl (\marks (x,y) = put True x y marks) marks sel
         pool = foldl (\pool (x,y) = addCell x y pool) pool sel
      = case rest of
          [] = expand marks cells pool rand
          _  # pool = addCell x y pool
             = expand marks cells pool rand

    filterCells marks ls = f [] marks ls where
      f ls marks [] = (ls, marks)
      f ls marks [(x,y):ee]
        | x &amp;lt; 0 || y &amp;lt; 0 || x &amp;gt;= m || y &amp;gt;= n = f ls marks ee
        # (k,marks) = get x y marks
        | k = f ls marks ee
            = f [(x,y):ls] marks ee

    selectCells ls [r:rand] = let (e1,e2) = f ls 1 [] [] in (e1, e2, rand) where
      f [] _ e1 e2 = (e1, e2)
      f [e:ee] t e1 e2
        | r bitand t == 0 = f ee (t &amp;lt;&amp;lt; 1) e1 [e:e2]
                          = f ee (t &amp;lt;&amp;lt; 1) [e:e1] e2

    updateCells x y ls cells = f ls cells where
      f :: ![(Int,Int)] !*{!MazeCell} -&amp;gt; *{!MazeCell}
      f [] cells = cells
      f [(x1,y1):ls] cells
        # (c0, cells) = get x y cells
          (c1, cells) = get x1 y1 cells
        | x1 &amp;lt; x = let (Cell r b) = c1 in put (Cell r True) x1 y1 cells |&amp;gt; f ls
        | y1 &amp;lt; y = let (Cell r b) = c1 in put (Cell True b) x1 y1 cells |&amp;gt; f ls
        | x1 &amp;gt; x = let (Cell r b) = c0 in put (Cell r True) x y cells |&amp;gt; f ls
        | y1 &amp;gt; y = let (Cell r b) = c0 in put (Cell True b) x y cells |&amp;gt; f ls
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
    &lt;div align = "right" style="margin-right: 1em;"&gt;
      [&lt;a href="http://ja.doukaku.org/lang/clean/"&gt;
      Clean
      &lt;/a&gt;]
      [&lt;a href="http://ja.doukaku.org/comment/5295/download/"&gt;
      download code
      &lt;/a&gt;]
      &lt;/a&gt;]
    &lt;/div&gt;
    &lt;hr&gt;
  

</description><guid>http://ja.doukaku.org/comment/5295/</guid></item><item><title>lethevert's comment on 魔方分割数
</title><link>http://ja.doukaku.org/comment/5218/</link><description>



&lt;a href="http://ja.doukaku.org/108/"&gt;魔方分割数&lt;/a&gt;
(&lt;a href="http://ja.doukaku.org/108/nested/"&gt;Nested&lt;/a&gt; 
 &lt;a href="http://ja.doukaku.org/108/flatten/"&gt;Flatten&lt;/a&gt;)


&lt;hr&gt;
  &lt;div class="section"&gt;
&lt;p&gt;comb_sumで明らかに無駄な数え上げをしているところがあったので、それを削除しました&lt;/p&gt;
&lt;p&gt;n=5で18秒まで減少しました&lt;/p&gt;
&lt;/div&gt;
&lt;hr&gt;
  
    &lt;table&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35&lt;/pre&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;module Main

import Bool, Int, List, Array, ValueCast, StringCast, System, Misc, Trace

Start = length $
        divide n s ls
  where
  n = toInt getCommandLine.[1]
  ls = [1..n*n]
  s = sum ls / n

divide n s ls = search ls
  where
  search [] = [[]]
  search ls
    =  comb_sum s n ls
    |&amp;gt; map (\f = let
                   (f0,fr) = (head f, tail f)
                   rr = filter (\e = not (e &amp;lt;= f0 || fr contains e)) ls
                 in [[f:t] \\ t &amp;lt;- search rr])
    |&amp;gt; foldr (++) []

comb_sum :: Int Int [Int] -&amp;gt; [[Int]]
comb_sum s n [e:ee]
  | e &amp;gt; s = []
  = map ((:&amp;gt;) e) (comb_sum (s - e) ck ee) // &amp;lt;- この部分を修正
  where
  ck = reverse $ take (n-1) $ scan (+) 0 $ reverse $ ee
  comb_sum 0 [] _ = [[]]
  comb_sum _ [] _ = []
  comb_sum _ _ [] = []
  comb_sum s ck=:[c:cc] [e:ee]
    | e &amp;gt; s     = []
    | e &amp;lt; s - c = comb_sum s ck ee
                = map ((:&amp;gt;) e) (comb_sum (s-e) cc ee) ++ comb_sum s ck ee
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
    &lt;div align = "right" style="margin-right: 1em;"&gt;
      [&lt;a href="http://ja.doukaku.org/lang/clean/"&gt;
      Clean
      &lt;/a&gt;]
      [&lt;a href="http://ja.doukaku.org/comment/5218/download/"&gt;
      download code
      &lt;/a&gt;]
      &lt;/a&gt;]
    &lt;/div&gt;
    &lt;hr&gt;
  

</description><guid>http://ja.doukaku.org/comment/5218/</guid></item><item><title>lethevert's comment on 魔方分割数
</title><link>http://ja.doukaku.org/comment/5217/</link><description>



&lt;a href="http://ja.doukaku.org/108/"&gt;魔方分割数&lt;/a&gt;
(&lt;a href="http://ja.doukaku.org/108/nested/"&gt;Nested&lt;/a&gt; 
 &lt;a href="http://ja.doukaku.org/108/flatten/"&gt;Flatten&lt;/a&gt;)


&lt;hr&gt;
  &lt;div class="section"&gt;
&lt;p&gt;いくつか高速化を試して、一番効果の高かったcomb_sumでの置き換えだけを適用したもの。&lt;/p&gt;
&lt;p&gt;n=5で、2分20秒&lt;/p&gt;
&lt;p&gt;効果があまりなかったものは、コメントに記述してあります。&lt;/p&gt;
&lt;/div&gt;
&lt;hr&gt;
  
    &lt;table&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60&lt;/pre&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;module Main

import Bool, Int, List, Array, ValueCast, StringCast, System, Misc

Start = length $
        divide n s ls
  where
  n = toInt getCommandLine.[1]
  ls = [1..n*n]
  s = sum ls / n

divide n s ls = search ls
  where
  search [] = [[]]
  search ls
    =  comb_sum s n ls
    |&amp;gt; map (\f = let
                   (f0,fr) = (head f, tail f)
                   rr = filter (\e = not (e &amp;lt;= f0 || fr contains e)) ls
                 in [[f:t] \\ t &amp;lt;- search rr])
    |&amp;gt; foldr (++) []

comb_sum :: Int Int [Int] -&amp;gt; [[Int]]
comb_sum 0 0 _ = [[]]
comb_sum _ 0 _ = []
comb_sum s _ [] = []
comb_sum s n [e:rr]
  | e &amp;gt; s
    = comb_sum s n rr
    = map ((:&amp;gt;) e) (comb_sum (s-e) (n-1) rr) ++ comb_sum s n rr

/*
  //1. filterの部分をrest_of関数で置き換え
  search [] = [[]]
  search ls
    =  comb_sum s n ls
    |&amp;gt; map (\f = let rr = rest_of f ls
                 in [[f:t] \\ t &amp;lt;- search rr])
    |&amp;gt; foldr (++) []

  rest_of _ [] = []
  rest_of es=:[e:ee] ls=:[l:ll]
    | l &amp;lt;= e = rest_of es ll
    = rm ee ls
    where
    rm _ [] = []
    rm [] ls = ls
    rm es=:[e:ee] ls=:[l:ll]
      | l &amp;lt; e  = [l: rm es ll]
      | e == l = rm es ll
               = rm ee ls

  //2. searchで直接グループわけの個数を計算
  search [] = 1
  search ls
    =  comb_sum s n ls
    |&amp;gt; map (\f = let rr = rest_of f ls
                 in search rr)
    |&amp;gt; sum
*/
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
    &lt;div align = "right" style="margin-right: 1em;"&gt;
      [&lt;a href="http://ja.doukaku.org/lang/clean/"&gt;
      Clean
      &lt;/a&gt;]
      [&lt;a href="http://ja.doukaku.org/comment/5217/download/"&gt;
      download code
      &lt;/a&gt;]
      &lt;/a&gt;]
    &lt;/div&gt;
    &lt;hr&gt;
  

</description><guid>http://ja.doukaku.org/comment/5217/</guid></item><item><title>lethevert's comment on 魔方分割数
</title><link>http://ja.doukaku.org/comment/5216/</link><description>



&lt;a href="http://ja.doukaku.org/108/"&gt;魔方分割数&lt;/a&gt;
(&lt;a href="http://ja.doukaku.org/108/nested/"&gt;Nested&lt;/a&gt; 
 &lt;a href="http://ja.doukaku.org/108/flatten/"&gt;Flatten&lt;/a&gt;)


&lt;hr&gt;
  &lt;div class="section"&gt;
&lt;p&gt;とりあえずナイーブに実装。&lt;/p&gt;
&lt;p&gt;n=4の場合、0.04秒ですが、n=5の場合、5分経っても終わらないです。&lt;/p&gt;
&lt;/div&gt;
&lt;hr&gt;
  
    &lt;table&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28&lt;/pre&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;module Main

import Bool, Int, List, Array, ValueCast, StringCast, System, Misc

Start = length $ divide n s ls
  where
  n = toInt getCommandLine.[1]
  ls = [1..n*n]
  s = sum ls / n

divide n s ls = search ls
  where
  search [] = [[]]
  search ls
    =  comb n ls
    |&amp;gt; filter (\f = sum f == s)
    |&amp;gt; map (\f = let
                   (f0,fr) = (head f, tail f)
                   rr = filter (\e = not (e &amp;lt;= f0 || fr contains e)) ls
                 in [[f:t] \\ t &amp;lt;- search rr])
    |&amp;gt; foldr (++) []

comb :: Int [a] -&amp;gt; [[a]]
comb 0 _ = [[]]
comb _ [] = []
comb n [e:rr]
  =  map ((:&amp;gt;) e) (comb (n-1) rr)
  ++ comb n rr
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
    &lt;div align = "right" style="margin-right: 1em;"&gt;
      [&lt;a href="http://ja.doukaku.org/lang/clean/"&gt;
      Clean
      &lt;/a&gt;]
      [&lt;a href="http://ja.doukaku.org/comment/5216/download/"&gt;
      download code
      &lt;/a&gt;]
      &lt;/a&gt;]
    &lt;/div&gt;
    &lt;hr&gt;
  

</description><guid>http://ja.doukaku.org/comment/5216/</guid></item><item><title>lethevert's comment on ポーカーの役判定
</title><link>http://ja.doukaku.org/comment/5199/</link><description>



&lt;a href="http://ja.doukaku.org/121/"&gt;ポーカーの役判定&lt;/a&gt;
(&lt;a href="http://ja.doukaku.org/121/nested/"&gt;Nested&lt;/a&gt; 
 &lt;a href="http://ja.doukaku.org/121/flatten/"&gt;Flatten&lt;/a&gt;)


&lt;hr&gt;
  &lt;div class="section"&gt;
&lt;p&gt;初投稿です。Cleanです。この辺のライブラリを使ってます。&lt;/p&gt;
&lt;p&gt;http://sourceforge.net/projects/cleanoptenv&lt;/p&gt;
&lt;/div&gt;
&lt;hr&gt;
  
    &lt;table&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65&lt;/pre&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;module Main

import System, Int, Char, String, List, Misc, MergeSort, ValueCast

Start
  | flush cards
    | straight cards
      | 14 == num (head cards)
        = &amp;quot;Royal flush&amp;quot;
      = &amp;quot;Straight flush&amp;quot;
    = &amp;quot;Flush&amp;quot;
  | straight cards
    = &amp;quot;Straight&amp;quot;
  | 4 == head groups
    = &amp;quot;Four of a kind&amp;quot;
  | 3 == head groups
    | 2 == groups !! 1
      = &amp;quot;Full house&amp;quot;
    = &amp;quot;Three of a kind&amp;quot;
  | 2 == head groups
    | 2 == groups !! 1
      = &amp;quot;Two pair&amp;quot;
    = &amp;quot;One pair&amp;quot;
  = &amp;quot;No pair&amp;quot;
  where
  cards = sortBy (&amp;gt;) $ parseCards getCommandLine.[1]
  groups = sortBy (&amp;gt;) $ map length $ groupCards [[]] 0 cards

:: Card = Card !Char !Int //suit num(2..14)
instance &amp;lt; Card where
  (&amp;lt;) (Card s0 n0) (Card s1 n1) = n0 &amp;lt; n1

suit (Card s n) = s
num (Card s n) = n

parseCards t = p 0
  where
  l = size t
  p i | i &amp;gt;= l = []
      = [Card s n: p (i+2)]
    where
    s = t.[i]
    n = case t.[i+1] of
          &amp;#39;A&amp;#39; = 14
          &amp;#39;K&amp;#39; = 13
          &amp;#39;Q&amp;#39; = 12
          &amp;#39;J&amp;#39; = 11
          &amp;#39;T&amp;#39; = 10
          c   = toInt (c - &amp;#39;0&amp;#39;)

groupCards ls _ [] = ls
groupCards [l:ll] m [c=:Card s n: rest]
  | m == n = groupCards [[c:l]:ll] n rest
           = groupCards [[c],l:ll] n rest

flush cards = and $ zipWith (==) suits (tail suits)
  where
  suits = map suit cards

straight cards = (and $ zipWith (\a b = a == b + 1) nums (tail nums))
              || caseAce nums
  where
  nums = map num cards
  caseAce [14,5,4,3,2] = True
  caseAce _ = False
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
    &lt;div align = "right" style="margin-right: 1em;"&gt;
      [&lt;a href="http://ja.doukaku.org/lang/clean/"&gt;
      Clean
      &lt;/a&gt;]
      [&lt;a href="http://ja.doukaku.org/comment/5199/download/"&gt;
      download code
      &lt;/a&gt;]
      &lt;/a&gt;]
    &lt;/div&gt;
    &lt;hr&gt;
  

</description><guid>http://ja.doukaku.org/comment/5199/</guid></item><item><title>mz's comment on 与えた条件を満たす候補
</title><link>http://ja.doukaku.org/comment/2526/</link><description>



&lt;a href="http://ja.doukaku.org/43/"&gt;与えた条件を満たす候補&lt;/a&gt;
(&lt;a href="http://ja.doukaku.org/43/nested/"&gt;Nested&lt;/a&gt; 
 &lt;a href="http://ja.doukaku.org/43/flatten/"&gt;Flatten&lt;/a&gt;)


&lt;hr&gt;
  &lt;pre class='compact'&gt;&lt;/pre&gt;
&lt;hr&gt;
  
    &lt;table&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21&lt;/pre&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;module xop
import StdEnv;($) infixr 1;($) a b :== a b;(&amp;gt;&amp;gt;.) infixl 0;(&amp;gt;&amp;gt;.) a b = \ w -&amp;gt; (\ (_, w) -&amp;gt; b w) (a w);(&amp;gt;&amp;gt;=) infixl 0;(&amp;gt;&amp;gt;=) a b = \ w -&amp;gt; (\ (x, w) -&amp;gt; b x w ) (a w);liftM m :== \ lst -&amp;gt; \ w -&amp;gt;  (m lst, w);join del [x:xs]= (toString x) +++ del +++ (join del xs);join _ [] = &amp;quot;&amp;quot;;putStr str = \w -&amp;gt; (stdio &amp;gt;&amp;gt;= liftM ( fwrites str) &amp;gt;&amp;gt;= fclose) w;Start w =snd $ main w;
main = putStr $ join &amp;quot;\n&amp;quot; $ map (join &amp;quot;,&amp;quot;) $ xop [And, Or, Not, And]
tf = [True, False]
:: XopOp = And |Or |Not
xopisNot Not = True
xopisNot _ = False
xop :: [XopOp] -&amp;gt; [[Bool]]
xop oplis = foldl (\ knil x  -&amp;gt; if (xopSatisfaction oplis x ) [x:knil] knil) [] $ crossProduct $ take n $ repeat tf  where
    n = length oplis  +  1  -  length (filter xopisNot oplis)
xopSatisfaction x org= lp x org where
    lp [And:Not:xs] [y:y2:ys] = lp xs [y &amp;amp;&amp;amp; (not y2):ys]
    lp [And:xs] [y:y2:ys] = lp xs [y &amp;amp;&amp;amp; y2:ys]
    lp [Or:Not:xs]  [y:y2:ys] = lp xs [y || (not y2):ys]
    lp [Or:xs]  [y:y2:ys] = lp xs [y || y2:ys]
    lp []  [y:ys]         = y
    lp _  [] = abort &amp;quot;test&amp;quot;
crossProduct x :== cp [] x where
    cp knil [[x:xs]:ys] = (cp knil [xs:ys]) ++ cp [x:knil] ys
    cp knil [[]:ys] =  []
    cp knil [] =  [knil]
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
    &lt;div align = "right" style="margin-right: 1em;"&gt;
      [&lt;a href="http://ja.doukaku.org/lang/clean/"&gt;
      Clean
      &lt;/a&gt;]
      [&lt;a href="http://ja.doukaku.org/comment/2526/download/"&gt;
      download code
      &lt;/a&gt;]
      &lt;/a&gt;]
    &lt;/div&gt;
    &lt;hr&gt;
  

</description><guid>http://ja.doukaku.org/comment/2526/</guid></item><item><title>mz's comment on Hello, world!
</title><link>http://ja.doukaku.org/comment/2519/</link><description>



&lt;a href="http://ja.doukaku.org/2/"&gt;Hello, world!&lt;/a&gt;
(&lt;a href="http://ja.doukaku.org/2/nested/"&gt;Nested&lt;/a&gt; 
 &lt;a href="http://ja.doukaku.org/2/flatten/"&gt;Flatten&lt;/a&gt;)


&lt;hr&gt;
  &lt;pre class='compact'&gt;よりhaskell風に&lt;/pre&gt;
&lt;hr&gt;
  
    &lt;table&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;pre&gt;1
2
3&lt;/pre&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;module hello
import StdEnv;($) infixr 1;($) a b :== a b;(&amp;gt;&amp;gt;.) infixl 0;(&amp;gt;&amp;gt;.) a b = \ w -&amp;gt; (\ (_, w) -&amp;gt; b w) (a w);(&amp;gt;&amp;gt;=) infixl 0;(&amp;gt;&amp;gt;=) a b = \ w -&amp;gt; (\ (x, w) -&amp;gt; b x w ) (a w);liftM m :== \ lst -&amp;gt; \ w -&amp;gt;  (m lst, w);join del [x:xs]= (toString x) +++ del +++ (join del xs);join _ [] = &amp;quot;&amp;quot;;putStr str = \w -&amp;gt; (stdio &amp;gt;&amp;gt;= liftM ( fwrites str) &amp;gt;&amp;gt;= fclose) w;Start w =snd $ main w;
main = putStr &amp;quot;Hello,&amp;quot; &amp;gt;&amp;gt;. putStr &amp;quot; World!\n&amp;quot;
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
    &lt;div align = "right" style="margin-right: 1em;"&gt;
      [&lt;a href="http://ja.doukaku.org/lang/clean/"&gt;
      Clean
      &lt;/a&gt;]
      [&lt;a href="http://ja.doukaku.org/comment/2519/download/"&gt;
      download code
      &lt;/a&gt;]
      &lt;/a&gt;]
    &lt;/div&gt;
    &lt;hr&gt;
  

</description><guid>http://ja.doukaku.org/comment/2519/</guid></item><item><title>mz's comment on 全ての組み合わせ
</title><link>http://ja.doukaku.org/comment/2517/</link><description>



&lt;a href="http://ja.doukaku.org/44/"&gt;全ての組み合わせ&lt;/a&gt;
(&lt;a href="http://ja.doukaku.org/44/nested/"&gt;Nested&lt;/a&gt; 
 &lt;a href="http://ja.doukaku.org/44/flatten/"&gt;Flatten&lt;/a&gt;)


&lt;hr&gt;
  &lt;pre class='compact'&gt;ブランクありで適当なのでコードがダサいかも。
簡単なので大丈夫なはずだが。
&lt;/pre&gt;
&lt;hr&gt;
  
    &lt;table&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25&lt;/pre&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;module crossproduct
import StdEnv
($) infixr 1;($) a b :== a b;(&amp;gt;&amp;gt;=) infixl 0;(&amp;gt;&amp;gt;=) a b = \ w -&amp;gt; (\ (x, w) -&amp;gt; b x w ) (a w);liftM m :== \ lst -&amp;gt; \ w -&amp;gt;  (m lst, w);
join del [x:xs]= (toString x) +++ del +++ (join del xs);
join _ [] = &amp;quot;&amp;quot;;
:: Elem= ElemChar Char | ElemStr String | ElemInt Int
class toElem a  where
    toElem :: a -&amp;gt; Elem
instance toElem Int where
    toElem a = ElemInt a
instance toElem Char where
    toElem a = ElemChar a
instance toElem String where
    toElem a = ElemStr a
instance toString Elem where
    toString (ElemInt a) = toString a
    toString (ElemStr a) = a
    toString (ElemChar a) = toString a
Start w =snd ((stdio &amp;gt;&amp;gt;= liftM ( fwrites str) &amp;gt;&amp;gt;= fclose) w)
    where str = join &amp;quot;\n&amp;quot; $ map (join &amp;quot;,&amp;quot;) $ crossProduct [] elems2
          elems2 = [map toElem [0,1],map toElem [&amp;#39;ab&amp;#39;], map toElem [&amp;quot;Foo&amp;quot;,&amp;quot;Bar&amp;quot;]]
crossProduct :: [Elem] [[Elem]] -&amp;gt; [[Elem]]
crossProduct knil [[x:xs]:ys] = crossProduct [x:knil] ys ++ (crossProduct knil [xs:ys])
crossProduct knil [[]:ys] =  []
crossProduct knil [] =  [knil]
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
    &lt;div align = "right" style="margin-right: 1em;"&gt;
      [&lt;a href="http://ja.doukaku.org/lang/clean/"&gt;
      Clean
      &lt;/a&gt;]
      [&lt;a href="http://ja.doukaku.org/comment/2517/download/"&gt;
      download code
      &lt;/a&gt;]
      &lt;/a&gt;]
    &lt;/div&gt;
    &lt;hr&gt;
  

</description><guid>http://ja.doukaku.org/comment/2517/</guid></item><item><title>mz's comment on ダブル完全数
</title><link>http://ja.doukaku.org/comment/2492/</link><description>



&lt;a href="http://ja.doukaku.org/25/"&gt;ダブル完全数&lt;/a&gt;
(&lt;a href="http://ja.doukaku.org/25/nested/"&gt;Nested&lt;/a&gt; 
 &lt;a href="http://ja.doukaku.org/25/flatten/"&gt;Flatten&lt;/a&gt;)


&lt;hr&gt;
  &lt;pre class='compact'&gt;&lt;/pre&gt;
&lt;hr&gt;
  
    &lt;table&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13&lt;/pre&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;module doubleperfect
import StdEnv, StdStrictLists, StdOverloadedList
Start w =snd ((stdio &amp;gt;&amp;gt;= liftM ( fwrites str) &amp;gt;&amp;gt;= fclose) w)
    where str = join $ filter isDoublePerfect [1..10001]
isDoublePerfect i = (Foldl (\x y -&amp;gt; x + y) 0 $ divisors i) == (i + i - 1)
divisors i =  [! j + (i/j) \\ j &amp;lt;- [2..(toInt $ sqrt $toReal i)] | (i rem j) == 0 !]
join [x:xs]= toString x +++ &amp;quot;,&amp;quot; +++ join xs
join [] = &amp;quot;&amp;quot;
($) infixr 1
($) a b :== a b
(&amp;gt;&amp;gt;=) infixl 0
(&amp;gt;&amp;gt;=) a b = \ w -&amp;gt; (\ (x, w) -&amp;gt; b x w ) $ a w
liftM m :== \ lst -&amp;gt; \ w -&amp;gt;  (m lst, w)
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
    &lt;div align = "right" style="margin-right: 1em;"&gt;
      [&lt;a href="http://ja.doukaku.org/lang/clean/"&gt;
      Clean
      &lt;/a&gt;]
      [&lt;a href="http://ja.doukaku.org/comment/2492/download/"&gt;
      download code
      &lt;/a&gt;]
      &lt;/a&gt;]
    &lt;/div&gt;
    &lt;hr&gt;
  

</description><guid>http://ja.doukaku.org/comment/2492/</guid></item><item><title>mz's comment on Hello, world!
</title><link>http://ja.doukaku.org/comment/2486/</link><description>



&lt;a href="http://ja.doukaku.org/2/"&gt;Hello, world!&lt;/a&gt;
(&lt;a href="http://ja.doukaku.org/2/nested/"&gt;Nested&lt;/a&gt; 
 &lt;a href="http://ja.doukaku.org/2/flatten/"&gt;Flatten&lt;/a&gt;)


&lt;hr&gt;
  &lt;pre class='compact'&gt;&lt;/pre&gt;
&lt;hr&gt;
  
    &lt;table&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;pre&gt;1
2
3
4
5
6
7
8
9&lt;/pre&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;// hello.icl
module hello
import StdEnv
($) infixr 1
($) a b :== a b
(&amp;gt;&amp;gt;=) infixl 0
(&amp;gt;&amp;gt;=) a b = \ w -&amp;gt; (\ (x, w) -&amp;gt; b x w ) $ a w
liftM m :== \ lst -&amp;gt; \ w -&amp;gt;  (m lst, w)
Start w = snd ((stdio &amp;gt;&amp;gt;= liftM (fwrites &amp;quot;Hello World!\n&amp;quot;) &amp;gt;&amp;gt;= fclose) w)
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
    &lt;div align = "right" style="margin-right: 1em;"&gt;
      [&lt;a href="http://ja.doukaku.org/lang/clean/"&gt;
      Clean
      &lt;/a&gt;]
      [&lt;a href="http://ja.doukaku.org/comment/2486/download/"&gt;
      download code
      &lt;/a&gt;]
      &lt;/a&gt;]
    &lt;/div&gt;
    &lt;hr&gt;
  

</description><guid>http://ja.doukaku.org/comment/2486/</guid></item><item><title>oskimura's comment on 重複無し乱数
</title><link>http://ja.doukaku.org/comment/2270/</link><description>



&lt;a href="http://ja.doukaku.org/46/"&gt;重複無し乱数&lt;/a&gt;
(&lt;a href="http://ja.doukaku.org/46/nested/"&gt;Nested&lt;/a&gt; 
 &lt;a href="http://ja.doukaku.org/46/flatten/"&gt;Flatten&lt;/a&gt;)


&lt;hr&gt;
  &lt;pre class='compact'&gt;Cleanでやってみた。
擬似乱数を生成するライブラリをつかってます。
本当の乱数じゃないので、同じ数を与えると同じ乱数表になってしまう…&lt;/pre&gt;
&lt;hr&gt;
  
    &lt;table&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;pre&gt;1
2
3
4
5&lt;/pre&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;module RandList
import StdEnv, MersenneTwister

Start = bingo 10
bingo n  = map snd  (sort  (zip ((genRandInt n),[1..n])))
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
    &lt;div align = "right" style="margin-right: 1em;"&gt;
      [&lt;a href="http://ja.doukaku.org/lang/clean/"&gt;
      Clean
      &lt;/a&gt;]
      [&lt;a href="http://ja.doukaku.org/comment/2270/download/"&gt;
      download code
      &lt;/a&gt;]
      &lt;/a&gt;]
    &lt;/div&gt;
    &lt;hr&gt;
  

</description><guid>http://ja.doukaku.org/comment/2270/</guid></item></channel></rss>