Puzzle challenges!

This is the place for forum games, not discussing games (Off-Topic), games development (Games Development), or Wesnoth (all other forums above).

Moderator: Forum Moderators

Post Reply
User avatar
Ravana
Forum Moderator
Posts: 2950
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Puzzle challenges!

Post by Ravana »

Learning haskell

Code: Select all

coin :: Int -> Int
coin n
  | n <= 1 = 0
  | otherwise = 1 + coin (div (n + 2) 3)

Code: Select all

*Test> coin 10
3
User avatar
Samonella
Posts: 382
Joined: January 8th, 2016, 5:41 pm
Location: USA

Re: Puzzle challenges!

Post by Samonella »

My guess:
edit:
Curiosity about Ravana's answer:
The last few months have been nothing but one big, painful reminder that TIMTLTW.

Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG
User avatar
Ravana
Forum Moderator
Posts: 2950
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Puzzle challenges!

Post by Ravana »

About Curiosity
That +2 is needed because div truncates float to get integer. So +2 when dividing by 3 results in rounding up.
Caladbolg
Posts: 198
Joined: January 1st, 2016, 4:40 pm
Location: Hopelessly trapped within the Submachine

Re: Puzzle challenges!

Post by Caladbolg »

Correct, both of you :D It's log_3 (N) rounded up in general case.
User avatar
Samonella
Posts: 382
Joined: January 8th, 2016, 5:41 pm
Location: USA

Re: Puzzle challenges!

Post by Samonella »

Ooh I see, very clever.

I have one more puzzle, though it's pretty similar to a couple of the others in this thread.

You are in a room with 20 bags of coins, containing 500 each. All of the coins are worthless except those in one particular bag, which are valid currency for recruiting units. The coins are impossible to tell apart, except that the fake ones weigh exactly 1 newton each and the real ones weigh 1.001.

Also in the room is a spring scale, which tells you the exact weight of whatever you measure (in newtons). However, after one use the scale breaks and becomes inaccurate. Typical.

You are only allowed to leave the room carrying 500 coins, so how can you use your single measurement to identify the bag that's valuable?

edit: Winner, Inky!
Last edited by Samonella on September 10th, 2017, 6:53 pm, edited 1 time in total.
The last few months have been nothing but one big, painful reminder that TIMTLTW.

Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG
User avatar
Ravana
Forum Moderator
Posts: 2950
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Puzzle challenges!

Post by Ravana »

However, after one use the scale breaks and becomes inaccurate. Typical.
Consistently inaccurate?
User avatar
Inky
Forum Moderator
Posts: 527
Joined: September 22nd, 2014, 1:02 am
Location: USA

Re: Puzzle challenges!

Post by Inky »

Samonella wrote:which are valid currency for recruiting units
Haha, love it!!!

Also, the fact that the scale works once means it already works more often than the typical scale I've come across :whistle:

I think this should work:
Spoiler:
User avatar
Samonella
Posts: 382
Joined: January 8th, 2016, 5:41 pm
Location: USA

Re: Puzzle challenges!

Post by Samonella »

Ravana wrote:Consistently inaccurate?
No, completely worthless.

Inky's answer was right, congratulations on your 500 gold!
The last few months have been nothing but one big, painful reminder that TIMTLTW.

Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG
User avatar
Inky
Forum Moderator
Posts: 527
Joined: September 22nd, 2014, 1:02 am
Location: USA

Re: Puzzle challenges!

Post by Inky »

Yeah, think of all the ruffians that could buy!

Here's an interesting question (that totally stumped me when I first encountered it):

The spider and the ant

