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