heh
hmm
| -rw-r--r-- | src/main.rs | 6 | ||||
| -rw-r--r-- | src/util.rs | 12 |
2 files changed, 7 insertions, 11 deletions
diff --git a/src/main.rs b/src/main.rs index fa3a6ea..a406ec8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,10 +57,10 @@ pub fn p2(i: &str) -> u64 { } .as_ptr() as *const [u8; 6]) }; - let c = 読む::hex(&dat[0..5]).unwrap(); + let c = unsafe { 読む::hex(&dat[0..5]).unwrap_unchecked() }; let (ox, oy) = (x, y); for _ in 0..c { - let d = 読む::hex_dig(dat[5]).unwrap(); + let d = 読む::hex_dig(dat[5]); (x, y) = mat!(d { 0 => (x + 1, y), 1 => (x, y - 1), @@ -78,7 +78,7 @@ pub fn p2(i: &str) -> u64 { } pub fn run(i: &str) -> impl Display { - p1(i) + p2(i) } fn main() { diff --git a/src/util.rs b/src/util.rs index f642d38..874ab5a 100644 --- a/src/util.rs +++ b/src/util.rs @@ -680,19 +680,15 @@ pub mod 読む { } } - pub fn hex_dig(b: u8) -> Result<u8, ()> { - match b { - b'0'..=b'9' => Ok(b as u8 - b'0' as u8), - b'a'..=b'f' => Ok(b as u8 - (b'a' as u8 - 10)), - _ => Err(()), - } + pub fn hex_dig(b: u8) -> u8 { + (b & 0xF) + 9 * (b >> 6) } pub fn hex(mut d: &[u8]) -> Result<u32, ()> { let &b = d.take_first().ok_or(())?; - let mut num = hex_dig(b)? as u32; + let mut num = hex_dig(b) as u32; while let Some(&b) = d.take_first() { - num = num * 16 + hex_dig(b)? as u32; + num = num * 16 + hex_dig(b) as u32; } Ok(num) } |