Ok, I'll be more clear. First, when I said that the arithmetic operation will take more time, I said it with respect to the mod2 machine. Second, let's take your example (just a wild guess, is this game GO)

```#!/usr/bin/perl
# note that %b modifier processes binary. Similarly, %x processes hexa
+decimal and %o is for octal.

use strict;
use warnings;

my (\$move, \$pos);
\$move = 0b1111111111111111;
\$pos = 0b0000111111111111;
printf "%b\n", (\$move ^ \$pos);

Even here, there are no arithmetical operations. Note that Exclusive Or is a logical operation. This is somewhat similar to a mod machine. You change state only if there are opposite inputs. The catch here is, if we'd have used strings instead of a number, there would've been a few more lines of code, keeping in mind and as you said, breaking the string and using regexes. I'm not saying that we should replace every arithmetic operation with string/logical operation, we just can't, I'm just trying to convey that there are better ways to do simple things that school teaches us in a very dogmatic way.

I mean seriously, why should I actually divide a number by 2 and check the remainder when I can directly check the last digit?! Or why should I recursively divide and mod by 10 to generate the reverse of a number when I can do it in one line?!

```/* Apologies for using C, but its my "mother-tongue" :P */

#include <stdio.h>

int main(int argc, char **argv)
{
int ;
for(i = (strlen(argv[1]) - 1); i >= 0; i--){
printf("%c", *(argv[1] + i)); /* reverse a string, a number, a
+ sentence, a novel... */
}
}
Note/PS: Logical operations, too, are faster than arithmetical operations afaik.

In reply to Re^2: A mod2 Machine. by code-ninja
in thread A mod2 Machine. by code-ninja

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.