Better BF function conversions

pull/1/head
Alex Bethel 2021-12-07 14:27:45 -07:00
parent b23963137a
commit 0217f25aa8
1 changed files with 6 additions and 4 deletions

View File

@ -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,
},