11
\$\begingroup\$

Write a program or a function in any programming language that takes a 6 digit hexadecimal input/argument. The input/argument can be 6 values or a 6 character string.

Your program should output an exactly 8 character wide rectangular block of characters containing only the hexadecimals supplied combined with spaces (+Linefeed). The rectangular block is a combination of smaller block shapes, one for each of the 6 supplied values.

Here follows 2 demostrative sample inputs and sample valid outputs:

Sample input:

"464fa6" or [4, 6, 4, 15, 10, 6]

One valid solution output:

44 66 ff
44 66 ff
   66 ff
aa     f
aaa ffff
aa  ffff
aaa     
    6 44
66666 44

Sample input:

"35bf12"

One valid solution output:

55555 22

bbbbbbbb
b b b   
      33
fffff  3
ff  ff  
ffffff 1

Rules:

  1. The output must be a rectangular shape

  2. The output can be of any vertical height, but must be exactly 8 characters wide

  3. The "inner blocks", refered to as the "block shape"s, cannot connect to any other block shape, the block shapes must be separated by a wall of blankspaces exactly 1 character wide horizontally, vertically and diagonally.

  4. The wall of blankspaces cannot run parallell to the outer edges, only 1 character wide wall-edges can exist at the output edges. There should not exist any linked spaces anywhere on the outmost rectangle edge on the output.

  5. The width of the wall of blankspaces should Not at any point exceed 1 character.

  6. The inner block shapes should be uniform with the area of x characters, where x is the hexadecimal value supplied and the shape should consist of the charater x where x is the hexadecimal character representative.

  7. The inner block shapes can be of any form as long as all of the shape characters connects vertically or horizontally, and does not valiating the rules for the wall of blankspaces.

  8. The 6 block shapes can be placed in any internal "order" inside the outputted rectangle.

  9. Valid input range: 1 ... 15 ("1" ... "f") for each shape. The input to your program should not contain any other information than the 6 hexadecimal numbers, and the input should not be sorted in any other way than in the samples before it is supplied to your program/function. Tell us what input format your solution uses (the input can not contain any other information than the hexadecimal values).

  10. A inner block shape can be hollow. The hole should be of blankspace characters which counts as wall of blankspaces, meaning the hole in a hollow inner block shape cannot be more than 1 characters wide.

Three examples of valid hollow shapes:

aaa
a aaa
aaa

999
9 9
999
9

ffffff
f   ff
ffffff

One example of an invalid hollow shape:

ffffff
f   f
f   f
fffff

I assume that all input combinations is not possible to "solve" according to the rules above, therefor I list 10 sample inputs that your program should be able to "solve" (all is verified solveable):

 1. 464fa6 (same as the first sample)
 2. 35bf12 (second example input seen above)
 3. 111126
 4. ff7fff
 5. 565656
 6. abcdef
 7. 1357bd
 8. 8c6a42
 9. ab7845
10. 349a67

Your program should be able to solve any of the 10 sample inputs in resonable time. translate resonable time to within 1 hour on a standard desktop computer. Say like: 3 Ghz Dual core, 4GB memory for a reference.

This is code golf, the shortest solution wins. The solution can be a fully working program or a function

\$\endgroup\$
  • \$\begingroup\$ What does rule 7 mean about "connecting"? Is this just a restatement of the rule 5 constraint that (my phrasing) prohibits the existence of a 2x2 blank square? \$\endgroup\$ – Peter Taylor Sep 20 '11 at 10:06
  • \$\begingroup\$ I am sorry about some restatements, but rule 7 is more of an restatement of rule 6 where it is stated that the shapes should be uniform. In other words rule 7 says that a single shape cannot be divided into 2 separate smaller shapes. \$\endgroup\$ – Plarsen Sep 20 '11 at 10:14
  • 6
    \$\begingroup\$ I've no intention of being mean, but this problem is by no way intriguing, interesting or showing any esthetically pleasing characteristic. it's just an abstract challenge and I don't see why anyone would have the necessary patience to even read all the rules, needless to say anything about solving it. good luck with your next one though! \$\endgroup\$ – Bogdan Alexandru Oct 1 '12 at 21:11
  • 1
    \$\begingroup\$ Clarification: the whitespace can form any shape as long as it separates the blocks and it contains no 2x2 block and no two consecutive whitespace blocks on the outer edge? \$\endgroup\$ – John Dvorak Jan 25 '13 at 21:37
  • 2
    \$\begingroup\$ This question is really tricky (or maybe I'm a poor problem solver)... do you have a solution yourself, Plarsen? Anyway, I think it would've been more interesting to drop the whitespace requirements and make it a code-challenge where the score depends on both the character count and the height of the block (thus making it beneficial to pack it a lot without making it a hard requirement). \$\endgroup\$ – FireFly Jan 19 '14 at 22:15
1
\$\begingroup\$

Haskell, 156

Well, this one stretches the rules a bit. I don't have any blankspace walls except for the linebreaks, therefore all my walls have a length of 1.

import Data.List
r=replicate
main=getLine>>=putStrLn.concatMap(\b->unlines$s(head$elemIndices b"0123456789abcdef")b)
s n c|n<9=[r n c,""]|True=r 8 c:s(n-8)c

output for 464fa6:

4444

666666

4444

ffffffff
fffffff

aaaaaaaa
aa

666666
\$\endgroup\$
  • \$\begingroup\$ Very, very close :) but rule 4 is not met, creating an imaginary rectangle of your output, you have more than 1 aligning whitespace in a row on the rightmost edge. \$\endgroup\$ – Plarsen Jan 19 '14 at 8:29
1
\$\begingroup\$

BrainF*ck - 134 (newline intr

>>+[++++++++++>,----------]>++++++[<+++++>-]<++[<]<++++++[>+++++<-]>++>-
>..<<.>>>..<<<.>>>>..<<<.<........>.>>>>..>>>.<<..>>.<..[<]>>.

I think that this is the simplist answer

Input taken via 6 hexadecimal characters to stdin, followed by a newline to submit.

EDIT: This fails due to rule 6, that I didn't fully realize until now :/

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.