2012-12-11 01:32:48 +00:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-03-22 18:23:21 +00:00
|
|
|
// Check that functions can modify local state.
|
2012-05-11 20:09:19 +00:00
|
|
|
|
2014-03-05 23:28:08 +00:00
|
|
|
|
2014-03-05 22:02:44 +00:00
|
|
|
fn sums_to(v: Vec<int> , sum: int) -> bool {
|
2013-06-05 04:43:41 +00:00
|
|
|
let mut i = 0u;
|
|
|
|
let mut sum0 = 0;
|
2012-05-11 20:09:19 +00:00
|
|
|
while i < v.len() {
|
2014-03-05 23:28:08 +00:00
|
|
|
sum0 += *v.get(i);
|
2012-05-11 20:09:19 +00:00
|
|
|
i += 1u;
|
|
|
|
}
|
2012-08-02 00:30:05 +00:00
|
|
|
return sum0 == sum;
|
2012-05-11 20:09:19 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 22:02:44 +00:00
|
|
|
fn sums_to_using_uniq(v: Vec<int> , sum: int) -> bool {
|
2013-06-05 04:43:41 +00:00
|
|
|
let mut i = 0u;
|
2014-05-06 01:56:44 +00:00
|
|
|
let mut sum0 = box 0;
|
2012-05-11 20:09:19 +00:00
|
|
|
while i < v.len() {
|
2014-03-05 23:28:08 +00:00
|
|
|
*sum0 += *v.get(i);
|
2012-05-11 20:09:19 +00:00
|
|
|
i += 1u;
|
|
|
|
}
|
2012-08-02 00:30:05 +00:00
|
|
|
return *sum0 == sum;
|
2012-05-11 20:09:19 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 22:02:44 +00:00
|
|
|
fn sums_to_using_rec(v: Vec<int> , sum: int) -> bool {
|
2013-06-05 04:43:41 +00:00
|
|
|
let mut i = 0u;
|
|
|
|
let mut sum0 = F {f: 0};
|
2012-05-11 20:09:19 +00:00
|
|
|
while i < v.len() {
|
2014-03-05 23:28:08 +00:00
|
|
|
sum0.f += *v.get(i);
|
2012-05-11 20:09:19 +00:00
|
|
|
i += 1u;
|
|
|
|
}
|
2012-08-02 00:30:05 +00:00
|
|
|
return sum0.f == sum;
|
2012-05-11 20:09:19 +00:00
|
|
|
}
|
|
|
|
|
2013-01-26 06:46:32 +00:00
|
|
|
struct F<T> { f: T }
|
|
|
|
|
2014-03-05 22:02:44 +00:00
|
|
|
fn sums_to_using_uniq_rec(v: Vec<int> , sum: int) -> bool {
|
2013-06-05 04:43:41 +00:00
|
|
|
let mut i = 0u;
|
2014-05-06 01:56:44 +00:00
|
|
|
let mut sum0 = F {f: box 0};
|
2012-05-11 20:09:19 +00:00
|
|
|
while i < v.len() {
|
2014-03-05 23:28:08 +00:00
|
|
|
*sum0.f += *v.get(i);
|
2012-05-11 20:09:19 +00:00
|
|
|
i += 1u;
|
|
|
|
}
|
2012-08-02 00:30:05 +00:00
|
|
|
return *sum0.f == sum;
|
2012-05-11 20:09:19 +00:00
|
|
|
}
|
|
|
|
|
2013-02-02 03:43:17 +00:00
|
|
|
pub fn main() {
|
2013-02-14 19:47:00 +00:00
|
|
|
}
|