TwitterToMail Alpha

Twitterの最低限の機能をメールで済ませてしまおうという計画のもとに作ったスクリプト.要PEAR::Mail,PEAR::Net::POP3
APIを使わないのは回数制限を回避するため,自分のTLを使わないのは遅延を回避するため,のつもり.
まだ投稿部分ができていない.fooとかbarとか多いのは,行き当たりばったりに作っているので勘弁.
コピーレフトなのでむしろ誰か改良して私にください.

続きを読む

数列モジュール

-- Haskell, 090104

module Sequence (prime, fibonacci, factorial, trianglar) where

import qualified Prime (prime)

-- 素数
prime = Prime.prime

-- フィボナッチ数
fibonacci :: Integral a => [a]
fibonacci = 1 : 1 : zipWith (+) fibonacci (tail fibonacci)

-- 階乗
factorial :: Integral a => [a]
factorial = 1 : zipWith (*) factorial [2..]

-- 三角数
trianglar :: Integral a => [a]
trianglar = zipWith (+) [1..] (0 : trianglar)

MakeYourDay

無用の科学あるいは錬金術様にて公開されたMakeYourDayのスクリプトtwitterの仕様変更のためか動かなかったので修正.
致命的なのは41行目の正規表現.以下のように修正すれば動きました.

# Ruby, 20090102

/<span class="entry-content">\s*(.+?)(\s*<a href="http:\/\/twitter\.com\/[^\/]+\/status\/\d+">\.\.\.<\/a>|\s*)<\/span>\s*<span class="meta entry-meta">\s*<a href="http:\/\/twitter\.com\/[^\/]+\/status\/(\d+)" class="entry-date" rel="bookmark"><span class="published" title="(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d)\:(\d\d)\:\d\d\+00\:00">/

また,この正規表現のすぐ上にあるif文は必要なさそうなので,削っても良いでしょう.

Problem 26

http://projecteuler.net/index.php?section=problems&id=26

--Haskell (needs -package containers), 20090102

import List (elemIndex)
import Maybe (fromJust)
import Data.Map (findMax, fromList)

search :: Int -> (Int, Int)
search n = (fromJust $ search' Nothing 1 [], n)
  where
    search' :: Maybe Int -> Int -> [Int] -> Maybe Int
    search' _        0 _ = Just 0
    search' (Just k) _ _ = Just (k+1)
    search' Nothing  t l = search' (elemIndex t l) (t*10`mod`n) (t:l)

main = print $ snd $ findMax $ fromList $ map search [2..999]

改善の余地あり.

Problem 18

http://projecteuler.net/index.php?section=problems&id=18

--Haskell (Input data from STDIN), 20090101

process :: [Int] -> [Int] -> [Int]
process f t = zipWith max (zipWith (+) f (init t) ++ [last t]) (head t : zipWith (+) f (tail t))

main = getContents >>= print . maximum . foldl1 process . map (map read . words) . lines