This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
constexpr int f( int n, int i ) | |
{ | |
return n<=0 ? 0 : (n + f(n-i, i)); | |
} | |
static constexpr int MAX = 1000 - 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Main{ | |
public static void main(String[] args){ | |
int max = 1000; | |
int total = 0; | |
int i; | |
i = 3; | |
while(i<max){ | |
total += i; | |
i += 3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
putStr $ show $ sum [x|x<-[1..999], rem x 3 == 0 || rem x 5 == 0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mergeSort :: Ord a => [a] -> [a] | |
mergeSort [] = [] | |
mergeSort [x] = [x] | |
mergeSort xs = merge (mergeSort l) (mergeSort r) | |
where | |
s = length xs `div` 2 | |
(l,r) = splitAt s xs | |
merge :: Ord a => [a] -> [a] -> [a] | |
merge [] ys = ys | |
merge xs [] = xs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# path を通す | |
(setq load-path (cons "~/.emacs.d/site-lisp" load-path)) | |
(setq load-path (cons "~/.emacs.d/site-lisp/melpa" load-path)) | |
# パッケージ管理を使うための初期化 | |
(require 'package) | |
; Add package-archives | |
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <array> | |
#include <string> | |
#include <algorithm> | |
#include <numeric> | |
int main() | |
{ | |
std::array<size_t, 100> arr; | |
std::iota(arr.begin(), arr.end(), 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Twitter::configure do |config| | |
config.consumer_key = 'piyo' | |
config.consumer_secret = 'poyo' | |
config.oauth_token = 'foo' | |
config.oauth_token_secret = 'bar' | |
end | |
# と書いていたのが, | |
Twitter::configure do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = 1 | |
b = 'a' | |
case [a,b] | |
when [1,'b'] then "hoge" | |
when [2,'a'] then "huga" | |
when [1,'a'] then "poyo" | |
else "puyo" end | |
#=> "poyo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isPalindromeNum :: Int -> Bool | |
isPalindromeNum n = s == reverse s | |
where s = show n | |
main = putStrLn . show . maximum $ [x*y| x<-[100..999],y<-[x..999], isPalindromeNum $ x*y] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
bool is_palindrome(int const i) | |
{ | |
auto s = std::to_string(i); | |
for(auto f=s.begin(), l=s.end()-1; f<=l; ++f, --l){ | |
if(*f!=*l) return false; | |
} | |
return true; |