-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3571c49
commit 9726dca
Showing
8 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
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
14 changes: 14 additions & 0 deletions
14
exercises/practice/armstrong-numbers/.docs/instructions.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Instructions | ||
|
||
An [Armstrong number][armstrong-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. | ||
|
||
[armstrong-number]: https://en.wikipedia.org/wiki/Narcissistic_number |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"authors": [ | ||
"erikschierboom" | ||
], | ||
"files": { | ||
"solution": [ | ||
"src/armstrong-numbers.art" | ||
], | ||
"test": [ | ||
"tests/test-armstrong-numbers.art" | ||
], | ||
"example": [ | ||
".meta/src/example.art" | ||
] | ||
}, | ||
"blurb": "Determine if a number is an Armstrong number.", | ||
"source": "Wikipedia", | ||
"source_url": "https://en.wikipedia.org/wiki/Narcissistic_number" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
armstrong_sum: $ [n][ | ||
digits_: digits n | ||
numDigits_: size digits_ | ||
sum map digits_ => [& ^ numDigits_] | ||
] | ||
|
||
armstrong?: $ [n][n = armstrong_sum n] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# This is an auto-generated file. | ||
# | ||
# Regenerating this file via `configlet sync` will: | ||
# - Recreate every `description` key/value pair | ||
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications | ||
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) | ||
# - Preserve any other key/value pair | ||
# | ||
# As user-added comments (using the # character) will be removed when this file | ||
# is regenerated, comments can be added via a `comment` key. | ||
|
||
[c1ed103c-258d-45b2-be73-d8c6d9580c7b] | ||
description = "Zero is an Armstrong number" | ||
|
||
[579e8f03-9659-4b85-a1a2-d64350f6b17a] | ||
description = "Single-digit numbers are Armstrong numbers" | ||
|
||
[2d6db9dc-5bf8-4976-a90b-b2c2b9feba60] | ||
description = "There are no two-digit Armstrong numbers" | ||
|
||
[509c087f-e327-4113-a7d2-26a4e9d18283] | ||
description = "Three-digit number that is an Armstrong number" | ||
|
||
[7154547d-c2ce-468d-b214-4cb953b870cf] | ||
description = "Three-digit number that is not an Armstrong number" | ||
|
||
[6bac5b7b-42e9-4ecb-a8b0-4832229aa103] | ||
description = "Four-digit number that is an Armstrong number" | ||
|
||
[eed4b331-af80-45b5-a80b-19c9ea444b2e] | ||
description = "Four-digit number that is not an Armstrong number" | ||
|
||
[f971ced7-8d68-4758-aea1-d4194900b864] | ||
description = "Seven-digit number that is an Armstrong number" | ||
|
||
[7ee45d52-5d35-4fbd-b6f1-5c8cd8a67f18] | ||
description = "Seven-digit number that is not an Armstrong number" | ||
|
||
[5ee2fdf8-334e-4a46-bb8d-e5c19c02c148] | ||
description = "Armstrong number containing seven zeroes" | ||
|
||
[12ffbf10-307a-434e-b4ad-c925680e1dd4] | ||
description = "The largest and last Armstrong number" |
3 changes: 3 additions & 0 deletions
3
exercises/practice/armstrong-numbers/src/armstrong-numbers.art
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
armstrong?: function[n][ | ||
panic "Please implement the armstrong? function" | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {unitt}! | ||
|
||
runTests.failFast findTests "tests" |
59 changes: 59 additions & 0 deletions
59
exercises/practice/armstrong-numbers/tests/test-armstrong-numbers.art
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import {unitt}! | ||
import {src/armstrong-numbers}! | ||
|
||
suite "Armstrong Numbers" [ | ||
test "Zero is an Armstrong number" [ | ||
result: armstrong? 0 | ||
assert -> true = result | ||
] | ||
|
||
test.skip "Single digit numbers are Armstrong numbers" [ | ||
result: armstrong? 5 | ||
assert -> true = result | ||
] | ||
|
||
test.skip "There are no 2 digit Armstrong Numbers" [ | ||
result: armstrong? 10 | ||
assert -> false = result | ||
] | ||
|
||
test.skip "Three digit number that is not an Armstrong number" [ | ||
result: armstrong? 100 | ||
assert -> false = result | ||
] | ||
|
||
test.skip "Three digit number that is an Armstrong number" [ | ||
result: armstrong? 153 | ||
assert -> true = result | ||
] | ||
|
||
test.skip "Four digit number that is an Armstrong number" [ | ||
result: armstrong? 9474 | ||
assert -> true = result | ||
] | ||
|
||
test.skip "Four digit number that is not an Armstrong number" [ | ||
result: armstrong? 9475 | ||
assert -> false = result | ||
] | ||
|
||
test.skip "Seven digit number that is not an Armstrong number" [ | ||
result: armstrong? 9926314 | ||
assert -> false = result | ||
] | ||
|
||
test.skip "Seven digit number that is an Armstrong number" [ | ||
result: armstrong? 9926315 | ||
assert -> true = result | ||
] | ||
|
||
test.skip "Armstrong number containing seven zeroes" [ | ||
result: armstrong? 186709961001538790100634132976990 | ||
assert -> true = result | ||
] | ||
|
||
test.skip "The largest and last Armstrong number" [ | ||
result: armstrong? 115132219018763992565095597973971522401 | ||
assert -> true = result | ||
] | ||
] |