Skip to content

Commit 44feed1

Browse files
authored
Merge pull request #5 from DanArmor/main
fix: return 1 for gcd_for_slice if all elements are 0.0
2 parents 2f03855 + 123f4e9 commit 44feed1

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/util.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ pub mod math {
1515
}
1616

1717
let first = slice[0];
18-
slice.iter().fold(
18+
let mut iter = slice.iter().skip_while(|x| x == &&0);
19+
let first = match iter.next() {
20+
Some(v) => *v,
21+
None => return 1
22+
};
23+
24+
let gcd = iter.fold(
1925
first,
2026
|acc, cur| {
2127
if *cur == 0 {
@@ -24,7 +30,8 @@ pub mod math {
2430
gcd(*cur, acc)
2531
}
2632
},
27-
)
33+
);
34+
gcd
2835
}
2936
}
3037

0 commit comments

Comments
 (0)