Skip to content

Commit abf3d49

Browse files
authored
Sync armstrong-numbers (#831)
[no important files changed]
1 parent 23f2cd7 commit abf3d49

File tree

5 files changed

+70
-59
lines changed

5 files changed

+70
-59
lines changed
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# Instructions
22

3-
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.
3+
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.
44

55
For example:
66

77
- 9 is an Armstrong number, because `9 = 9^1 = 9`
8-
- 10 is *not* an Armstrong number, because `10 != 1^2 + 0^2 = 1`
8+
- 10 is _not_ an Armstrong number, because `10 != 1^2 + 0^2 = 1`
99
- 153 is an Armstrong number, because: `153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153`
10-
- 154 is *not* an Armstrong number, because: `154 != 1^3 + 5^3 + 4^3 = 1 + 125 + 64 = 190`
10+
- 154 is _not_ an Armstrong number, because: `154 != 1^3 + 5^3 + 4^3 = 1 + 125 + 64 = 190`
1111

1212
Write some code to determine whether a number is an Armstrong number.
13+
14+
[armstrong-number]: https://en.wikipedia.org/wiki/Narcissistic_number

exercises/practice/armstrong-numbers/.meta/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
".meta/example.php"
1818
]
1919
},
20-
"blurb": "Determine if a number is an Armstrong number",
20+
"blurb": "Determine if a number is an Armstrong number.",
2121
"source": "Wikipedia",
2222
"source_url": "https://en.wikipedia.org/wiki/Narcissistic_number"
2323
}

exercises/practice/armstrong-numbers/.meta/example.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,5 @@
11
<?php
22

3-
/*
4-
* By adding type hints and enabling strict type checking, code can become
5-
* easier to read, self-documenting and reduce the number of potential bugs.
6-
* By default, type declarations are non-strict, which means they will attempt
7-
* to change the original type to match the type specified by the
8-
* type-declaration.
9-
*
10-
* In other words, if you pass a string to a function requiring a float,
11-
* it will attempt to convert the string value to a float.
12-
*
13-
* To enable strict mode, a single declare directive must be placed at the top
14-
* of the file.
15-
* This means that the strictness of typing is configured on a per-file basis.
16-
* This directive not only affects the type declarations of parameters, but also
17-
* a function's return type.
18-
*
19-
* For more info review the Concept on strict type checking in the PHP track
20-
* <link>.
21-
*
22-
* To disable strict typing, comment out the directive below.
23-
*/
24-
253
declare(strict_types=1);
264

275
function isArmstrongNumber(int $number): bool
Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,47 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
411

512
[c1ed103c-258d-45b2-be73-d8c6d9580c7b]
613
description = "Zero is an Armstrong number"
714

815
[579e8f03-9659-4b85-a1a2-d64350f6b17a]
9-
description = "Single digit numbers are Armstrong numbers"
16+
description = "Single-digit numbers are Armstrong numbers"
1017

1118
[2d6db9dc-5bf8-4976-a90b-b2c2b9feba60]
12-
description = "There are no 2 digit Armstrong numbers"
19+
description = "There are no two-digit Armstrong numbers"
1320

1421
[509c087f-e327-4113-a7d2-26a4e9d18283]
15-
description = "Three digit number that is an Armstrong number"
22+
description = "Three-digit number that is an Armstrong number"
1623

1724
[7154547d-c2ce-468d-b214-4cb953b870cf]
18-
description = "Three digit number that is not an Armstrong number"
25+
description = "Three-digit number that is not an Armstrong number"
1926

2027
[6bac5b7b-42e9-4ecb-a8b0-4832229aa103]
21-
description = "Four digit number that is an Armstrong number"
28+
description = "Four-digit number that is an Armstrong number"
2229

2330
[eed4b331-af80-45b5-a80b-19c9ea444b2e]
24-
description = "Four digit number that is not an Armstrong number"
31+
description = "Four-digit number that is not an Armstrong number"
2532

2633
[f971ced7-8d68-4758-aea1-d4194900b864]
27-
description = "Seven digit number that is an Armstrong number"
34+
description = "Seven-digit number that is an Armstrong number"
2835

2936
[7ee45d52-5d35-4fbd-b6f1-5c8cd8a67f18]
30-
description = "Seven digit number that is not an Armstrong number"
37+
description = "Seven-digit number that is not an Armstrong number"
38+
39+
[5ee2fdf8-334e-4a46-bb8d-e5c19c02c148]
40+
description = "Armstrong number containing seven zeroes"
41+
include = false
42+
comment = "PHP does not support integers > 64bit in its standard library"
43+
44+
[12ffbf10-307a-434e-b4ad-c925680e1dd4]
45+
description = "The largest and last Armstrong number"
46+
include = false
47+
comment = "PHP does not support integers > 64bit in its standard library"

