-
-
Notifications
You must be signed in to change notification settings - Fork 525
armstrong-numbers: port #988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'generator/exercise_case' | ||
|
||
class ArmstrongNumbersCase < Generator::ExerciseCase | ||
|
||
def workload | ||
assert_or_refute(expected, call_armstrong) | ||
end | ||
|
||
def call_armstrong | ||
"ArmstrongNumbers.include?(#{underscore(input['number'])})" | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class ArmstrongNumbers | ||
def self.include?(number) | ||
exponent = number.digits.size | ||
|
||
number.digits.sum { |digit| digit**exponent } == number | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :-) And I'm slightly confused too. ;-) Does this mean that you think the original solution is not good enough? Or? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I just really wanted to use stabby lambda for the hell of it, and the guide for porting exercises on this track says the solution doesn't need to be ideal (although I think this one is fun 😃) I have no problem reverting it. That is a simple fix 😃 (I think that porting guide was written before the profound track anatomy project happened, so wanting example solutions that fit the level of the exercise is a reasonable desire given all that you all have done to polish this track 😃) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The example solution is a proof of concept, and if it is not "normal" this means that we will likely spot it quickly, if for some reason it comes to be a solution submitted by a student. So there are some advantages to having a non ideal solution, as long as it "proves the concept". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the other hand, since this isn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, you mentioned the lambda fun somewhere else, so that's what I thought it was 🤓 . FYI: Thanks for reverting :-) |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Armstrong Numbers | ||
|
||
An [Armstrong number](https://en.wikipedia.org/wiki/Narcissistic_number) is a number that is the sum of its own digits each raised to the power of the number of digits. | ||
|
||
For example: | ||
|
||
- 9 is an Armstrong number, because `9 = 9^1 = 9` | ||
- 10 is *not* an Armstrong number, because `10 != 1^2 + 0^2 = 1` | ||
- 153 is an Armstrong number, because: `153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153` | ||
- 154 is *not* an Armstrong number, because: `154 != 1^3 + 5^3 + 4^3 = 1 + 125 + 64 = 190` | ||
|
||
Write some code to determine whether a number is an Armstrong number. | ||
|
||
* * * * | ||
|
||
For installation and learning resources, refer to the | ||
[Ruby resources page](http://exercism.io/languages/ruby/resources). | ||
|
||
For running the tests provided, you will need the Minitest gem. Open a | ||
terminal window and run the following command to install minitest: | ||
|
||
gem install minitest | ||
|
||
If you would like color output, you can `require 'minitest/pride'` in | ||
the test file, or note the alternative instruction, below, for running | ||
the test file. | ||
|
||
Run the tests from the exercise directory using the following command: | ||
|
||
ruby armstrong_numbers_test.rb | ||
|
||
To include color from the command line: | ||
|
||
ruby -r minitest/pride armstrong_numbers_test.rb | ||
|
||
|
||
## Source | ||
|
||
Wikipedia [https://en.wikipedia.org/wiki/Narcissistic_number](https://en.wikipedia.org/wiki/Narcissistic_number) | ||
|
||
## Submitting Incomplete Solutions | ||
It's possible to submit an incomplete solution so you can see how others have completed the exercise. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require 'minitest/autorun' | ||
require_relative 'armstrong_numbers' | ||
|
||
# Common test data version: 1.1.0 b3c2522 | ||
class ArmstrongNumbersTest < Minitest::Test | ||
def test_zero_is_an_armstrong_number | ||
# skip | ||
assert ArmstrongNumbers.include?(0) | ||
end | ||
|
||
def test_single_digit_numbers_are_armstrong_numbers | ||
skip | ||
assert ArmstrongNumbers.include?(5) | ||
end | ||
|
||
def test_there_are_no_2_digit_armstrong_numbers | ||
skip | ||
refute ArmstrongNumbers.include?(10) | ||
end | ||
|
||
def test_three_digit_number_that_is_an_armstrong_number | ||
skip | ||
assert ArmstrongNumbers.include?(153) | ||
end | ||
|
||
def test_three_digit_number_that_is_not_an_armstrong_number | ||
skip | ||
refute ArmstrongNumbers.include?(100) | ||
end | ||
|
||
def test_four_digit_number_that_is_an_armstrong_number | ||
skip | ||
assert ArmstrongNumbers.include?(9_474) | ||
end | ||
|
||
def test_four_digit_number_that_is_not_an_armstrong_number | ||
skip | ||
refute ArmstrongNumbers.include?(9_475) | ||
end | ||
|
||
def test_seven_digit_number_that_is_an_armstrong_number | ||
skip | ||
assert ArmstrongNumbers.include?(9_926_315) | ||
end | ||
|
||
def test_seven_digit_number_that_is_not_an_armstrong_number | ||
skip | ||
refute ArmstrongNumbers.include?(9_926_314) | ||
end | ||
end |
Uh oh!
There was an error while loading. Please reload this page.