-2
\$\begingroup\$

The students in my high school computer science class were asked to write the game of nim for a simple project. Most of them found it very easy and finished quickly. However, one student came up with this solution. I'll probably make them redo it anyway, but I'm wondering if anyone can understand what's going on.

enum $ {

$$;
static int _, $_$, $_, _0_;

{
    {
        {
            {
                _$ $_ = _$.__;
            }
        }
    }
}

enum _$ {

    __(new byte[][]{
        "\nNumber of stones: \0\nPlayer one move: \0Computer takes \0\nComputer wins!\n\0\nPlayer wins!\n".getBytes(),
        new byte[]{(byte) (_ = (int) (Math.random() * (_ = ((_ = -~_) * (_ << -~-~_) + -~-~-~_ + -~ ~ ~-~_)) + _))}},
        null);

    java.io.Console ___ = System.console();
    _$(byte[] _$_[], String $[]) {
        for ($ = new String(_$_[$_$]).split(Character.toString((char) $_$)); _ > 0;) {
            ___.printf($[$_$] + _);
            do _0_ = ___.readLine($[-~$_$]).getBytes()[$_$] - 060;
            while (_0_ > -~-~-~$_$ || _0_ > _);
            _ -= $_$ + _0_ >> $_$;
            if (((!(!(((!((!((_) < -~($_ = $_$))))))))))) break;
            _ -= $_ = Math.min((int) (Math.random() * -~-~-~$_$ + -~$_$), _);
            ___.printf($[-~-~$_$] + $_);
        }
        ___.printf(($_$ = -~-~-~$_$) > _ ? $[$_ > 0 ? -~$_$ : $_$] : $[2]);}}};

`

\$\endgroup\$
2
  • \$\begingroup\$ See stackoverflow.com/questions/7906483/… The rest is just obfuscating variable names. And it has a bug, because it allows the player to take 0. \$\endgroup\$ Nov 24, 2011 at 18:05
  • \$\begingroup\$ PS This isn't actually on topic for this site. It's essentially a duplicate of the linked post, so I would suggest that you flag it for closing; otherwise, I'm not sure where it would fit. \$\endgroup\$ Nov 24, 2011 at 18:06

1 Answer 1

3
\$\begingroup\$

just cause I have way too much time on my hands:

import java.io.*;
import java.util.*;

enum MyEnum {

    $$;

    {
        EnumCalc $_ = EnumCalc.CONSTR;
    }

    enum EnumCalc {

        static int total, $_$, comp, player;
            CONSTR( );

        PrintStream out = System.out;
        Scanner scan = new Scanner(System.in);

        EnumCalc() {

            total = (int) (Math.random() * 20 + 20);
            strings = new String[] { "\nNumber of stones: ",
                    "\nPlayer one move: ", "Computer takes ",
                    "\nComputer wins!\n","\nPlayer wins!\n" };
            while(total > 0) {
                out.printf("\nNumber of stones: " + total);

                do {
                    out.printf("\nPlayer one move: ");
                    player = scan.nextLine().charAt(0) - '0';
                } while (player > 3 || player > total);//input loop

                total -= player;
                comp = 0;
                if (total < 1)
                    break;
                comp = Math.min((int) (Math.random() * 4), total);
                total -= comp;
                out.printf("Computer takes " + comp);
            }
            String string;
            if (3 > total)
                string = comp > 0 ?"\nPlayer wins!\n":"\nComputer wins!\n";
            else
                string = "Computer takes ";
            out.printf(string);
        }


    }
};

note that -~i is the same as 1+i

and I replaced the console calls with System.out and Scanner cause eclipse doesn't give me a Console

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.