fn combos(i: i32, slice: &[i32], cached: &mut HashMap<i32, i64>) -> i64 {
    if slice.is_empty() {
        return 1;
    }

    if let Some(cache) = cached.get(&i) {
        return *cache;
    }

    let mut total = 0;

    for (index, x) in slice.iter().enumerate() {
        if (x - i) <= 3 {
            let combo = combos(slice[index], &slice[(index + 1)..], cached);

            cached.insert(slice[index], combo);

            total += combo;
        } else {
            break;
        }
    }

    total
}
// Work out how many combinations of < 3 steps are in the slice.
Work out how many combinations of < 3 steps are in the slice.
Work out how many combinations of < 3 steps are in the slice .
fn combos(i: i32, slice: &[i32], cached: &mut HashMap<i32, i64>) -> i64 {
    if slice.is_empty() {
        return 1;
    }
    if let Some(cache) = cached.get(&i) {
        return *cache;
    }
    let mut total = 0;
    for (index, x) in slice.iter().enumerate() {
        if (x - i) <= 3 {
            let combo = combos(slice[index], &slice[(index + 1)..], cached);
            cached.insert(slice[index], combo);
            total += combo;
        } else {
            break;
        }
    }
    total
}
fn combos ( i : i32 , slice : & [ i32 ] , cached : & mut HashMap < i32 , i64 > ) -> i64 { if slice . is_empty ( ) { return 1 ; } if let Some ( cache ) = cached . get ( & i ) { return * cache ; } let mut total = 0 ; for ( index , x ) in slice . iter ( ) . enumerate ( ) { if ( x - i ) <= 3 { let combo = combos ( slice [ index ] , & slice [ ( index + 1 ) .. ] , cached ) ; cached . insert ( slice [ index ] , combo ) ; total += combo ; } else { break ; } } total }
Work out how many combinations of < 3 steps are in the slice.
Work out how many combinations of < 3 steps are in the slice .
i
i32
slice
&[i32]
cached
&mut HashMap<i32, i64>
i
i32
slice
&[i32]
cached
&mut HashMap<i32, i64>