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..501).map{|n|4*(2*n-3)**2+20*(n-1)}.inject{|a,b|a+b}-3 # 669171001 |
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 (2..100).map{|a|(2..100).map{|b|a**b}}.flatten.uniq.size # 9183 |
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..999999).select{|a|a == a.to_s.split(//).map{|a|a.to_i**5}.inject{|a,b|a+b}}.inject{|a,b|a+b}-1 # 443839 |
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,2,5,10,20,50,100,200] | |
| $ans = 0 | |
| def dfs(n) | |
| case n.inject{|a,b|a+b} | |
| when 0..199 | |
| $p.each{|a|dfs(n<<a)} | |
| when 200 | |
| $ans += 1 | |
| p n |
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
| ans = 0 | |
| (0).step(200,100) do |p100| | |
| (0).step(200,50) do |p50| | |
| (0).step(200,20) do |p20| | |
| (0).step(200,10) do |p10| | |
| (0).step(200,5) do |p5| | |
| (0).step(200,2) do |p2| | |
| ans += 1 if p100+p50+p20+p10+p5+p2 <= 200 | |
| 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 (1000..9999).select{|a|(2..Math::sqrt(a)).select{|b|a % b == 0 && "#{a}#{b}#{a/b}".split(//).sort.join == (1..9).to_a.join}.empty?.!}.inject(0, :+) # 45228 |
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
| ans = Rational(1, 1) | |
| (1..9).each do |a| | |
| (1...a).each do |b| | |
| (1..9).each do |c| | |
| d = Rational(b,a) | |
| if Rational(b*10+c, a*10+c) == d || | |
| Rational(b*10+c, a+c*10) == d || | |
| Rational(b+c*10, a*10+c) == d || | |
| Rational(b+c*10, a+c*10) == d | |
| ans *= d |
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' | |
| p Prime.each.lazy.select{|a|a>7&&(1...a.to_s.size).map{|b|[a.to_s[0,b],a.to_s.split(//).reverse.join[0,b].split(//).reverse.join]}.flatten.all?{|b|b.to_i.prime?}}.take(11).inject(:+) | |
| # 748317 (ruby2.0.0dev) | |
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 (3...(1..9).inject(1,:*)*9).select{|a|a==a.to_s.split(//).map{|b|(1..b.to_i).inject(1,:*)}.inject(0,:+)}.inject(0,:+) # 40730 |
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' | |
| p Prime.each(10**6).select{|a|(1..a.to_s.size-1).map{|b|a.to_s.scan(/.{#{b}}|.+\Z/)}.map{|b|b.push(b.shift).join.to_i}.select{|b|b.prime?.!}.empty?}.size # 55 |