-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
12 changed files
with
23,733 additions
and
22,373 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
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 |
---|---|---|
|
@@ -2,5 +2,3 @@ | |
edition = "2021" | ||
name = "perfect_numbers" | ||
version = "1.1.0" | ||
|
||
[dependencies] |
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
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,128 @@ | ||
1| 33|#[derive(Debug, PartialEq, Eq)] | ||
^0 ^0 | ||
------------------ | ||
| Unexecuted instantiation: <perfect_numbers::Classification as core::fmt::Debug>::fmt | ||
------------------ | ||
| Unexecuted instantiation: <perfect_numbers::Classification as core::fmt::Debug>::fmt | ||
------------------ | ||
| Unexecuted instantiation: <perfect_numbers::Classification as core::cmp::PartialEq>::eq | ||
------------------ | ||
| <perfect_numbers::Classification as core::cmp::PartialEq>::eq: | ||
| 1| 33|#[derive(Debug, PartialEq, Eq)] | ||
------------------ | ||
| Unexecuted instantiation: <perfect_numbers::Classification as core::cmp::PartialEq>::eq | ||
------------------ | ||
2| |pub enum Classification { | ||
3| | Abundant, | ||
4| | Perfect, | ||
5| | Deficient, | ||
6| |} | ||
7| | | ||
8| |/// Determine if a number is perfect, abundant or deficient based on Nicomachus' (60 - 120 CE) classification scheme for positive integers. | ||
9| |/// | ||
10| |/// Example - Invalid Input | ||
11| |/// ```rust | ||
12| |/// use perfect_numbers::*; | ||
13| |/// | ||
14| |/// let want: Option<Classification> = None; | ||
15| |/// | ||
16| |/// match classify(0) { | ||
17| |/// Some(got) => { assert!(false); } | ||
18| |/// None => { assert!(true) }, | ||
19| |/// }; | ||
20| |/// ``` | ||
21| |/// | ||
22| |/// Example - Perfect | ||
23| |/// ```rust | ||
24| |/// use perfect_numbers::*; | ||
25| |/// | ||
26| |/// let want: Classification = Classification::Perfect; | ||
27| |/// | ||
28| |/// match classify(6) { | ||
29| |/// Some(got) => { assert_eq!(got, want); } | ||
30| |/// None => {}, | ||
31| |/// }; | ||
32| |/// ``` | ||
33| |/// | ||
34| |/// Example - Abundant | ||
35| |/// ```rust | ||
36| |/// use perfect_numbers::*; | ||
37| |/// | ||
38| |/// let want: Classification = Classification::Abundant; | ||
39| |/// | ||
40| |/// match classify(12) { | ||
41| |/// Some(got) => { assert_eq!(got, want); } | ||
42| |/// None => {}, | ||
43| |/// }; | ||
44| |/// ``` | ||
45| |/// | ||
46| |/// Example - Deficient | ||
47| |/// ```rust | ||
48| |/// use perfect_numbers::*; | ||
49| |/// | ||
50| |/// let want: Classification = Classification::Deficient; | ||
51| |/// | ||
52| |/// match classify(8) { | ||
53| |/// Some(got) => { assert_eq!(got, want); } | ||
54| |/// None => {}, | ||
55| |/// }; | ||
56| |/// ``` | ||
57| 36|pub fn classify(number: u64) -> Option<Classification> { | ||
58| 36| if number == 0 { | ||
59| 3| return None; | ||
60| 33| } | ||
61| 33| | ||
62| 33| let mut factors: Vec<u64> = Vec::new(); | ||
63| 33| | ||
64| 33| let mut factor: u64 = 1; | ||
65| | | ||
66| 301M| while factor < number { | ||
67| 301M| if number % factor == 0 { | ||
68| 351| factors.push(factor); | ||
69| 301M| } | ||
70| | | ||
71| 301M| factor += 1; | ||
72| | } | ||
73| | | ||
74| 33| let aliquot_sum: u64 = factors.iter().sum(); | ||
75| 33| | ||
76| 33| Some(match aliquot_sum { | ||
77| 33| sum if sum > number => Classification::Abundant, | ||
^9 ^9 | ||
78| 24| sum if sum < number => Classification::Deficient, | ||
^15 ^15 | ||
79| 9| _ => Classification::Perfect, | ||
80| | }) | ||
81| 36|} | ||
------------------ | ||
| Unexecuted instantiation: perfect_numbers::classify | ||
------------------ | ||
| perfect_numbers::classify: | ||
| 57| 36|pub fn classify(number: u64) -> Option<Classification> { | ||
| 58| 36| if number == 0 { | ||
| 59| 3| return None; | ||
| 60| 33| } | ||
| 61| 33| | ||
| 62| 33| let mut factors: Vec<u64> = Vec::new(); | ||
| 63| 33| | ||
| 64| 33| let mut factor: u64 = 1; | ||
| 65| | | ||
| 66| 301M| while factor < number { | ||
| 67| 301M| if number % factor == 0 { | ||
| 68| 351| factors.push(factor); | ||
| 69| 301M| } | ||
| 70| | | ||
| 71| 301M| factor += 1; | ||
| 72| | } | ||
| 73| | | ||
| 74| 33| let aliquot_sum: u64 = factors.iter().sum(); | ||
| 75| 33| | ||
| 76| 33| Some(match aliquot_sum { | ||
| 77| 33| sum if sum > number => Classification::Abundant, | ||
| ^9 ^9 | ||
| 78| 24| sum if sum < number => Classification::Deficient, | ||
| ^15 ^15 | ||
| 79| 9| _ => Classification::Perfect, | ||
| 80| | }) | ||
| 81| 36|} | ||
------------------ |
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,8 @@ | ||
Running: cargo llvm-cov --no-clean --all-features --show-missing-lines | ||
|
||
Filename Regions Missed Regions Cover Functions Missed Functions Executed Lines Missed Lines Cover Branches Missed Branches Cover | ||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ||
/home/vpayno/git_vpayno/exercism-workspace/rust/perfect-numbers/src/lib.rs 20 2 90.00% 3 1 66.67% 22 1 95.45% 0 0 - | ||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ||
TOTAL 20 2 90.00% 3 1 66.67% 22 1 95.45% 0 0 - | ||
|
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 @@ | ||
SF:/home/vpayno/git_vpayno/exercism-workspace/rust/perfect-numbers/src/lib.rs | ||
FN:1,_RNvXs0_CshU4NEG0KGoF_15perfect_numbersNtB5_14ClassificationNtNtCs8zepCCxJ8Q4_4core3cmp9PartialEq2eqB5_ | ||
FN:1,_RNvXCshU4NEG0KGoF_15perfect_numbersNtB2_14ClassificationNtNtCs8zepCCxJ8Q4_4core3fmt5Debug3fmt | ||
FN:57,_RNvCshU4NEG0KGoF_15perfect_numbers8classify | ||
FN:1,_RNvXs0_Cscb4KXbkaF77_15perfect_numbersNtB5_14ClassificationNtNtCs8zepCCxJ8Q4_4core3cmp9PartialEq2eqCsfVn1n8yW6ma_15perfect_numbers | ||
FN:1,_RNvXs0_Cscb4KXbkaF77_15perfect_numbersNtB5_14ClassificationNtNtCs8zepCCxJ8Q4_4core3cmp9PartialEq2eqB5_ | ||
FN:57,_RNvCscb4KXbkaF77_15perfect_numbers8classify | ||
FN:1,_RNvXCscb4KXbkaF77_15perfect_numbersNtB2_14ClassificationNtNtCs8zepCCxJ8Q4_4core3fmt5Debug3fmt | ||
FNDA:0,_RNvXs0_CshU4NEG0KGoF_15perfect_numbersNtB5_14ClassificationNtNtCs8zepCCxJ8Q4_4core3cmp9PartialEq2eqB5_ | ||
FNDA:0,_RNvXCshU4NEG0KGoF_15perfect_numbersNtB2_14ClassificationNtNtCs8zepCCxJ8Q4_4core3fmt5Debug3fmt | ||
FNDA:0,_RNvCshU4NEG0KGoF_15perfect_numbers8classify | ||
FNDA:11,_RNvXs0_Cscb4KXbkaF77_15perfect_numbersNtB5_14ClassificationNtNtCs8zepCCxJ8Q4_4core3cmp9PartialEq2eqCsfVn1n8yW6ma_15perfect_numbers | ||
FNDA:0,_RNvXs0_Cscb4KXbkaF77_15perfect_numbersNtB5_14ClassificationNtNtCs8zepCCxJ8Q4_4core3cmp9PartialEq2eqB5_ | ||
FNDA:12,_RNvCscb4KXbkaF77_15perfect_numbers8classify | ||
FNDA:0,_RNvXCscb4KXbkaF77_15perfect_numbersNtB2_14ClassificationNtNtCs8zepCCxJ8Q4_4core3fmt5Debug3fmt | ||
FNF:3 | ||
FNH:2 | ||
DA:1,11 | ||
DA:57,12 | ||
DA:58,12 | ||
DA:59,1 | ||
DA:60,11 | ||
DA:61,11 | ||
DA:62,11 | ||
DA:63,11 | ||
DA:64,11 | ||
DA:66,100651123 | ||
DA:67,100651112 | ||
DA:68,117 | ||
DA:69,100650995 | ||
DA:71,100651112 | ||
DA:74,11 | ||
DA:75,11 | ||
DA:76,11 | ||
DA:77,11 | ||
DA:78,8 | ||
DA:79,3 | ||
DA:81,12 | ||
BRF:0 | ||
BRH:0 | ||
LF:22 | ||
LH:21 | ||
end_of_record |
Oops, something went wrong.