03-21-2012 08:19 AM
I really enjoyed having a go at Jcarmody's FizzBuzz Challenge a couple of weeks ago.
It was a bit of a distraction during a lunch break, but more importantly seeing other peoples solutions gave me new insight on how some functions operate.
So i'm posting a new Coffee Break Coding Challenge (fanfare please! ).
The challenge is supposed to be a simple 5-10 min puzzle (but some Knights might struggle to make it last 5 - 10 secs ), hopefully producing some varied solutions that we can all learn from.
If this takes off and enough people enjoy it, perhaps we could make a regular feature. Anyway I'm getting ahead of myself; so here is the first Challenge:
"For any number, find the next highest number that uses all of the same digits. E.g. The next highest number after 123, using all the digits 1, 2 & 3, is 132."
p.s. Post your solutions in a spoiler box to avoid sending people down the same path as you!
03-21-2012 09:54 AM
Interesting. I probably won't have time for this before the weekend.
Anyway, what are the limits on "any number", does it need to fit in one of the integer data types or can it have a near infinite number of digits?
Is the input number a decimally formatted string?
03-21-2012 10:02 AM
And since I am doing a stand-up coding routine let me ask...
THe input value will be assumed to have a larger available eg 321 ?
03-21-2012 10:06 AM
I did think about putting in strictly defined conditions on the input number, but I thought this might limit the creativity of some solutions.
A basic program might consider that only integers data types are allowed, but a more complex one would consider alternatives.
I guess my answer would be that it is up to you to define what "any number" means and either state the conditions your solution works for or impliment controls to ensure that people can't break it!
p.s. If this is too vague then we could easily introduce type definitions into the challenge description
03-21-2012 10:15 AM - edited 03-21-2012 10:16 AM
I realised this when I was going to use 321 as the example in the challenge description!
I would say that it's the programmers responsibility to check that an input will function correctly with his/her programme and alert the user if it won't.
03-21-2012 09:58 PM - edited 03-21-2012 10:08 PM
are we limited to decimal digits or limited by non-duplicated digits in any place? (eg. for "123" would 1123 be a valid solution? This, I believe but do not wish to prove mathematically today, would theoretically unbound the solution by allowing 123, 1233, 123.3, 123.23, ad nasuem as member of the set solving the problem )
Love these types of posts! Really tough to pose these problems! noobs do it better
If you can pose these problems.... I would love to play! I'm just not sharp enough to forment the questions. Really (I do puzzles often, and really like the problem solving... I do not author puzzles. That takes a skill set I lack)
03-22-2012 04:19 AM
Right ok guys, this is all my fault for not properly defining the challenge (surely this never happens in the real world! )
So now i'm going to redefine the problem:
Your task (should you choose to accept it) is to produce a piece of code that will accept any integer input and calculate the next highest integer that uses all of the same digits.
Cue the A-team music and good luck!
03-22-2012 06:42 AM - edited 03-22-2012 06:44 AM
OK, so here is a baseline - the stupid, brute force approach. No math, no elegance, just a quick and dirty solution, which seems to work correctly. It even handles duplicate digits, but it only works with positive integers.
03-22-2012 08:35 AM
Here's my crack at this, done over lunch.
I'm sure there are much more elegant ways of doing the maths and sorting the arrays etc. so comments/improvements on any pieces of code in this thread here would be a great help to everyone.
I confidently expect to see this re-posted in the Rube thread
You're going to have to excuse the wiring - I've still got a giant sandwich to get through before the lunch hour is over!