Here's a fun puzzle from StackExchange [1]:

----------
You are on your way to visit your Grandma, who lives at the end of the
valley. It's her birthday, and you want to give her the cakes you've made.

Between your house and her house, you have to cross 7 bridges, and as it
goes in the land of make believe, there is a troll under every bridge!
Each troll, quite rightly, insists that you pay a troll toll. Before you
can cross their bridge, you have to give them half of the cakes you are
carrying, but as they are kind trolls, they each give you back a single
cake.

How many cakes do you have to leave home with to make sure that you arrive
at Grandma's with exactly 2 cakes?

[If you go to your grandma's with a half eaten cake, she's gonna be pissed.
The trolls can't give you half a cake back. It is unhygienic and
disgusting.]
----------

Code isn't really required to solve the puzzle (in fact, starting out to
code a solution immediately makes one recognize that such an exercise is
superfluous), nevertheless, an example of how to solve this in J in ....
10
 9
 8
 7
 6
 5
 4
 3
 2
 1


   +:@<:@]^:(-@[)/ 7 2    NB. x=# bridges, y=# cakes for Granny
NB. <Result redacted>

-Dan

[1]  Puzzling.SE: Troll Toll
     http://puzzling.stackexchange.com/questions/626/paying-the-troll-toll
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to