# Help Duke find a way out

Hello! For each Java conference, we come up with a game so that anyone can have fun at our booth. At the Joker 2018 conference, we invited participants to take Duke out of the maze, a detailed article about the game from last year can be found here . This year we continued the tradition and made a game where, answering Java questions, you need to help Duke find a hidden way out.

The idea is to wander around a private playing field with questions about Java, for each game session a unique grid of questions is generated. The player’s task in answering questions is to get Duke out of the maze through the door, the location of which is new each time, so it’s impossible to work out a strategy in advance and stick to it, there’s always a great chance to go in the wrong direction and be far from the exit. At the same time, answering different categories of questions, the player opens a different number of closed cells around him, when answering a simple question, 1 cell opens, on the average 2, and on complex 3. For the correct answer to a simple question, 1 point is awarded, for the average - 2 , and for the most difficult - 5, and if the player was able to get Duke out of the maze, then he will be awarded an additional 20 points. But not so simple! If the player does not answer the questions correctly, points burn out in proportion to the accrual system, answered incorrectly to a simple answer, lost 1 point, to an average - 2, to a difficult - 5. Therefore, 0 points are not the worst result, because you can go deep into minus. The one who gets the most points in 180 seconds wins.

The most difficult thing for the participants was this question (it, by the way, is from the category of simple ones):

What will the code print?

```
BigInteger big = BigInteger.valueOf(Long.MAX_VALUE);
System.out.println(big.add(big).longValue());
```

- -2
- 4294967294
- 18446744073709551614
- will throw
`ArithmeticException`

**Correct answer**

It is necessary to recall the basics of bit arithmetic and not to forget what

`longValue()`

implements narrowing primitive conversion:```
jshell> BigInteger big = BigInteger.valueOf(Long.MAX_VALUE)
big ==> 9223372036854775807
jshell> big.toString(16)
$2 ==> "7fffffffffffffff"
jshell> big.add(big).toString(16)
$3 ==> "fffffffffffffffe"
jshell> big.add(big).longValue()
$4 ==> -2
```

Some game statistics:

- the number of gaming sessions was 1123;
- maximum score 252;
- on average, for 1 game session a player answered correctly 15 questions.

Paradoxically, the fact is that this year, simple questions were answered worse than complex ones.

This time we decided not to publish the correct answers to the questions, but to give you the opportunity to get as close as possible to the conditions of the Odnoklassniki stand at the JPoint 2019 conference and put the game out in the public domain for everyone.

You can play the game and test your strength here: javagame.odkl.ru