1 // This code is editable and runnable!
3 // A simple integer calculator:
4 // `+` or `-` means add or subtract by 1
5 // `*` or `/` means multiply or divide by 2
7 let program
= "+ + * - /";
8 let mut accumulator
= 0;
10 for token
in program
.chars() {
12 '
+'
=> accumulator
+= 1,
13 '
-'
=> accumulator
-= 1,
14 '
*'
=> accumulator
*= 2,
15 '
/'
=> accumulator
/= 2,
16 _
=> { /* ignore everything else */ }
20 assert_eq
!(accumulator
, 1);