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
;;; This was installed by package-install.el. | |
;;; This provides support for the package system and | |
;;; interfacing with ELPA, the package archive. | |
;;; Move this code earlier if you want to reference | |
;;; packages in your .emacs. | |
(when | |
(load | |
(expand-file-name "~/.emacs.d/elpa/package.el")) | |
(package-initialize)) | |
(custom-set-variables |
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
def f(i, a, b) | |
a.to_s.size < 1000 ? f(i + 1, a + b, a) : i | |
end | |
puts f(2, 1, 1) #=> 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
(1...1000).select{|i| i % 3 == 0 || i % 5 == 0}.inject(0, :+) # => 233168 |
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
(2...10**6).select{|i| i == i.to_s.split(//).inject(0){|s, c| s + c.to_i**5}}.inject(0, :+) # => 443839 |
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
dp = [1] + [0] * 200 | |
[1, 2, 5, 10, 20, 50, 100, 200].each do |v| | |
0.upto(200) do |i| | |
dp[i] += dp[i - v] if i - v >= 0 | |
end | |
end | |
puts dp[200] # => 73682 |
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..9).flat_map{|a| ((a + 1)..9).flat_map{|b| (1..9).flat_map{|i| [10 * a + i, 10 * i + a].product([10 * b + i, 10 * i + b]).map{|p, q| Rational(p, q)}.select{|w| w == Rational(a, b)}}}}.inject(:*).denominator |
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
fact = (1..9).each_with_object([1]){|i, a| a << a[-1] * i} | |
puts (3..(6 * fact[9])).select{|n| n.to_s.split(//).map{|s| fact[s.to_i]}.inject(:+) == n}.inject(:+) |
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' | |
puts (1...10**6).count{|n| s = n.to_s; (0...s.length).all?{|i| Prime.prime?((s[i..-1] + s[0...i]).to_i)}} |
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
# -*- coding: utf-8 -*- | |
require 'cgi' | |
require 'open3' | |
require 'benchmark' | |
require 'httpclient' # gem | |
class Validator | |
def accepted?(answer, output) |
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...10**6).select{|i| i.to_s == i.to_s.reverse && i.to_s(2) == i.to_s(2).reverse}.inject(:+) |
OlderNewer