02-11-2016 10:09 AM
As I go through the forums or even work on my own projects I occasionally run across something that, after writing it up, I think "That was fun!" or "That was harder than I thought it would be".
So, let's post interesting questions or problems that you come across and let others see what answers they come up with.
02-11-2016 01:11 PM - edited 02-11-2016 01:16 PM
OK, so I meant to get this started earlier but got busy. I'll also admit that I shamelessly stole the idea from reddit, and so I am going to shamelessly steal the first puzzle. I don't expect later submissions to be this well written or extensive, but this one looked fun.
This exercise is inspired by a Numberphile video (no need to watch past 2:00).
Description
A number of sailors (let's call it N) are stranded on an island with a huge pile of coconuts and a monkey. During the night, each sailor (in turn) does the following without the others knowing:
In the morning, they split the remaining coconuts between them. This time the split is even. There's nothing left over for the monkey.
Your task: Given the number of sailors (N), how many coconuts were in the pile to begin with (lowest possible number)?
Formal inputs/outputs Input
The input is a single number: N, the number of sailors. This number is a whole number that is greater than or equal to 2.
Output
The output is a single number: the number of coconuts in the original pile.
Sample input/output
Input:
5
Output:
3121
Sample solution for 5 sailors: https://jsfiddle.net/722gjnze/8/
Credit
This challenge was originally suggested on /r/dailyprogrammer_ideas by /u/TinyLebowski (prior to some changes by me). Have a cool challenge idea? Hop on over to /r/dailyprogrammer_ideas to tell everyone about it!
Edit: Source: https://www.reddit.com/r/dailyprogrammer/comments/43ouxy/20160201_challenge_252_easy_sailors_and_mon...
02-11-2016 01:40 PM
It's not an individual challenge, but I've fount the https://projecteuler.net/ website, and I've been attempting to go through all the puzzles here and attempt to solve in LabVIEW (only). They can get tough very quickly.
"I won't be wronged. I won't be insulted. I won't be laid a-hand on. I don't do these things to other people, and I require the same from them." John Bernard Books
02-11-2016 01:47 PM
That was fun, I needed a break this afternoon. Once you get to 8 sailors it takes a while. 🙂
02-11-2016 02:29 PM - edited 02-11-2016 02:32 PM
Funny you start his thread today because I was thinking about irational numbers.
Is it even possible to contrive a test of irrationality in a computer environment where everything has to be entered as a rational number?
Ben
02-11-2016 03:45 PM
02-12-2016 07:36 AM
@Ben wrote:Funny you start his thread today because I was thinking about irational numbers. [...]
Ben
Are irrational numbers the numbers engineers get from managers? Budgets, deadlines...
02-12-2016 02:12 PM
I have a VI (it's actually two VIs, is that breaking some rules?) that computes the answer for 9 sailors in 10.8ms. Answer for 8 sailors takes 4.5ms.
I'll post them on Monday.
02-12-2016 05:48 PM - edited 02-12-2016 05:50 PM
Hmm, removing a recursive VI call and replacing it with a for loop gets my timing for the 8 sailor solution down to 0.4ms..... Funnily enough the 9 sailor solution only takes 1.4ms. Seems like the Recursive VI call overhead was pretty significant in the previous example. I'll tidy up the code and post both versions next week. I think I'll implement an I64 version to get to higher numbers.
02-12-2016 06:34 PM
@Intaris wrote:I have a VI (it's actually two VIs, is that breaking some rules?) that computes the answer for 9 sailors in 10.8ms. Answer for 8 sailors takes 4.5ms.
Hmm, noticed some patterns and do 8 in under 2us. Have to work out the theory.... 😉