Last active
August 15, 2018 17:30
-
-
Save havenwood/b6d55b412fbf583758c91b8ee339a822 to your computer and use it in GitHub Desktop.
A "fun" solution to this_dude's problem in the #ruby irc channel: http://www.codewars.com/kata/sum-of-digits-slash-digital-root/train/ruby
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
class Proc | |
def >> other | |
-> arg { other.to_proc.call call arg } | |
end | |
end | |
class Symbol | |
def >> other | |
to_proc >> other.to_proc | |
end | |
end | |
class Enumerator | |
class << self | |
def generate value | |
raise ArgumentError, 'No block given' unless block_given? | |
Enumerator.new Float::INFINITY do |yielder| | |
loop do | |
yielder << value | |
value = yield value | |
end | |
end | |
end | |
end | |
end | |
Enumerator.generate(942, &:digits >> :sum).find(&:digits >> :one?) | |
#=> 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment