-
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
1 parent
9490a04
commit aafa3b2
Showing
6 changed files
with
65 additions
and
4 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
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,18 @@ | ||
Rust Implementation of Problem 12 | ||
================================= | ||
|
||
View source code `here on GitHub! <https://github.com/LivInTheLookingGlass/Euler/blob/master/rust/src/p0012.rs>`_ | ||
|
||
Includes | ||
-------- | ||
|
||
- `primes <./primes.html>`_ | ||
|
||
Problem Solution | ||
---------------- | ||
|
||
.. rust:fn:: p0012::p0012() -> i128 | ||
.. literalinclude:: ../../rust/src/p0012.rs | ||
:language: rust | ||
:linenos: |
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
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,41 @@ | ||
/* | ||
Project Euler Problem 12 | ||
I'm very glad that I did the most expansive version of my prime infrastructure | ||
from the start. | ||
Problem: | ||
The sequence of triangle numbers is generated by adding the natural numbers. So | ||
the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten | ||
terms would be: | ||
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... | ||
Let us list the factors of the first seven triangle numbers: | ||
1: 1 | ||
3: 1,3 | ||
6: 1,2,3,6 | ||
10: 1,2,5,10 | ||
15: 1,3,5,15 | ||
21: 1,3,7,21 | ||
28: 1,2,4,7,14,28 | ||
We can see that 28 is the first triangle number to have over five divisors. | ||
What is the value of the first triangle number to have over five hundred | ||
divisors? | ||
*/ | ||
use crate::primes; | ||
|
||
pub fn p0012() -> i128 { | ||
let mut num: u64 = 0; | ||
for x in 1.. { | ||
num += x; | ||
if proper_divisors(num).len() > 499 { | ||
return num.into(); | ||
} | ||
} | ||
return -1; | ||
} |