projects
/
rust-101.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
part07.rs lines shortened
[rust-101.git]
/
solutions
/
src
/
bigint.rs
diff --git
a/solutions/src/bigint.rs
b/solutions/src/bigint.rs
index 96958b47bbe3d262804dc78ac8ec59a0fab4a37d..5869ba89401076c8998bb7414dae31e71a3d738c 100644
(file)
--- a/
solutions/src/bigint.rs
+++ b/
solutions/src/bigint.rs
@@
-154,16
+154,14
@@
impl Minimum for BigInt {
other
} else {
// compare back-to-front, i.e., most significant digit first
other
} else {
// compare back-to-front, i.e., most significant digit first
- let mut idx = self.data.len()
-1
;
+ let mut idx = self.data.len();
while idx > 0 {
while idx > 0 {
+ idx = idx-1;
if self.data[idx] < other.data[idx] {
return self;
} else if self.data[idx] > other.data[idx] {
return other;
}
if self.data[idx] < other.data[idx] {
return self;
} else if self.data[idx] > other.data[idx] {
return other;
}
- else {
- idx = idx-1;
- }
}
// the two are equal
return self;
}
// the two are equal
return self;
@@
-285,7
+283,9
@@
mod tests {
let b3 = BigInt::from_vec(vec![0, 1]);
assert_eq!(b1.min(&b2), &b1);
let b3 = BigInt::from_vec(vec![0, 1]);
assert_eq!(b1.min(&b2), &b1);
+ assert_eq!(b2.min(&b1), &b1);
assert_eq!(b3.min(&b2), &b2);
assert_eq!(b3.min(&b2), &b2);
+ assert_eq!(b2.min(&b3), &b2);
}
#[test]
}
#[test]