This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(unused)] | |
fn peaks<T: std::cmp::PartialOrd>(values: Vec<T>) -> Vec<usize> { | |
values | |
.windows(3) | |
.enumerate() | |
.filter_map(|(i, window)| { | |
if window[0] < window[1] && window[1] > window[2] { | |
Some(i + 1) | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(unused)] | |
fn reorder<T: Clone>(values: Vec<T>, indices: Vec<usize>) -> Vec<Option<(usize, T)>> { | |
let mut pairs: Vec<_> = indices.iter().zip(values).collect(); | |
pairs.sort_by_key(|v| v.0); | |
let mut iter = pairs.iter().peekable(); | |
(0..*pairs.last().unwrap().0 + 1) | |
.map(|i| match iter.peek() { | |
Some((j, _)) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! Checks if an integer is an odious number. | |
/// Determine if an integer is an odious number. | |
/// | |
/// 14 is an odious number because it has an odd number of 1s in its binary | |
/// expansion 1110. Conversely, 5 isn't an odious number. It has an even number | |
/// of 1s in its binary expansion 101 and so is called an evil number. | |
fn is_odious(num: i64) -> bool { | |
let mut num = num; | |
let mut sum = false; |