From 3044ef91e3056e01e8dfcfdc45a82af14ddafa0f Mon Sep 17 00:00:00 2001 From: Alex Bethel Date: Tue, 7 Dec 2021 14:27:45 -0700 Subject: [PATCH] Better BF function conversions --- ablescript/src/variables.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ablescript/src/variables.rs b/ablescript/src/variables.rs index 47a3a1d..11e2d6a 100644 --- a/ablescript/src/variables.rs +++ b/ablescript/src/variables.rs @@ -209,10 +209,12 @@ impl Value { Value::Int(i) => Functio::BfFunctio { instructions: { let instruction_mappings = [b'[', b']', b'+', b'-', b',', b'.', b'<', b'>']; - std::iter::successors(Some(i), |i| Some(i >> 3)) - .take_while(|&i| i != 0) - .map(|i| instruction_mappings[(i & 0x07) as usize]) - .collect() + std::iter::successors(Some(i as usize), |i| { + Some(i / instruction_mappings.len()) + }) + .take_while(|&i| i != 0) + .map(|i| instruction_mappings[i % instruction_mappings.len()]) + .collect() }, tape_len: crate::brian::DEFAULT_TAPE_SIZE_LIMIT, },