This file contains hidden or 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
p (0..9).to_a.permutation(10).select {|a| | |
a[1..3].join.to_i % 2 == 0 and | |
a[2..4].join.to_i % 3 == 0 and | |
a[3..5].join.to_i % 5 == 0 and | |
a[4..6].join.to_i % 7 == 0 and | |
a[5..7].join.to_i % 11 == 0 and | |
a[6..8].join.to_i % 13 == 0 and | |
a[7..9].join.to_i % 17 == 0 | |
}.inject(0) {|v, i| v + i.join.to_i } |
This file contains hidden or 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 Integer | |
def pentagonal? | |
((Math.sqrt(24 * self + 1) + 1) / 6) % 1 == 0 | |
end | |
end | |
def pentagonal_number(n) | |
n * (3 * n - 1) / 2 | |
end |
This file contains hidden or 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 Integer | |
def triangle? | |
((Math.sqrt(8 * self + 1) - 1) / 2) % 1 == 0 | |
end | |
def pentagonal? | |
((Math.sqrt(24 * self + 1) + 1) / 6) % 1 == 0 | |
end | |
end |
This file contains hidden or 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
#! ruby | |
require 'prime' | |
max = 100000 | |
nums = 3.step(max, 2).reject {|v| Prime.prime?(v) } | |
nums.each do |n| | |
flag = false | |
Prime.each(n) do |p| |
This file contains hidden or 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
require 'prime' | |
1.upto(1000000).each_cons(4) do |a| | |
if a.all? {|v| Prime.prime_division(v).size == 4 } | |
p a | |
exit | |
end | |
end |
This file contains hidden or 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
p 1.upto(1000).inject(0) {|v, i| v + i ** i }.to_s[-10..-1] |
This file contains hidden or 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
#! ruby | |
require 'prime' | |
ans = [] | |
Prime.each(9999).select {|v| v >= 1000 }.each do |n| | |
a = n.to_s.split(//).permutation.map {|v| v.join.to_i }.select {|v| Prime.prime?(v) && v.to_s.size == 4 }.combination(3).select {|v| | |
v.sort | |
v[0] != v[1] && v[2] - v[1] == v[1] - v[0] | |
}.sort.uniq |
This file contains hidden or 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
#! ruby | |
require 'prime' | |
def p050(max) | |
ary = Prime.each(max).to_a | |
size = ary.size | |
limit = (size < 10000) ? size : 10000 | |
limit.downto(0) do |i| | |
p i if i % 100 == 0 |
This file contains hidden or 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
require 'tempfile' | |
# 一時ファイル作成 | |
temp_file_obj = Tempfile.open("stdouttest") | |
# 標準出力を一時ファイルに切り替え | |
$stdout = File.open(temp_file_obj, "w") | |
# 標準出力へ出力 | |
puts "You did it!" |
This file contains hidden or 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
# LANG | |
export LANG=ja_JP.UTF-8 | |
# KEYBIND | |
bindkey -v | |
bindkey "" history-incremental-search-backward | |
# PROMPT | |
PROMPT='%{%(?..$fg[red])%}%%%{$reset_color%} ' | |
PROMPT2="> " |