exercises/practice/armstrong-numbers/ArmstrongNumbersTest.php

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,5 @@
11
<?php
22

3-
/*
4-
* By adding type hints and enabling strict type checking, code can become
5-
* easier to read, self-documenting and reduce the number of potential bugs.
6-
* By default, type declarations are non-strict, which means they will attempt
7-
* to change the original type to match the type specified by the
8-
* type-declaration.
9-
*
10-
* In other words, if you pass a string to a function requiring a float,
11-
* it will attempt to convert the string value to a float.
12-
*
13-
* To enable strict mode, a single declare directive must be placed at the top
14-
* of the file.
15-
* This means that the strictness of typing is configured on a per-file basis.
16-
* This directive not only affects the type declarations of parameters, but also
17-
* a function's return type.
18-
*
19-
* For more info review the Concept on strict type checking in the PHP track
20-
* <link>.
21-
*
22-
* To disable strict typing, comment out the directive below.
23-
*/
24-
253
declare(strict_types=1);
264

275
class ArmstrongNumbersTest extends PHPUnit\Framework\TestCase
@@ -31,46 +9,82 @@ public static function setUpBeforeClass(): void
319
require_once 'ArmstrongNumbers.php';
3210
}
3311

12+
/**
13+
* uuid: c1ed103c-258d-45b2-be73-d8c6d9580c7b
14+
* @testdox Zero is an Armstrong number
15+
*/
3416
public function testZero(): void
3517
{
3618
$this->assertTrue(isArmstrongNumber(0));
3719
}
3820

21+
/**
22+
* uuid: 579e8f03-9659-4b85-a1a2-d64350f6b17a
23+
* @testdox Single-digit numbers are Armstrong numbers
24+
*/
3925
public function testSingleDigit(): void
4026
{
4127
$this->assertTrue(isArmstrongNumber(5));
4228
}
4329

30+
/**
31+
* uuid: 2d6db9dc-5bf8-4976-a90b-b2c2b9feba60
32+
* @testdox There are no two-digit Armstrong numbers
33+
*/
4434
public function testDoubleDigit(): void
4535
{
4636
$this->assertFalse(isArmstrongNumber(10));
4737
}
4838

39+
/**
40+
* uuid: 509c087f-e327-4113-a7d2-26a4e9d18283
41+
* @testdox Three-digit number that is an Armstrong number
42+
*/
4943
public function testThreeDigitIsArmstrongNumber(): void
5044
{
5145
$this->assertTrue(isArmstrongNumber(153));
5246
}
5347

48+
/**
49+
* uuid: 7154547d-c2ce-468d-b214-4cb953b870cf
50+
* @testdox Three-digit number that is not an Armstrong number
51+
*/
5452
public function testThreeDigitIsNotArmstrongNumber(): void
5553
{
5654
$this->assertFalse(isArmstrongNumber(100));
5755
}
5856

57+
/**
58+
* uuid: 6bac5b7b-42e9-4ecb-a8b0-4832229aa103
59+
* @testdox Four-digit number that is an Armstrong number
60+
*/
5961
public function testFourDigitIsArmstrongNumber(): void
6062
{
6163
$this->assertTrue(isArmstrongNumber(9474));
6264
}
6365

66+
/**
67+
* uuid: eed4b331-af80-45b5-a80b-19c9ea444b2e
68+
* @testdox Four-digit number that is not an Armstrong number
69+
*/
6470
public function testFourDigitIsNotArmstrongNumber(): void
6571
{
6672
$this->assertFalse(isArmstrongNumber(9475));
6773
}
6874

75+
/**
76+
* uuid: f971ced7-8d68-4758-aea1-d4194900b864
77+
* @testdox Seven-digit number that is an Armstrong number
78+
*/
6979
public function testSevenDigitIsArmstrongNumber(): void
7080
{
7181
$this->assertTrue(isArmstrongNumber(9926315));
7282
}
7383

84+
/**
85+
* uuid: 7ee45d52-5d35-4fbd-b6f1-5c8cd8a67f18
86+
* @testdox Seven-digit number that is not an Armstrong number
87+
*/
7488
public function testSevenDigitIsNotArmstrongNumber(): void
7589
{
7690
$this->assertFalse(isArmstrongNumber(9926314));

0 commit comments

Comments
 (0)