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
#include <iostream>
constexpr int f( int n, int i )
{
return n<=0 ? 0 : (n + f(n-i, i));
}
static constexpr int MAX = 1000 - 1;
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;
putStr $ show $ sum [x|x<-[1..999], rem x 3 == 0 || rem x 5 == 0]
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
# 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)
@rhysd
rhysd / fizzbuzz.cpp
Created July 3, 2012 07:31
FizzBuzz
#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);
@rhysd
rhysd / gist:3071840
Created July 8, 2012 17:14
yield self から instance_eval に変えると
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
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"
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]
#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;