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
y = 1901 | |
m = 1 | |
d = 1 | |
w = 1 # 0..6 -> Sun..Sat | |
count = 0 | |
def m31? (m) | |
[1,3,5,7,8,10,12].each do |i| | |
if m == i | |
return true |
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
require 'date' | |
st = Date::new(1901, 1, 1) | |
en = Date::new(2000, 12, 31) | |
count = 0 | |
while st != en | |
count += 1 if st.day == 1 && st.wday == 0 | |
st += 1 | |
end | |
p count # 171 |
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
puts (1..100).inject(1){|a, b| a * b}.to_s.split(//).map(&:to_i).inject(0){|a, b| a + b} # 648 |
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
require 'prime' | |
arr = Array.new(10001){1} | |
sum = 0 | |
2.upto(10000) do |i| | |
i.prime_division.each do |j| | |
a = 0 | |
(j[1]+1).times do |k| | |
a += j[0]**k | |
end | |
arr[i] *= 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
c, score = 0, 0 | |
open("names.txt").gets.split(/,/).map{|a| a.delete("\"")}.sort.each do |i| | |
c += 1 | |
i.size.times do |j| | |
score += (i[j].bytes.to_a[0].to_i - "A".bytes.to_a[0].to_i + 1) * c | |
end | |
end | |
puts score # 871198282 |
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
require 'prime' | |
m = 28123 | |
sum = 0 | |
adn = Array.new() | |
flag = Array.new(m+1){false} | |
2.upto(m) do |i| | |
a = 1 | |
i.prime_division.each do |j| | |
b = 0 | |
(j[1]+1).times do |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
puts (0..9).to_a.permutation(10).to_a[1000000-1].join | |
# 2783915460 |
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
f = [1,1] | |
f.push(f[-1] + f[-2]) while f[-1].to_s.size < 1000 | |
p f.size # 4782 |
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
require 'Prime' | |
max, answer = 0, 0 | |
Prime.each(1000).to_a.reject{|p| p == 2 || p == 5}.each do |p| | |
a, c = 10, 1 | |
while a % p != 1 do | |
c += 1 | |
a *= 10 | |
end | |
max, answer = c, p if max < c | |
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
require 'Prime' | |
max, answer = 0, 0 | |
(-999..999).each do |a| | |
Prime.each(999).to_a.each do |b| | |
n = 0 | |
n += 1 while Prime.prime?(n ** 2 + a * n + b) | |
max, answer = n, a * b if max < n | |
end | |
end | |
puts answer # -59231 |
OlderNewer