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
// {{{ Boilerplate Code <-------------------------------------------------- | |
// | |
// vim:filetype=cpp foldmethod=marker foldmarker={{{,}}} | |
#include <algorithm> | |
#include <bitset> | |
#include <cmath> | |
#include <cstdio> | |
#include <cstdlib> |
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
// {{{ Boilerplate Code <-------------------------------------------------- | |
// | |
// vim:filetype=cpp foldmethod=marker foldmarker={{{,}}} | |
#include <algorithm> | |
#include <bitset> | |
#include <cmath> | |
#include <cstdio> | |
#include <cstdlib> |
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 <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') { |
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
#!/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] |
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
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
puts (1...1000).inject {|sum, n| ((n % 3 == 0) or (n % 5 == 0)) ? sum + n : sum } |
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
#!/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 |
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
#!/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 |
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
#!/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 |
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
#!/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 |
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
#!/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 |