Skip to content

Instantly share code, notes, and snippets.

View yuuki's full-sized avatar

Yuuki TSUBOUCHI yuuki

View GitHub Profile
@yuuki
yuuki / div2-145-200.cpp
Created May 24, 2012 21:29
SRM Div2-145 200score
// {{{ Boilerplate Code <--------------------------------------------------
//
// vim:filetype=cpp foldmethod=marker foldmarker={{{,}}}
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
@yuuki
yuuki / YahtzeeScore.cpp
Created May 24, 2012 23:52
SRM Div2-146 250score
// {{{ Boilerplate Code <--------------------------------------------------
//
// vim:filetype=cpp foldmethod=marker foldmarker={{{,}}}
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
@yuuki
yuuki / CCipher.cpp
Created May 25, 2012 00:15
SRM Div2-147 250score
#include <string>
using namespace std;
class CCipher
{
public:
string decode(string cipherText, int shift)
{
for (int i = 0; i < cipherText.size(); ++i) {
if (cipherText[i] - shift < 'A') {
@yuuki
yuuki / S3parser.py
Created June 26, 2012 01:32
S3 Data file parser
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
if __name__ == '__main__':
with file(sys.argv[1], 'r') as f:
sum = [0, 0, 0]
num = [0, 0, 0]
@yuuki
yuuki / euler1.rb
Created July 23, 2012 11:21
euler1
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
puts (1...1000).inject {|sum, n| ((n % 3 == 0) or (n % 5 == 0)) ? sum + n : sum }
@yuuki
yuuki / euler2.rb
Created July 24, 2012 11:23
euler2
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
fib = Enumerator.new do |y|
a, b = 0, 1
while b < 4000000 do
y << b if b % 2 == 0
a, b = b, a + b
end
end
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'prime' # 反則
NUMBER = 600851475143
prime_factor = []
Prime.each(NUMBER) do |p| # おそい
prime_factor.push p if NUMBER % p == 0
break if NUMBER < 2 * p
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
r = (100 .. 999).to_a.map do |i|
(i .. 999).to_a.map do |j|
s = i * j
s.to_s == s.to_s.reverse ? s : nil
end.compact!.max
end.compact!.max
puts r
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'prime'
factories_count = {}
Prime.each(20) {|i| factories_count[i] = 0}
(2..20).each do |n|
factories_count.each_key do |k| # 素因数分解
break if n < k
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
n = (1..100).each.inject {|sum, i| sum + i }
r = (1..100).each.inject {|sum, i| sum + i**2 }
puts n**2 - r