-
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
4d65f88
commit bf9baf8
Showing
22 changed files
with
430 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
fibonacci.rs | ||
============= | ||
|
||
View source code :source:`rust/src/include/fibonacci.rs` | ||
|
||
Includes | ||
-------- | ||
|
||
use std::ops::{Add,Mul}; | ||
|
||
use num_traits::{one,zero,One,Zero}; | ||
|
||
use crate::include::iter_cache::cache_iterator; | ||
|
||
- :external:rust:trait:`num_traits::One` | ||
- :external:rust:trait:`num_traits::Zero` | ||
- :external:rust:fn:`num_traits::one` | ||
- :external:rust:fn:`num_traits::zero` | ||
- :external:rust:trait:`std::ops::Add` | ||
- :external:rust:trait:`std::ops::Mul` | ||
|
||
.. rust:struct:: pub struct fibonacci::CachingIterator<I, T> where I: Iterator<Item = T> + 'static, T: Clone + 'static | ||
This struct implements a global cache that maps an iterator-iterated pair to a cache of values. It is mostly | ||
intended for use with the prime function generator. | ||
|
||
.. rust:fn:: pub fn fibonacci::CachingIterator::new() -> CachingIterator<I, T> where I: Iterator<Item = T> + 'static, T: Clone + 'static | ||
.. rust:fn:: pub fn fibonacci::CachingIterator::default() -> CachingIterator<I, T> where I: Iterator<Item = T> + 'static, T: Clone + 'static | ||
.. rust:fn:: pub fn fibonacci::CachingIterator::next() -> Option<T> where T: Clone + 'static | ||
.. literalinclude:: ../../../../rust/src/include/fibonacci.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Rust Implementation of Problem 36 | ||
================================= | ||
|
||
View source code :source:`rust/src/p0036.rs` | ||
|
||
Includes | ||
-------- | ||
|
||
- `math <./lib/math.html>`_ | ||
|
||
Problem Solution | ||
---------------- | ||
|
||
.. rust:fn:: pub fn p0036::p0036() -> utils::Answer | ||
.. literalinclude:: ../../../rust/src/p0036.rs | ||
:language: rust | ||
:linenos: | ||
|
||
.. tags:: palindrome, number-base |
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,20 @@ | ||
Rust Implementation of Problem 37 | ||
================================= | ||
|
||
View source code :source:`rust/src/p0037.rs` | ||
|
||
Includes | ||
-------- | ||
|
||
- `math <./lib/math.html>`_ | ||
|
||
Problem Solution | ||
---------------- | ||
|
||
.. rust:fn:: pub fn p0037::p0037() -> utils::Answer | ||
.. literalinclude:: ../../../rust/src/p0037.rs | ||
:language: rust | ||
:linenos: | ||
|
||
.. tags:: prime-number, digit-manipulation, rust-iterator |
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,20 @@ | ||
Rust Implementation of Problem 45 | ||
================================= | ||
|
||
View source code :source:`rust/src/p0045.rs` | ||
|
||
Includes | ||
-------- | ||
|
||
- `math <./lib/math.html>`_ | ||
|
||
Problem Solution | ||
---------------- | ||
|
||
.. rust:fn:: pub fn p0045::p0045() -> utils::Answer | ||
.. literalinclude:: ../../../rust/src/p0045.rs | ||
:language: rust | ||
:linenos: | ||
|
||
.. tags:: figurate-number, triangle-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,20 @@ | ||
Rust Implementation of Problem 53 | ||
================================= | ||
|
||
View source code :source:`rust/src/p0053.rs` | ||
|
||
Includes | ||
-------- | ||
|
||
- `math <./lib/math.html>`_ | ||
|
||
Problem Solution | ||
---------------- | ||
|
||
.. rust:fn:: pub fn p0053::p0053() -> utils::Answer | ||
.. literalinclude:: ../../../rust/src/p0053.rs | ||
:language: rust | ||
:linenos: | ||
|
||
.. tags:: combinatorics, factorial, binomial-coefficient |
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,80 @@ | ||
use std::ops::{Add,Mul}; | ||
|
||
use num_traits::{one,zero,One,Zero}; | ||
|
||
use crate::include::iter_cache::cache_iterator; | ||
|
||
pub fn fib<I>() -> impl Iterator<Item = I> where I: Copy + Zero + One + Add + 'static { | ||
return cache_iterator(Fibonacci::<I>::new()); | ||
} | ||
|
||
pub fn fib_by_3<I>() -> impl Iterator<Item = I> where I: Copy + Zero + One + Add + Mul + 'static { | ||
return cache_iterator(FibonacciBy3::<I>::new()); | ||
} | ||
|
||
pub struct Fibonacci<I> { | ||
a: I, | ||
b: I, | ||
} | ||
|
||
impl<I> Default for Fibonacci<I> where I: Zero + One { | ||
fn default() -> Self { | ||
return Fibonacci::<I>{ | ||
a: zero(), | ||
b: one(), | ||
}; | ||
} | ||
} | ||
|
||
impl<I> Fibonacci<I> where I: Zero + One { | ||
pub fn new() -> Self { | ||
return Default::default(); | ||
} | ||
} | ||
|
||
impl<I> Iterator for Fibonacci<I> where I: Zero + One + Add + Copy { | ||
type Item = I; | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
let prior_a = self.a; | ||
let prior_b = self.b; | ||
self.b = self.a + self.b; | ||
self.a = prior_b; | ||
return Some(prior_a); | ||
} | ||
} | ||
|
||
pub struct FibonacciBy3<I> { | ||
a: I, | ||
b: I, | ||
} | ||
|
||
impl<I> Default for FibonacciBy3<I> where I: Zero + One + Add + Copy { | ||
fn default() -> Self { | ||
let two = one::<I>() + one(); | ||
return FibonacciBy3::<I>{ | ||
a: zero(), | ||
b: two, | ||
}; | ||
} | ||
} | ||
|
||
impl<I> FibonacciBy3<I> where I: Zero + One + Add + Copy { | ||
pub fn new() -> Self { | ||
return Default::default(); | ||
} | ||
} | ||
|
||
impl<I> Iterator for FibonacciBy3<I> where I: Zero + One + Add + Mul + Copy { | ||
type Item = I; | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
let two = one::<I>() + one(); | ||
let four = two + two; | ||
let prior_a = self.a; | ||
let prior_b = self.b; | ||
self.b = four * self.b + self.a; | ||
self.a = prior_b; | ||
return Some(prior_a); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod iter_cache; | ||
pub mod factors; | ||
pub mod fibonacci; | ||
pub mod math; | ||
pub mod primes; | ||
pub mod problems; | ||
|
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
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
Oops, something went wrong.