fn arrangements2(input: &[usize]) -> usize {
    let mut sorted = input.to_vec();
    sorted.push(0);
    sorted.sort_unstable();

    let diffs = sorted.windows(2).map(|a| a[1] - a[0]).collect::<Vec<_>>();
    diffs
        .split(|&num| num != 1)
        .filter(|s| !s.is_empty())
        .map(|s| s.iter().sum::<usize>())
        .map(combos)
        .product()
}
/// Only diffs < 3 count to add combinations
/// This means that we need to identify all sequences of diffs = 1
/// We then sum consecutive 1 diff sequences
/// and compute the number of combos for each
/// finally, multiply all combos
/// This relies on the assumption that there are only 1 & 3 diffs.
Only diffs < 3 count to add combinations
This means that we need to identify all sequences of diffs = 1
We then sum consecutive 1 diff sequences
and compute the number of combos for each
finally, multiply all combos
This relies on the assumption that there are only 1 & 3 diffs.
Only diffs < 3 count to add combinations This means that we need to identify all sequences of diffs = 1 We then sum consecutive 1 diff sequences and compute the number of combos for each finally multiply all combos This relies on the assumption that there are only 1 & 3 diffs .
fn arrangements2(input: &[usize]) -> usize {
    let mut sorted = input.to_vec();
    sorted.push(0);
    sorted.sort_unstable();
    let diffs = sorted.windows(2).map(|a| a[1] - a[0]).collect::<Vec<_>>();
    diffs
        .split(|&num| num != 1)
        .filter(|s| !s.is_empty())
        .map(|s| s.iter().sum::<usize>())
        .map(combos)
        .product()
}
fn arrangements2 ( input : & [ usize ] ) -> usize { let mut sorted = input . to_vec ( ) ; sorted . push ( 0 ) ; sorted . sort_unstable ( ) ; let diffs = sorted . windows ( 2 ) . map ( | a | a [ 1 ] - a [ 0 ] ) . collect :: < Vec < _ > > ( ) ; diffs . split ( | & num | num != 1 ) . filter ( | s | ! s . is_empty ( ) ) . map ( | s | s . iter ( ) . sum :: < usize > ( ) ) . map ( combos ) . product ( ) }
Only diffs < 3 count to add combinations
This means that we need to identify all sequences of diffs = 1
We then sum consecutive 1 diff sequences
and compute the number of combos for each
finally, multiply all combos
This relies on the assumption that there are only 1 & 3 diffs.
Only diffs < 3 count to add combinations This means that we need to identify all sequences of diffs = 1 We then sum consecutive 1 diff sequences and compute the number of combos for each finally multiply all combos This relies on the assumption that there are only 1 & 3 diffs .
input
&[usize]
input
&[usize]