Pythagorean quadruples: Difference between revisions

fix tests, port another answer from scala
(rust)
(fix tests, port another answer from scala)
Line 1,780:
This is equivalent to https://oeis.org/A094958
which simply contains positive integers of the form 2^n or 5*2^n
We provide iterator-style and loop-style code:
 
<lang rust>
Line 1,792 ⟶ 1,791:
.collect::<BinaryHeap<u16>>()
.into_sorted_vec()
}
 
fn a094958_filter() -> Vec<u16> {
(1..2200) // ported from Scala
.filter(|n| ((n & (n - 1) == 0) || (n % 5 == 0 && ((n / 5) & (n / 5 - 1) == 0))))
.collect()
}
 
Line 1,809 ⟶ 1,814:
println!("{:?}", a094958_iter());
println!("{:?}", a094958_loop());
println!("{:?}", a094958_filter());
}
 
Line 1,814 ⟶ 1,820:
mod tests {
use super::*;
static HAPPYANSWER: &str = "[1, 2, 4, 5, 8, 10, 16, 20, 32, 40, 64, 80, 128, 160, 256, 320, 512, 640, 1024, 1280, 2048]";
#[test]
fn test_a094958_iter() {
assert!(format!("{:?}", a094958_iter()) == HAPPYANSWER);
}
#[test]
fn test_a094958_loop() {
assert!(format!("{:?}", a094958_loop()) == HAPPYANSWER);
}
#[test]
fn test_a094958_filter() {
assert!(format!("{:?}", a094958_filter()) == ANSWER);
}
}
Anonymous user