Open Source WEB



今月の一行


2006-08-31 [bash] 空のファイルをつくる

TPRG:memo(2006-08-31)より

今まで,

$ touch newempty.file

とかやってたけど.

$ > newempty.file

でいいんだ...最短.

でも zsh だと,標準入力から入力まちになるから

% : > newempty.file

が最短か...

--nobsun


Name:
Comment:
cut-sea: (Wed Sep 6 22:35:12 2006 )
alias t touch として最短ってのは。。。ダメ?


2006-08-30 [bash] : コマンド

バカが征く より,

なんかどこかで見たことがあるんですよねぇ.

これだっ! 理屈はよくわからないけど...

--nobsun


Name:
Comment:
cut-sea: (Wed Sep 6 22:13:26 2006 )
たしかnobsunが翻訳されてた三週間の方にもあったような。
あれで初めて知ったし。":";exec ...形。


2006-08-29 [Haskell] 連想リストから関数を作る

なんどか書いたけど,ふたたび.

関数は入力と出力の対の集合だとみなせるから,連想リストから関数が作れることにはなんの不思議はない.

genfun :: Eq a => String -> [(a,b)] -> (a -> b)
genfun msg = foldr add (error msg)

add :: Eq a => (a,b) -> (a -> b) -> (a -> b)
add (k,v) f x = if k == x then v else f x

たとえば,会員番号と会員氏名との連想リストから,会員番号から名前を引くための関数を合成してみよう.

*Main> let who = genfun "Not member" [(1,"GLS"),(2,"rms"),(3,"eiiti")]
*Main> who 1
"GLS"
*Main> who 3
"eiiti"
*Main> who 5
"*** Exception: Not member

--nobsun


Name:
Comment:
cut-sea: (Wed Sep 6 22:32:37 2006 )
あーassoc一発だと思ったんだけど、そっか。

(define (genfun msg alist)
  (define (? k a)
    (cond ((null? a) msg)
          ((eq? k (caar a)) (cadar a))
          (else (? k (cdr a)))))
  (lambda (x)
    (or (? x alist) msg)))

30:user> (define who (genfun "Not member" '((1 "GLS") (2 "rms") (3 "eiiti"))))
=> who
31:user> (who 2)
=> "rms"
32:user> (who 1)
=> "GLS"
33:user> (who 3)
=> "eiiti"
34:user> (who 4)
=> "Not member"
35:user> (who 2)
=> "rms"
koguro: (Fri Sep 8 21:46:54 2006 )
あれ、assoc一発で書けませんか? (エラーチェックは必要ですけど)

(define (getfun msg alist)
  (lambda (v)
    (cdr (or (assoc v alist) (error msg)))))


2006-08-28 [Haskell] 棒グラフ

今さらながら, キミならどう書く2.0 -ROUND 3 - をHaskellでやってみた.

左の数字は無しで '*' だけの印字なら簡単にワンライナーで書ける.といっても リスト記法で引数を渡すことになるけど.

% ghc -e "putStr $ unlines $ [ replicate n '*' | n <- [2,5,9]]"
**
*****
*********

左から右へ伸ばすのではなく下から上へ伸ばすには,

% ghc -e "putStr $ unlines $ reverse $ takeWhile (not . null . words) $ Data.List.transpose $ [replicate n '*' ++ repeat ' ' | n <- [2,5,9]]"
  *
  *
  *
  *
 **
 **
 **
***
***

どうだっ!

--nobsun


Name:
Comment:

There is no comment.


2006-08-25 [Haskell] 特定の条件に適合する要素だけ写像する

リストの要素のうち,特定の条件にあうものだけを写像したり,畳み込んだり したい場合がよくある.そんなときたとえば,

map f $ filter p xs

とか

foldr f e $ filter p xs

のように filter してから,map や foldr すればよいのだが, 中間のリストの生成が気になる.そこで,中間リストを生成しないように mapWhen とか foldrWhen を定義してみよう.

mapWhen :: (a -> Bool) -> (a -> b) -> [a] -> [b]
mapWhen p f [] = []
mapWhen p f (x:xs)
  | p x       = f x : mapWhen p f xs
  | otherwise = mapWhen p f xs

foldrWhen :: (a -> Bool) -> (a -> b -> b) -> b -> [a] -> b
foldrWhen p f e [] = e
foldrWhen p f e (x:xs) 
  | p x       = f x (foldrWhen p f e xs)
  | otherwise = foldrWhen p f e xs

また,無限リストから有限部分をとりだす時によくつかう takeWhile と組み合せた mapWhile や foldrWhile も定義しておくと便利.

mapWhile :: (a -> Bool) -> (a -> b) -> [a] -> [b]
mapWhile p f [] = []
mapWhile p f (x:xs)
 | p x       = f x : mapWhile p f xs
 | otherwise = []

foldrWhile :: (a -> Bool) -> (a -> b -> b) -> b -> [a] -> b
foldrWhile p f e [] = e
foldrWhile p f e (x:xs) 
 | p x       = f x (foldrWhen p f e xs)
 | otherwise = e

--nobsun


Name:
Comment:

There is no comment.


2006-08-24 [Haskell] 「マヤ文献の解読」

The 18th International Olympiad in Informatics が 8/13 - 8/20 にあったそうです.

そのときの第一日目課題1 Deciphering the Mayan Writingを(やさしそうなので ^^;)解いてみました.といっても,パターン照合は素朴にしかやっていないので,メチャ効率悪い.これじゃ得点できないかなぁ.

module Main where

import Data.List (transpose, sort, inits, tails)

contElems :: Int -> [a] -> [[a]]
contElems n = (!!n) . transpose . map inits . tails

main :: IO ()
main = do cs <- getContents
          case words cs of
             l:_:w:s:_ -> putStrLn $ show 
                                   $ length 
                                   $ filter ((sort w ==) . sort) 
                                   $ contElems (read l) s

--nobsun


Name:
Comment:

There is no comment.


2006-08-23 [Haskell] Hamming 問題

以下の条件を満す非負整数列 {A(n) | n∈N}を求めよ.

  1. i < j ならば A(i) < A(j)
  2. i ≠ j ならば A(i) ≠ A(j)
  3. 1 ∈ {A(n)}
  4. x ∈ {A(n)} ならば x*2 ∈ {A(n)} ∧ x*3 ∈ {A(n)} ∧ x*5 ∈ {A(n)}
  5. 3.,4. 以外の数は含まれない

要するに,2^p * 3^q * 5^r (p,q,rは共に非負整数) によって作られる数を 重複なく小さい方から順にならべればよい.

hamming = 1 : merge (map (2*) hamming)
                    (merge (map (3*) hamming)
                           (map (5*) hamming))

merge xxs@(x:xs) yys@(y:ys) | x < y     = x : merge xs  yys
                            | x > y     = y : merge xxs ys
                            | otherwise = x : merge xs  ys

hamming の定義で merge や map (n*) hamming の繰り返しが気になる向きには

hamming = 1 : foldr1 merge (map (flip map hamming . (*)) [2,3,5])

などという定義はいかが?

--nobsun


Name:
Comment:

There is no comment.


2006-08-22 [Haskell] 有理数の値を指定した桁数だけ表示する

有理数の値を小数点以下,指定桁だけ表示したいことがたまにある.

import Ratio

showRational :: Int -> Rational -> String
showRational n r = h++('.':l)
  where dm0 = divMod x y
        x = numerator r
        y = denominator r
        s = take (n+1) $ iterate (flip divMod y . (10*) . snd) dm0
        h = show $ fst $ head s
        l = concatMap (show . fst) $ tail s

実行例 355/113 を 10 桁まで

*Main> showRational 10 (355 % 113)
"3.1415929203"

--nobsun


Name:
Comment:

There is no comment.


2006-08-21 [Haskell] 第5回 日本情報オリンピック 本選 問題5 入力9

2006-08-18で書いた素朴な実装では,用意されていた 入力9のような大規模な問題が解けない.

  1. 効率が悪い.
  2. 計算機資源を食いつくす.

という理由からだ.1.の方はアルゴリズムを見直すことで解決するのだが, 2. の方はHaskellでは計算が内部でどのように行われるのかという言語系の 知識がすこし必要になる.

Y軸に平行な直線を X軸方向にずらして行きながら,長方形のY軸に平行な辺 に当たるごとに,処理を重ねるように考える.あんまり整理されていないが 次のようにプログラムすると,入力9を食わせても大丈夫.

module Main where

import Data.List
import System.Environment

type Rect = (Int,Int,Int,Int)

xscmp (x,_,_,_) (x',_,_,_) = compare x x'
xecmp (_,_,x,_) (_,_,x',_) = compare x x'
yscmp (_,y,_,_) (_,y',_,_) = compare y y'

xseq (x,_,_,_) (x',_,_,_) = x == x'
xeeq (_,_,x,_) (_,_,x',_) = x == x'

quadruple :: [Int] -> (Int,Int,Int,Int)
quadruple (a:b:c:d:_) = (a,b,c,d)

yintv :: Rect -> (Int,Int)
yintv (_,s,_,e) = (s,e)

intvadd :: (Int,Int) -> (Int,Int) -> [(Int,Int)]
intvadd (s0,e0) (s1,e1)
 | e0 < s1   = [(s0,e0),(s1,e1)]
 | s0 > e1   = [(s1,e1),(s0,e0)]
 | otherwise = [(min s0 s1, max e0 e1)]

intvadds' :: [(Int, Int)] -> (Int,Int) -> [(Int,Int)]
intvadds' [] iv = [iv]
intvadds' ivss@(iv0@(s0,e0):ivs) iv1@(s1,e1)
 | s0 > e1   = iv1 : ivss
 | e0 < s1   = iv0 : intvadds' ivs iv1
 | otherwise = foldl' intvadds' ivs $ intvadd iv1 iv0

intvadds :: [(Int,Int)] -> [(Int,Int)] -> [(Int,Int)]
intvadds = foldl' intvadds' 

intvsubs' :: [(Int, Int)] -> (Int,Int) -> [(Int,Int)]
intvsubs' [] intv = []
intvsubs' ivss@(iv0@(s0,e0):ivs) iv1@(s1,e1)
 | e0 <= s1 = iv0:intvsubs' ivs iv1
 | s0 >= e1 = ivss
 | s0 <  s1 && e0 >  e1 = (s0,s1):(e1,e0):ivs
 | s0 >= s1 && e0 <= e1 = intvsubs' ivs iv1
 | s0 >= s1             = (e1,e0) : ivs
 | otherwise            = (s0,s1):intvsubs' ivs iv1

intvsubs :: [(Int,Int)] -> [(Int,Int)] -> [(Int,Int)]
intvsubs = foldl' intvsubs'

yis :: [Rect] -> [(Int,Int)]
yis = intvadds [] . sort . map yintv

height :: [Rect] -> Int 
height = sum . map (uncurry subtract) . yis

scanByX1 :: Int -> Int -> [Rect] -> [[Rect]] -> [[Rect]] -> Int
scanByX1 a _ _ [] [] = a
scanByX1 a x rs [] (ers:erss)
 = let (_,_,x',_) = head ers
       h          = height rs
       rs'        = rs \\ ers
       da         = h * (x'-x)
   in a `seq` scanByX1 (a+da) x' rs' [] erss
scanByX1 a x rs ss@(srs:srss) es@(ers:erss)
 = let (sx,_,_,_) = head srs
       (_,_,ex,_) = head ers
       h          = height rs
       (a',x',rs',ss',es')
         = case compare sx ex of
             LT -> let rs'' = rs++srs
                       da   = h * (sx-x)
                   in (a+da,sx,rs'',srss,es)
             GT -> let rs'' = rs \\ ers
                       da   = h * (ex-x)
                   in (a+da,ex,rs'',ss,erss)
             EQ -> let rs'' = (rs \\ ers) ++ srs
                       da   = h * (sx-x)
                   in (a+da,sx,rs'',srss,erss)
   in a `seq` scanByX1 a' x' rs' ss' es'

scanByX2 :: Int -> Int -> Int -> [Rect] -> [[Rect]] -> [[Rect]] -> (Int,Int)
scanByX2 a p _ _ [] [] = (a,p)
scanByX2 a p x rs [] (ers:erss)
 = let (_,_,x',_) = head ers
       h          = height rs
       h'         = height rs'
       rs'        = rs \\ ers
       da         = h * (x'-x)
       sec        = intvadds [] (map yintv rs)
       dp         = length sec * (x' - x) * 2 + h - h'
   in a `seq` p `seq` scanByX2 (a+da) (p+dp) x' rs' [] erss
scanByX2 a p x rs ss@(srs:srss) es@(ers:erss)
 = let (sx,_,_,_) = head srs
       (_,_,ex,_) = head ers
       h          = height rs
       sec        = intvadds [] (map yintv rs)
       (a',p',x',rs',ss',es')
         = case compare sx ex of
             LT -> let rs'' = rs++srs
                       h'   = height rs''
                       da   = h * (sx-x)
                       dp   = length sec * (sx-x) * 2 + h' - h
                   in (a+da,p+dp,sx,rs'',srss,es)
             GT -> let rs'' = rs \\ ers
                       h'   = height rs''
                       da   = h * (ex-x)
                       dp   = length sec * (ex-x) * 2 + h - h'
                   in (a+da,p+dp,ex,rs'',ss,erss)
             EQ -> let rs'' = (rs \\ ers) ++ srs
                       irs  = yis rs
                       irs''= yis rs''
                       eys  = yis ers
                       sys  = yis srs
                       eh   = sum $ map (uncurry subtract) $ intvsubs eys irs''
                       sh   = sum $ map (uncurry subtract) $ intvsubs sys irs
                       da   = h * (sx-x)
                       dp   = length sec * (sx-x) * 2 + sh + eh
                   in (a+da,p+dp,sx,rs'',srss,erss)
   in a `seq` p `seq` scanByX2 a' p' x' rs' ss' es'

main :: IO ()
main = do cs <- getContents
          let ls    = lines cs
              [n,t] = map read $ words $ head ls
              rs    = sortBy yscmp $ map (quadruple . map read . words) 
                                   $ take n $ tail ls
              srss  = groupBy xseq $ sortBy xscmp rs
              erss  = groupBy xeeq $ sortBy xecmp rs
              a1      = scanByX1 0 0 [] srss erss
              (a2,p2) = scanByX2 0 0 0 [] srss erss
          if t == 1 
             then putStrLn (show a1)
             else putStrLn (show a2) >> putStrLn (show p2)

--nobsun


Name:
Comment:

There is no comment.


2006-08-18 [Haskell] 第5回 日本情報オリンピック 本選問題(その5)

さらに,さらに,さらに,2006-08-17に引き続き, 問題5をやってみよう. とりあえず,素朴な実装

module Main where

import Data.List

type Shape = [(Int,Int)]

mkRect :: [Int] -> Shape
mkRect (a:b:c:d:_) = [(x,y) | x <- [a .. c-1], y <- [b .. d-1]]

aproxs :: (Int,Int) -> [(Int,Int)]
aproxs (x,y) = [(x-1,y),(x,y-1),(x+1,y),(x,y+1)]

peri :: Shape -> (Int,Int) -> Int
peri s t = length $ filter (not . flip mem s) $ aproxs t

mem :: (Int,Int) -> [(Int,Int)] -> Bool
mem x []              = False
mem x (y:ys) | x < y  = False
             | x > y  = mem x ys
             | otherwise = True

ins :: [(Int,Int)] -> (Int,Int) -> [(Int,Int)]
ins [] x         = [x]
ins yys@(y:ys) x = case compare x y of
                     LT -> x:yys
                     GT -> y:ins ys x
                     EQ -> yys

peripheral :: Shape -> Int
peripheral s = sum $ map (peri s) s

main :: IO ()
main = do cs <- getContents
          let ls      = lines cs
              (n:t:_) = map read $ words $ head ls
              rs      = take n $ tail ls
              shape   =  foldl' ins [] $ concatMap (mkRect . map read . words) rs
              perilen = peripheral shape
              area    = length shape
          if t == 1 then putStrLn $ show area
                    else mapM_ putStrLn $ map show [area,perilen]

公開されている 入力1をくわせてみよう. 公開されている 正解

709
120

である.

% runhaskell jolymp5.hs < 2006-ho-t5-in9
709
120

パチパチ.

ちょと!待ったぁ!入力9 をくわせてみよ.だめだめだろう!?

改良版は宿題としておこう.おっ.

--nobsun


Name:
Comment:

There is no comment.


2006-08-17 [Haskell] 第5回 日本情報オリンピック 本選問題(その4)

さらに,さらに,2006-08-16に引き続き, 問題4をやってみよう. ちょっと考えないと難しい.グラフ表現の作成と深さ優先探索がキモかな.

module Main where

import Data.Array
import Data.List

type Graph = Array Int [Int]

mkGraph :: [(Int,Int)] -> Graph
mkGraph xs = accum (flip (:)) (listArray bs (repeat [])) xs
  where rs  = sort $ map fst xs
        bs  = (head rs, last rs)

bidirs :: [(Int,Int)] -> [(Int,Int)]
bidirs = concatMap (\ xy -> swap xy:[xy])
  where swap (x,y) = (y,x)

dfs :: Int -> Graph -> [Int]
dfs s g = reverse (fs [s] [])
  where fs [] vis = vis
        fs (c:cs) vis
           | elem c vis = fs cs vis
           | otherwise  = fs (g ! c) (c:vis)

main :: IO ()
main = do cs <- getContents
          let ls = lines cs
              l  = read $ head $ words $ head ls
              rs = take l $ tail ls
              es = bidirs $ map (mkpair . map read . words) rs
              g  = mkGraph es
              ps = map (flip dfs g) $ range (bounds g)
          putStrLn (show (maximum (map length ps)))
  where mkpair (x:y:_) = (x,y)

公開されている入力9をくわせて, 公開されている 正解 は 20 である.

% cat 2006-ho-t4-in9
98
41 42
41 43
41 44
41 45
41 46
41 47
41 48
41 49
41 50
42 43
42 44
42 45
42 46
42 47
42 48
42 49
42 50
43 44
43 45
43 46
43 47
43 48
43 49
43 50
44 45
44 46
44 47
44 48
44 49
44 50
45 46
45 47
45 48
45 49
45 50
46 47
46 48
46 49
46 50
47 48
47 49
47 50
48 49
48 50
49 50
11 30
12 30
13 30
14 30
15 30
16 30
17 30
18 30
19 30
20 30
21 30
22 30
23 30
24 30
25 30
26 30
27 30
28 30
29 30
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
11 29
1 4
1 5
1 6
1 7
1 8
2 4
2 5
2 6
2 7
2 8
3 4
3 5
3 6
3 7
3 8
% runhaskell jolymp4.hs < 2006-ho-t4-in9
20

パチパチ

--nobsun


Name:
Comment:

There is no comment.


2006-08-16 [Haskell] 第5回 日本情報オリンピック 本選問題(その3)

さらに,2006-08-15に引き続き, 問題3をやってみよう. この問題も Data.List.group を使うと上手くいく.

module Main where

import Data.List 

splits1 [x] = []
splits1 (x:xs) = ([x],xs):[ (x:zs,ws) | (zs,ws) <- splits1 xs]

splits1' xs = ([],xs):splits1 xs

step :: Int -> [[Int]]
step 1 = [[1]]
step n = map head $ group $ sortBy (flip compare)
       $ concatMap f ps ++ map (++[1]) ps
          where ps = step (n-1)

f :: [Int] -> [[Int]]
f xs = map g $ splits1' $ group xs
g (xs,y@(z:zs):ys) = concat $ xs++(z+1:zs):ys

showIntList :: [Int] -> String
showIntList = unwords . map show

main :: IO ()
main = getContents >>= putStr . unlines . map showIntList 
                              . step . read . head . words

これも公開されている入力5をくわせて, 公開されている正解と比較してみる.(改行コードを合せておくこと)

% cat 2006-ho-t3-in5
29
% runhaskell jolymp3.hs < 2006-ho-t3-in5 | diff - 2006-ho-t3-out
%

パチパチ

--nobsun


Name:
Comment:

There is no comment.


2006-08-15 [Haskell] 第5回 日本情報オリンピック 本選問題(その2)

2006-08-14に引き続き, 問題2をやってみよう. Haskell では Prelude.iterate と Data.List.group を使うことに気づけば, 易しいかな.

module Main where

import Data.List (group)

op :: String -> String
op = concatMap f . group
 where f s = show (length s) ++ [head s]

main :: IO ()
main = do cs <- getContents
          case map (head . words) $ lines cs of
            n:s:_ -> putStrLn $ iterate op s !! read n

これも公開されている入力5をくわせて, 公開されている正解と比較してみる.(改行コードを合せておくこと)

% cat 2006-ho-t2-in5
20
6541654132438671867231213514354868768761575142413241246541681796196565432431541354987811213332266915
% runhaskell jolymp2.hs < 2006-ho-t2-in5 | diff - 2006-ho-t2-out
%

パチパチ

--nobsun


Name:
Comment:

There is no comment.


2006-08-14 [Haskell] 第5回 日本情報オリンピック 本選問題(その1)

世界大会への登竜門?らしい.参加対象者は中学生・高校生とのこと. そのときの問題が公開されている.言語は C,C++,Java に限られているようだ.

問題1をやってみた.

module Main where
import Data.List

main :: IO ()
main = do cs <- getContents
          case lines cs of
            h:ls -> putStr
                    $ unlines $ (:[]) $ unwords
                    $ map show $ map fst $ sortBy cmp $ zip [1..]
                    $ transpose $ map (map read) $ map words ls
            where cmp (_,xs) (_,ys) = compare (sum ys) (sum xs)

入出力は,問題ではファイルをつかうことになっているが 標準入出力を使うほうが試しやすいのでそのようにしてある.

公開されている入力データ5を使って計算させてみよう. 正解も公表されている.

% runhaskell 2006-ho-t1.hs < 2006-ho-t1-in5
13 92 78 91 98 16 38 36 37 57 66 76 80 89 93 94 11 25 27 1 17 28 43 41 56 84 14 31 63 70 99 72 40 42 54 8 15 10 34 44 100 69 79 85 4 59 90 3 74 50 51 53 18 39 60 64 5 77 97 9 68 81 2 21 24 67 30 65 29 20 23 96 6 19 26 86 47 49 82 55 88 73 95 45 12 35 61 7 48 52 83 87 33 58 62 75 71 32 22 46

--nobsun


Name:
Comment:

There is no comment.


2006-08-11 [Haskell] シェルピンスキーのガスケット

『プログラマの数学』によると Pascal の三角形の数字の偶数奇数を塗り分けるとなんとシェルピンスキーのガスケットが現れるらしい. ちょっとやってみよう

pascal = [1]:[zipWith (+) ([0]++p) (p++[0]) | p <- pascal]
disp = map (\ i -> if even i then '.' else '#')

と定義(sierpinski.hs)しておいて,ghci に読み込む.

% ghci sierpinski.hs
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.5.20060804, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base ... linking ... done.
[1 of 1] Compiling main:Main        ( sierinski.hs, interpreted )
Ok, modules loaded: Main.
*main:Main> 

こうしておいて,mapM_ putStrLn $ map disp $ take 64 pascal を評価すると

*main:Main> mapM_ putStrLn $ map disp $ take 64 pascal
#
##
#.#
####
#...#
##..##
#.#.#.#
########
#.......#
##......##
#.#.....#.#
####....####
#...#...#...#
##..##..##..##
#.#.#.#.#.#.#.#
################
#...............#
##..............##
#.#.............#.#
####............####
#...#...........#...#
##..##..........##..##
#.#.#.#.........#.#.#.#
########........########
#.......#.......#.......#
##......##......##......##
#.#.....#.#.....#.#.....#.#
####....####....####....####
#...#...#...#...#...#...#...#
##..##..##..##..##..##..##..##
#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#
################################
#...............................#
##..............................##
#.#.............................#.#
####............................####
#...#...........................#...#
##..##..........................##..##
#.#.#.#.........................#.#.#.#
########........................########
#.......#.......................#.......#
##......##......................##......##
#.#.....#.#.....................#.#.....#.#
####....####....................####....####
#...#...#...#...................#...#...#...#
##..##..##..##..................##..##..##..##
#.#.#.#.#.#.#.#.................#.#.#.#.#.#.#.#
################................################
#...............#...............#...............#
##..............##..............##..............##
#.#.............#.#.............#.#.............#.#
####............####............####............####
#...#...........#...#...........#...#...........#...#
##..##..........##..##..........##..##..........##..##
#.#.#.#.........#.#.#.#.........#.#.#.#.........#.#.#.#
########........########........########........########
#.......#.......#.......#.......#.......#.......#.......#
##......##......##......##......##......##......##......##
#.#.....#.#.....#.#.....#.#.....#.#.....#.#.....#.#.....#.#
####....####....####....####....####....####....####....####
#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#
##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##
#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#
################################################################

おおっ.

--nobsun


Name:
Comment:

There is no comment.


2006-08-10 [Eclipse] Mac OS X 10.4、Eclipse 3.2でEUC-JPのJavaソースを編集する

EUC-JPで書かれたJavaソースを読み込む前に、プロジェクト設定でエンコーディングをEUC-JPに変更する。 (読み込んだ後にエンコーディングを変更すると文字化けが直らないことがある)

パッケージエクスプローラー上でプロジェクト名をCtrl+クリックしてコンテキストメニューから「プロパティ」を選ぶ。

「プロパティー」ダイアログが表示されるので、「情報」セクションで「テキスト・ファイル・エンコード」で「その他」を選び、コンボボックスに「EUC-JP」と入力する。

「OK」ボタンを押して「プロパティー」ダイアログを閉じる。

エンコーディングを変更したら、このプロジェクトにEUC-JPで書かれたJavaソースをインポートする。

--yasuyuki


Name:
Comment:

There is no comment.


2006-08-09 [Eclipse] Mac OS X 10.4でEclipse 3.2を日本語化する

http://download.eclipse.org/eclipse/downloads/drops/R-3.2-200606291905/index.php

上記からMac OS X用のインストールファル eclipse-SDK-3.2-macosx-carbon.tar.gz をダウンロードする。

上記はUniversal BinaryなのでIntel Macでもネイティブ動作する。

上記を展開するとeclipseというディレクトリが出来るので、適切なディレクトリに保存する。

例:

cd /Applications
sudo tar xvfz ~/Desktop/eclipse-SDK-3.2-macosx-carbon.tar.gz

この時点でまだEclipseを起動してはいけない。

次に日本語化パッケージをダウンロードする。

http://download.eclipse.org/eclipse/downloads/drops/L-3.2_Language_Packs-200607121700/index.php

上記からWindows用の日本語化パッケージ NLpack1-eclipse-SDK-3.2-win32.zip をダウンロードする。

上記を展開するとeclipseというディレクトリが出来る。これをEclipseのインストールディレクトリに上書きする。

例:

cd /Applications
unzip ~/Desktop/NLpack1-eclipse-SDK-3.2-win32.zip

eclipseディレクトリのEclipseアイコンをダブルクリックして起動すると日本語化されている。

--yasuyuki


Name:
Comment:

There is no comment.


2006-08-08 [Linux] SWAP領域を増やす

例えばメモリーを1GB増設したら、SWAP領域も1GB増やしておこう。

まず、以下をroot権限で実行する。

# mkdir /SWAP
# dd if=/dev/zero of=/SWAP/SWAPFILE bs=1024 count=1024K
# mkswap /SWAP/SWAPFILE
# swapon /SWAP/SWAPFILE

SWAP領域が追加されたことを確認するにはswapon -sを実行する。

# swapon -s
Filename                                Type            Size    Used    Priority
/dev/hda3                               partition       995988  591036  -1
/SWAP/SWAPFILE                          file            1048568 0       -2

起動時にSWAP領域として追加するには/etc/fstabに/SWAP/SWAPFILEを追加する。

/SWAP/SWAPFILE  swap            swap    defaults                0       0

参考文献: http://www.geocities.co.jp/SiliconValley-Cupertino/9120/tips.html#swapspace

--yasuyuki


Name:
Comment:

There is no comment.


2006-08-07 [Linux] ネイティブスレッドがサポートされているかどうか調べる

getconf GNU_LIBPTHREAD_VERSION

上記を実行し、結果文字列にNPTLが含まれていればネイティブスレッドが動作している。

例:

 NPTL 2.3.6

--yasuyuki


Name:
Comment:

There is no comment.


2006-08-04 [Java] Widows XP SP2、IE6でJavaアプレットを実行させる

Windows XP SP2のIE6では、<APPLET>タグで埋め込まれたJavaアプレットが動作しない。

Javaアプレットを動作させるには、 [スタート]-[設定]-[コントロールパネル]で「Java」をダブルクリックし、 「詳細」タブの「<APPLET>タグのサポート」セクションで「Internet Explorer」を選択する。

--yasuyuki


Name:
Comment:

There is no comment.


2006-08-03 [Java] Widows XP SP2、Java 2 SE 5.0でJavaコンソールを表示させる

FirefoxやIEなどのブラウザ側の設定を見てもこのオプションは見つからない。

Javaコンソールを表示させるには、 [スタート]-[設定]-[コントロールパネル]で「Java」をダブルクリックし、 「詳細」タブの「Javaコンソール」セクションで「コンソールを表示する」を選択する。

--yasuyuki


Name:
Comment:

There is no comment.


2006-08-02 [Haskell] 入試問題(その12)

http://www.i.u-tokyo.ac.jp/edu/course/ci/pdf/ci-2006-programming-2nd.pdf の問題 4-2 最後の問題

-- 4-2

cs42 :: CellSpace
cs42 = take 65 $ concat $ iterate (0:) [0,1]

m42 :: StateFun
m42 = gen 250

a42 :: IO ()
a42 = printTransition 2000 51 $ iterate (extrarule . trans m42) cs42

c0 を特別扱いしたものを適用すると

.#..#...#....#.....#......#.......#........#.........#..........#
#.##.#.#.#..#.#....#.#.....#.#......#.#.......#.#........#.#.........#.
.###.#.#.##.#.#..#.#.#....#.#.#.....#.#.#......#.#.#.......#.#.#........#.#
.####.#.###.#.##.#.#.#..#.#.#.#....#.#.#.#.....#.#.#.#......#.#.#.#.......#.#
.#####.####.###.#.#.##.#.#.#.#..#.#.#.#.#....#.#.#.#.#.....#.#.#.#.#......#.#
.###############.#.###.#.#.#.##.#.#.#.#.#..#.#.#.#.#.#....#.#.#.#.#.#.....#.#
.################.####.#.#.###.#.#.#.#.##.#.#.#.#.#.#..#.#.#.#.#.#.#....#.#
.######################.#.####.#.#.#.###.#.#.#.#.#.##.#.#.#.#.#.#.#..#.#
.#######################.#####.#.#.####.#.#.#.#.###.#.#.#.#.#.#.##.#
.##############################.#.#####.#.#.#.####.#.#.#.#.#.###
################################.######.#.#.#####.#.#.#.#.###
########################################.#.######.#.#.#.###
#########################################.#######.#.#.###
##################################################.#.###
###################################################.###
######################################################
#####################################################
####################################################
###################################################
##################################################
#################################################
################################################
###############################################
##############################################
#############################################
############################################
###########################################
##########################################
#########################################
########################################
#######################################
######################################
#####################################
####################################
###################################
##################################
#################################
################################
###############################
##############################
#############################
############################
###########################
##########################
#########################
########################
#######################
######################
#####################
####################
###################

ほほう.なかなか面白い形ですな. では c0 を特別あつかいしないほうは?

.#..#...#....#.....#......#.......#........#.........#..........#
#.##.#.#.#..#.#....#.#.....#.#......#.#.......#.#........#.#.........#.
.###.#.#.##.#.#..#.#.#....#.#.#.....#.#.#......#.#.#.......#.#.#........#.#
####.#.###.#.##.#.#.#..#.#.#.#....#.#.#.#.....#.#.#.#......#.#.#.#.......#.#.
#####.####.###.#.#.##.#.#.#.#..#.#.#.#.#....#.#.#.#.#.....#.#.#.#.#......#.#.
###############.#.###.#.#.#.##.#.#.#.#.#..#.#.#.#.#.#....#.#.#.#.#.#.....#.#.
################.####.#.#.###.#.#.#.#.##.#.#.#.#.#.#..#.#.#.#.#.#.#....#.#.
######################.#.####.#.#.#.###.#.#.#.#.#.##.#.#.#.#.#.#.#..#.#.
#######################.#####.#.#.####.#.#.#.#.###.#.#.#.#.#.#.##.#.
##############################.#.#####.#.#.#.####.#.#.#.#.#.###.
###############################.######.#.#.#####.#.#.#.#.####
#######################################.#.######.#.#.#.####
########################################.#######.#.#.####
#################################################.#.####
##################################################.####
######################################################
#####################################################
####################################################
###################################################
##################################################
#################################################
################################################
###############################################
##############################################
#############################################
############################################
###########################################
##########################################
#########################################
########################################
#######################################
######################################
#####################################
####################################
###################################
##################################
#################################
################################
###############################
##############################
#############################
############################
###########################
##########################
#########################
########################
#######################
######################
#####################
####################
###################

あまり違わないように見える.でも,こちらの方が微妙に整ってみえる.

--nobsun


Name:
Comment:

There is no comment.


2006-08-01 [Haskell] 入試問題(その11)

http://www.i.u-tokyo.ac.jp/edu/course/ci/pdf/ci-2006-programming-2nd.pdf の問題 4-1 である.

追加ルールをかませてある.

-- 4-1

cs41 :: CellSpace
cs41 = take 100 [ if count n == 3 then 1 else 0 | n <- [0..] ]

m41 :: StateFun
m41 = gen 53

a41 :: IO ()
a41 = printTransition 2000 501 $ iterate (extrarule . trans m41) cs41

a41 を評価してみると,

*Main> a41
.......#...#.##....#.##..##.#......#.##..##.#....##.#...#..........#.##..##.#....##.#...#........##.
######.##.##..##.##..#....######.##..#....####....###.#########.##..#....####....###.#######....
......#..#..#....#..#.###........#..#.###......##.....#..........#..#.###......##.....#........##..
#####.##.##.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....#
.....#..#..#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##...
####.##.##.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....##
....#..#..#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##....
###.##.##.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....###
...#..#..#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##.....
##.##.##.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....####
..#..#..#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##......
#.##.##.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....#####
.#..#..#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##.......
.##.##.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######
#..#..#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........
##.##.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.
..#..#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#
#.##.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.#
.#..#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#.
.##.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##
#..#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..
##.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.
..#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#
#.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.#
.#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#.
.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##
#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..
.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##
#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..
.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##
#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..
.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##
#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..
.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##
#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..
.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##
#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..
.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##
#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..
.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##
#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..
.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##
#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..
.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##
#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..
.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##
#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..
.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##
#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..
.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##
#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..

初期パターンが右へ移動していき,あるところから動かなくなる. なるほど,これが, c0 を特別あつかいした結果なんですねぇ.

では,ただし書きを無視するとどうなるかな.後のほうの extrarule 関数を 使って,a0 を評価すると...

*main:Main> a41
.......#...#.##....#.##..##.#......#.##..##.#....##.#...#..........#.##..##.#....##.#...#........##.
######.##.##..##.##..#....######.##..#....####....###.#########.##..#....####....###.#######....
......#..#..#....#..#.###........#..#.###......##.....#..........#..#.###......##.....#........##..
#####.##.##.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....#
.....#..#..#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##...
####.##.##.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....##
....#..#..#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##....
###.##.##.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....###
...#..#..#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##.....
##.##.##.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....####
..#..#..#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##......
#.##.##.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....#####
.#..#..#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##.......
.##.##.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######
#..#..#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........
##.##.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.
..#..#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#
#.##.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.#
.#..#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#.
.##.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##
#..#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..
##.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.
..#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#
#.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.#
.#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#.
.###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##
#....#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..
###.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##.
...#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..#.
##.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##.#
..#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..#..
#.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##.##
.#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..#...
.##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##.###
#..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..#....
##.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##.###.
..#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..#....#
#.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##.###.#
.#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..#....#.
.##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##.###.##
#..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..#....#..
##....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##.###.##.
..##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..#....#..#
#....######.##.##....####....###.#########.##.##....####....###.#######....######.##.##.###.##.#
.##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..#....#..#.
...######.##.##....####....###.#########.##.##....####....###.#######....######.##.##.###.##.##.
##........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..#....#..#..
..######.##.##....####....###.#########.##.##....####....###.#######....######.##.##.###.##.##..
#........#..#..##......##.....#..........#..#..##......##.....#........##........#..#..#....#..#..#
.######.##.##....####....###.#########.##.##....####....###.#######....######.##.##.###.##.##...
.......#..#..##......##.....#..........#..#..##......##.....#........##........#..#..#....#..#..##.

今度はパターンが左へ左へと流れているようだ.

--nobsun


Name:
Comment:

There is no comment.


このサイトは、 IPA の「平成15年度オープンソフトウエア活用基盤整備事業」 の委託事業として開発されたKahuaで試験的に運用しております。

Copyright (c) 2004-2007 株式会社タイムインターメディア About Us