From 6036ce2832c9b06794569a514b2dda92c2ebe056 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Sat, 9 Jun 2018 19:28:25 +0200 Subject: [PATCH] io: fix Elias gamma code reading --- src/io/intcode.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/io/intcode.rs b/src/io/intcode.rs index 5e35a15..e876772 100644 --- a/src/io/intcode.rs +++ b/src/io/intcode.rs @@ -71,11 +71,11 @@ fn read_rice(br: &mut BitReader, k: u8) -> BitReaderResult { } fn read_gamma(br: &mut BitReader) -> BitReaderResult { - let mut ret = 0; + let mut ret = 1; while br.read(1)? != 1 { ret = (ret << 1) | br.read(1)?; } - Ok(ret) + Ok(ret - 1) } fn read_gammap(br: &mut BitReader) -> BitReaderResult { -- 2.39.5