A giant spider is attached to a cave wall with a 1 meter silk thread. An ant starting at the cave wall is trying to reach the spider by crawling along the thread (don't ask why, maybe it just wants to say hi).

The ant has crawled 1 cm (= .01 meters) along the thread, when suddenly the spider jumps forward by 1 meter (these things can jump really far, it is how they always come out of nowhere to maul your units in campaigns), stretching the thread to 2 meters (the ant maintains its relative position on the thread, so now instead of 1 cm it is 2 cm from the wall). Undaunted, the ant crawls another 1 cm along the thread, but then the spider jumps another meter, stretching the thread to 3 meters.

Assuming this continues indefinitely (so ignoring stuff like lifespans or whether silk can actually stretch), will the ant ever reach the spider?
Hint:
How about we do the same thing as for the other yes/no riddle: just make a guess as to what you think will happen and if you want you can give your reasoning for it, then after a few people guess (or if nobody posts for a while) I'll say which answer is correct. :)
User avatar
Ravana
Forum Moderator
Posts: 2950
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Puzzle challenges!

Post by Ravana »

WolframAlpha
says it takes 1.509*10^43 jumps for ant to reach spider.

Personally only managed to calculate up to 10^8 before Exception: stack overflow
User avatar
Inky
Forum Moderator
Posts: 527
Joined: September 22nd, 2014, 1:02 am
Location: USA

Re: Puzzle challenges!

Post by Inky »

Well wolfram alpha is one way to do it! :D :whistle:
Ravana's answer is correct! 8)
Answer
Yes; the ant's first cm is 1/100 of the thread length, then the second cm is 1/2 * 1/100 of the total length...the Nth cm is 1/N*1/100 of the thread length. So at the Nth step the portion of the thread the ant has covered is 1/100 * (1 + 1/2 + 1/3 + ... + 1/N) of the thread and we want to know whether this sum can surpass 1 is N if large enough.

In fact it can, because the sum 1 + 1/2 + 1/3 + ... + 1/N can become larger than any number you want if you add up enough terms (since it consists of 2 terms each > 1/4, followed by 4 terms > 1/8, then 8 terms > 1/16 and so on, where each group sums to > 1/2). This means no matter what the length of the original thread and the speeds of the spider and ant were, the ant would still reach the spider!

It just takes really long... as Ravana said, the value of N that makes this series sum to 100 is 1.509*10^43. (You could also approximate sum[t=1 to N] 1/t by integral[t=1 to N] 1/t dt = ln(N), to see that the time needed is on the order of e^100 = 2.67*10^43).
User avatar
skeptical_troll
Posts: 498
Joined: August 31st, 2015, 11:06 pm

Re: Puzzle challenges!

Post by skeptical_troll »

just thought it was nice noticing that this riddle it's a pretty good model of light (the ant) travelling in a Universe (the silk thread) with zero acceleration and decreasing expansion rate (Hubble parameter ~ 1/N). So if one uses the analogy to solve the riddle...
Spoiler:
Probably over-killing, but since it was already solved I thought it was worth adding some variations :mrgreen:
User avatar
Samonella
Posts: 382
Joined: January 8th, 2016, 5:41 pm
Location: USA

Re: Puzzle challenges!

Post by Samonella »

I came across another puzzle that is quite a bit like one from earlier in the thread, but this one is a little harder.

A band of 20 pirates has managed to steal a chest of treasure containing 100 gold coins, and it is time to divide up the booty. However, the pirate code specifies a very unusual method for doing so. First, the captain gets to propose a plan for dividing the gold; his plan might be that they divide it up equally between all 20 pirates, or he might suggest that he gets all the gold for himself, or one coin for everyone except the first mate, who gets the rest, or any other combination he wants. The whole crew (including the captain) will then vote on whether or not the plan passes. It does, as long as 50% or more of the pirates vote yes. Otherwise, the captain will walk the plank, and the first mate will then become captain and can propose a plan of his own. The process continues, following a predetermined hierarchy through the crew, until a plan passes.

Being pirates, every member of the crew is purely interested in getting as much gold as possible (without dying, of course). Additionally, they're quite a rough bunch even for pirates, so if one happened to know it would get the same amount of gold regardless of whether it votes yes or no, it will vote no just for the fun of making someone walk the plank. And finally, they know each other very well, and are all perfect logicians.

So the question is, what plan should the captain propose in order to get as much gold as possible without risking his own life?
The last few months have been nothing but one big, painful reminder that TIMTLTW.

Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG
User avatar
WTrawi
Posts: 136
Joined: July 11th, 2016, 6:04 pm
Location: My location is not public, but I know YOURS and I can use it against you.

Re: Puzzle challenges!

Post by WTrawi »

I've heard this riddle before and solved it, but now I can't remember the answer. I will think about it because I love this one :D
Not very active on the forum anymore, but I still read it, and I also still play Wesnoth and draw a bit.
User avatar
Ravana
Forum Moderator
Posts: 2950
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Puzzle challenges!

Post by Ravana »

#rank where #x = on which day #x is captain.

#1=91:#3=1:#5=1:#7=1:#9=1:#11=1:#13=1:#15=1:#17=1:#19=1
Spoiler:
Post Reply