#[derive(Debug)]enumBadInputError{ZeroLength,FirstPoint(char),}fncount_patterns_from(first_point:char,length:usize)->Result<u16,BadInputError>{iflength<2{returnErr(BadInputError::ZeroLength);}Ok(matchfirst_point{'A'|'C'|'G'|'I'=>[1,5,31,154,684,2516,7104,13792,13792],'B'|'D'|'F'|'H'=>[1,7,37,188,816,2926,8118,15564,15564],'E'=>[1,8,48,256,1152,4248,12024,23280,23280],bad=>returnErr(BadInputError::FirstPoint(first_point)),}.get(length-2).cloned().unwrap_or(0))}fnmain(){forstartin(b'A'..=b'I').map(char::from){println!("starting at {}, there are",start);forlengthin1..=10{matchcount_patterns_from(start,length){Ok(num)=>println!("\t{} patterns of length {}",num,length),Err(err)=>eprintln!("{:?}",err),}}}}
Deviations from spec: function named in snake_case, takes a char and not a single-char string.
Deviations from test cases: errors on length 1, as phones don't accept that, you need at least two anchors.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Rust, precomputed here
Deviations from spec: function named in snake_case, takes a char and not a single-char string.
Deviations from test cases: errors on length
1
, as phones don't accept that, you need at least two anchors.