Skip to content

Instantly share code, notes, and snippets.

View rhysd's full-sized avatar
🐕
Fixing an off-by-wan error

Linda_pp rhysd

🐕
Fixing an off-by-wan error
View GitHub Profile
import Data.List (maximumBy)
import Data.Function (on)
collatzLength :: Int -> Int -> Int
collatzLength acc 1 = acc
collatzLength acc n
| even n = collatzLength (acc+1) (n `div` 2)
| odd n = collatzLength (acc+1) (3*n + 1)
-- 末尾再帰にしたら少し早くなった
import Data.Char(digitToInt)
main = print $ sum $ map digitToInt $ show $ 2^1000
-- 1366
-- 多倍長整数チート感ある…
puts (2**1000).to_s.chars.map{|c|c.to_i}.inject :+
@rhysd
rhysd / euler19.vim
Created August 10, 2012 02:33
これぐらいの問題なら Vim script で解くか〜
function! s:is_leap_year(year)
return a:year % 4 == 0 && !(a:year % 100 == 0 && a:year % 400) ? 1 : 0
endfunction
function! s:count_20th_century_mondays()
let l:day_count = 366 " 1900年の365日分 + 1
let l:monday = 0
" 1 2 3 4 5 6 7 8 9 10 11 12
let month = [31,28,31,30,31,30,31,31,30,31,30,31]
for y in range(1901,2000)
import Data.Char (digitToInt)
main :: IO ()
main = print $ sum $ map digitToInt $ show $ product [1..100]
-- 648
@rhysd
rhysd / cpp.snip
Created August 11, 2012 16:49
constexpr_func snippet
snippet constexpr_func
abbr constexpr auto func() -> decltype
prev_word '^'
constexpr auto ${1:name}( ${2:args} ) -> decltype($1)
{
return ${1:body};
}
#include <iostream>
#include <vector>
// range-based アルゴリズム使いたかった
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/range/numeric.hpp>
inline int sum_of_divisors(int const n)
{
main :: IO ()
main = print $ sum $ scanl1 (+) $ 1:(concat $ map (replicate 4) [2,4..1000])
-- 669171001
" フレームにアイコンを表示
let g:tweetvim_display_icon = 1
" 1ページのツイート数
let g:tweetvim_tweet_per_page = 60
nnoremap <silent><Leader>tw :<C-u>tabnew <Bar> TweetVimHomeTimeline<CR>
nnoremap <silent><Leader>tl :<C-u>TweetVimHomeTimeline<CR>
nnoremap <silent><Leader>tm :<C-u>TweetVimMentions<CR>
nnoremap <Leader>ts :<C-u>TweetVimSay<CR>
@rhysd
rhysd / inuu.vim
Created September 10, 2012 06:37
イヌゥ… ステータスライン
" This is イヌゥ… script for vim's status line.
" The original script is here.
" https://github.com/koron/homoo-vim
" All you have to do is to execute the below command.
" :source path/to/inuu.vim
scriptencoding utf-8