[go: nahoru, domu]

Skip to content

Commit

Permalink
Added recursion solution
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-harding committed Sep 6, 2023
1 parent 1494166 commit 4ac3d79
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl TripleStep for Solution {
fn triple_step(steps: usize) -> usize {
// Your solution here
use crate::solutions::_08_recursion_and_dynamic_programming::_01_triple_step as solutions;
solutions::Solution::triple_step(steps)
solutions::RecursionSolution::triple_step(steps)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub struct Solution;
impl TripleStep for Solution {
fn triple_step(steps: usize) -> usize {
match steps {
0 => 0,
0 => 1,
1 => 1,
2 => 2,
3 => 4,
Expand All @@ -27,3 +27,20 @@ impl TripleStep for Solution {
}
}
}

pub struct RecursionSolution;

impl TripleStep for RecursionSolution {
fn triple_step(steps: usize) -> usize {
match steps {
0 => 1,
1 => 1,
2 => 2,
_ => {
Self::triple_step(steps - 1)
+ Self::triple_step(steps - 2)
+ Self::triple_step(steps - 3)
}
}
}
}

0 comments on commit 4ac3d79

Please sign in to comment.