2012-05-11 15:09:19 -05:00
|
|
|
// Check that pure functions can modify local state.
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
pure fn sums_to(v: ~[int], sum: int) -> bool {
|
2012-05-11 15:09:19 -05:00
|
|
|
let mut i = 0u, sum0 = 0;
|
|
|
|
while i < v.len() {
|
|
|
|
sum0 += v[i];
|
|
|
|
i += 1u;
|
|
|
|
}
|
|
|
|
ret sum0 == sum;
|
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
pure fn sums_to_using_uniq(v: ~[int], sum: int) -> bool {
|
2012-05-11 15:09:19 -05:00
|
|
|
let mut i = 0u, sum0 = ~mut 0;
|
|
|
|
while i < v.len() {
|
|
|
|
*sum0 += v[i];
|
|
|
|
i += 1u;
|
|
|
|
}
|
|
|
|
ret *sum0 == sum;
|
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
pure fn sums_to_using_rec(v: ~[int], sum: int) -> bool {
|
2012-05-11 15:09:19 -05:00
|
|
|
let mut i = 0u, sum0 = {f: 0};
|
|
|
|
while i < v.len() {
|
|
|
|
sum0.f += v[i];
|
|
|
|
i += 1u;
|
|
|
|
}
|
|
|
|
ret sum0.f == sum;
|
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
pure fn sums_to_using_uniq_rec(v: ~[int], sum: int) -> bool {
|
2012-05-11 15:09:19 -05:00
|
|
|
let mut i = 0u, sum0 = {f: ~mut 0};
|
|
|
|
while i < v.len() {
|
|
|
|
*sum0.f += v[i];
|
|
|
|
i += 1u;
|
|
|
|
}
|
|
|
|
ret *sum0.f == sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
}
|