Paul Fioravanti
September 10, 2019
110

# Exercism: Armstrong Numbers (Ruby)

A presentation outlining my solution to the Exercism Armstrong Numbers problem in Ruby (https://exercism.io/tracks/ruby/exercises/armstrong-numbers).

Presented at the Sydney Ruby on Rails meetup on 10 September 2019.

Presentation slide deck markdown and speaker notes (useable in Deckset 2):
https://github.com/paulfioravanti/presentations/tree/master/exercism_ruby_armstrong_numbers

## Paul Fioravanti

September 10, 2019

## Transcript

2. None
3. None

12. ### Armstrong Numbers ✅ 9 = 9^1 = 9 ❌ 10

!= 1^2 + 0^2 = 1

= 153
14. ### Armstrong Numbers ✅ 153 = 1^3 + 5^3 + 3^3

= 153 ❌ 154 != 1^3 + 5^3 + 4^3 = 190

17. ### Armstrong Numbers ! Get the number of digits ! Calculate

the power of each digit
18. ### Armstrong Numbers ! Get the number of digits ! Calculate

the power of each digit ! Sum all the powers

end

end

end end
25. ### Get number of digits module ArmstrongNumbers module_function def include?(number) number

.digits end end

end end
27. ### Sum Powers module ArmstrongNumbers module_function def include?(number) sum = number

.digits .then(&method(:sum_powers)) end end
28. ### Sum Powers module ArmstrongNumbers module_function def include?(number) sum = number

.digits .then(&method(:sum_powers)) sum == number end end
29. ### Sum Powers module ArmstrongNumbers module_function # ... def sum_powers(digits) end

private_class_method :sum_powers end
30. ### Sum Powers module ArmstrongNumbers module_function # ... def sum_powers(digits) digits

end private_class_method :sum_powers end
31. ### Sum Powers module ArmstrongNumbers module_function # ... def sum_powers(digits) digits

.each end private_class_method :sum_powers end
32. ### Sum Powers module ArmstrongNumbers module_function # ... def sum_powers(digits) digits

.each .with_object(digits.length) end private_class_method :sum_powers end
33. ### Sum Powers module ArmstrongNumbers module_function # ... def sum_powers(digits) digits

.each .with_object(digits.length) .sum(&method(:power)) end private_class_method :sum_powers end
34. ### Calculate Power of Each Digit module ArmstrongNumbers module_function # ...

def power((digit, length)) digit**length end private_class_method :power end
35. ### module ArmstrongNumbers module_function def include?(number) sum = number .digits .then(&method(:sum_powers))

sum == number end def sum_powers(digits) digits .each .with_object(digits.length) .sum(&method(:power)) end private_class_method :sum_powers def power((digit, length)) digit**length end private_class_method :power end
36. None
37. None

45. ### module ArmstrongNumbers module_function def include?(number) digits = number.digits length =

digits.length end end
46. ### module ArmstrongNumbers module_function def include?(number) digits = number.digits length =

digits.length number == digits.sum { |digit| digit**length } end end
47. None

56. ### BONUS FACTOIDS! ! Number of Armstrong numbers is ﬁnite !

Only 88 Armstrong numbers in Base 10

58. None