2012-09-01から1ヶ月間の記事一覧

池袋バイナリ勉強会(2)に参加してきました

9月23日(日)に池袋バイナリ勉強会(2)に参加してきました。 MonoDevelopでHello world! MonoDevelopとGTK#を用いて、ボタンをクリックしたらメッセージダイアログを表示するGUIプログラムを書きました。 MonoDevelopをインストールします。MonoDevelopからダ…

Codeforces 110B - B. Lucky String

110B - B. Lucky String calc :: Int -> String calc n = take n $ cycle "abcd" main = do s <- getLine putStrLn $ calc $ read s

Processing, プロジェクト名と同じ名前のクラスは定義できない。

プロジェクト名(.pdeファイル名)と同じ名前のクラスを定義しようとすると、以下のエラーメッセージが表示されました。 The nested type Test cannot hide an enclosing type

Processingで正三角形を描画する

Processingで正三角形を描画しようと思い、コードを書き始めたけど、すぐに手が止まってしまった。triangle()を使って、3点の座標位置を指定すれば三角形を描画できる。だけど、3点の座標位置はどう決めたら良いのだろうか?そもそも正三角形とはどういう形…

primesパッケージをインストール

primesパッケージをインストールします。 cabal install primes http://hackage.haskell.org/package/primes Prelude Data.Numbers.Primes> take 30 primes [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113] …

Codeforces 37A - A. Towers

37A - A. Towers import Data.List calc :: [Int] -> (Int, Int) calc xs = (maximum [count x xs | x <- xs], length $ nub xs) where count a xs = sum [1 | x <- xs, x == a] main = do s <- getLine t <- getLine let (x, y) = calc $ map read $ words …

Codeforces 122B - B. Lucky Substring

122B - B. Lucky Substring calc :: String -> Int calc s | n4+n7 == 0 = -1 | otherwise = if n4 >= n7 then 4 else 7 where n4 = sum [1 | c <- s, c == '4'] n7 = sum [1 | c <- s, c == '7'] main = do s <- getLine print $ calc s

Codeforces 122A - A. Lucky Division

122A - A. Lucky Division isLucky :: Int -> Bool isLucky n = show n == filter (\c -> c == '4' || c == '7') (show n) calc :: Int -> String calc n = if null [i | i <- [1..n], isLucky i, n `mod` i == 0] then "NO" else "YES" main = do s <- getL…

第4回 スタートHaskell2に参加してきました

第4回 スタートHaskell2 - [PARTAKE] に参加してきました。 第8章「入出力」@igrep さん IO action putStrLn は文字列を引数にとり、()(空のタプル。unit型ともいう)を結果とする I/O アクションを返す do記法。IO actionをつなぎ合わせる。 >>= 関数の構文…

Codeforces 146B - B. Lucky Mask

146B - B. Lucky Mask整数 a, b が与えられたとき、c のマスクが b と等しく、かつ c > a であるような c を求めよという問題。「c のマスクが b と等しい」とは、整数 c から 4 と 7 以外の数字を取り除いた数が b と等しいという意味。制約: 1 全探索。 ma…

Codeforces 221A - A. Little Elephant and Function

221A - A. Little Elephant and Function calc :: Int -> [Int] calc 1 = [1] calc 2 = [2, 1] calc n = [n, 1] ++ [2..n-1] main = do s <- getLine putStrLn $ unwords $ map show $ calc $ read s

Codeforces 26A - A. Almost Prime

26A - A. Almost Prime素因数分解したときに、素因数の種類が 2 つかどうか求める問題。 import Data.List factorize :: Int -> [Int] factorize 1 = [1] factorize n = fac 2 n where fac p n | n == 1 = [] | n `mod` p == 0 = p : fac p (n `div` p) | ot…

Codeforces 148A - A. Insomnia cure

148A - A. Insomnia cure calc :: Int -> Int -> Int -> Int -> Int -> Int calc k l m n d = d - length [i | i <- [1..d], i `mod` k /= 0, i `mod` l /= 0, i `mod` m /= 0, i `mod` n /= 0] main = do s <- getContents let [k, l, m, n, d] = map read …