Skip to content

Instantly share code, notes, and snippets.

@2GMon
2GMon / get.rb
Created December 15, 2011 13:38
# instapaper経由でwebのtextのみを取得
# ログインしてないとダメ?(未確認)
require 'net/http'
require 'uri'
require 'cgi'
uri = URI("http://www.instapaper.com/text?u=#{CGI.escape(ARGV[0])}")
http = Net::HTTP.new(uri.host, uri.port)
res = http.get(uri.request_uri)
@2GMon
2GMon / add_to_instapaper.rb
Created December 16, 2011 07:21
instapaperにURLを登録する
# instapaperにURLを登録する
require 'net/http'
require 'cgi'
url = CGI.escape(ARGV[0])
username = CGI.escape(ARGV[1])
password = CGI.escape(ARGV[2])
post = ""
if password == nil
abc = [[a, b, c] | c <- [1..], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2, a + b + c == 1000]
main = putStrLn (show (product (head abc)))
triangularNumbers :: [Int]
triangularNumbers = [sum [1..x] | x <- [1..]]
divisors :: Int -> [Int]
divisors x = filter (\n -> x `mod` n == 0) [1..x]
main = print $ head [triNum | triNum <- triangularNumbers, length (divisors triNum) >= 501]
numbers :: [Integer]
numbers = [
37107287533902102798797998220837590246510135740250,
46376937677490009712648124896970078050417018260538,
74324986199524741059474233309513058123726617309629,
91942213363574161572522430563301811072406154908250,
23067588207539346171171980310421047513778063246676,
89261670696623633820136378418383684178734361726757,
28112879812849979408065481931592621691275889832738,
44274228917432520321923589422876796487670272189318,
import Data.List
collatz :: Int -> [Int]
collatz 1 = [1]
collatz x
| even x = x : collatz (x `div` 2)
| odd x = x : collatz (3 * x + 1)
collatzLength :: Int -> (Int, Int)
collatzLength x = (x, length (collatz x))
-- Project Euler : Problem 15
combination :: Integer -> Integer -> Integer
combination n m = product [n,n-1..(n - m + 1)] `div` product [1..m]
numRoutes :: Integer -> Integer -> Integer
numRoutes x y = combination (x + y) $ min x y
main = print $ numRoutes 20 20
-- Project Euler : Problem 16
import Data.Char
power :: Integer
power = 2 ^ 1000
digitList :: Integer -> [Int]
digitList x = map digitToInt $ show x
-- Project Euler : Problem 17
-- 1000の時にスペースを入れてしまっていたのを修正
numToStr :: Int -> String
numToStr 1 = "one"
numToStr 2 = "two"
numToStr 3 = "three"
numToStr 4 = "four"
numToStr 5 = "five"
numToStr 6 = "six"
@2GMon
2GMon / dailycoding18.hs
Created August 9, 2012 04:18
Project Euler : Problem 18
-- Project Euler : Problem 18
triangle :: [[Int]]
triangle = [
[75],
[95, 64],
[17, 47, 82],
[18, 35, 87, 10],
[20, 04, 82, 47, 65],
[19, 01, 23, 75, 03, 34],