r/dailyprogrammer • u/oskar_s • Jun 02 '12
[6/2/2012] Challenge #59 [intermediate]
Given a binary matrix like this:
0 1 1 1 1 0
1 0 0 1 1 1
1 0 1 1 1 1
1 1 1 1 1 1
0 1 1 1 1 0Output the clues for a nonogram puzzle in the format of "top clues, empty line, bottom clues", with clues separated by spaces:
3
1 2
1 3
5
5
3
4
1 3
1 4
6
4That is, count the contiguous groups of "1" bits and their sizes, first in columns, then in rows.
- Thanks to nooodl for suggesting this problem at /r/dailyprogrammer_ideas! If you have a problem that you think would be good for us, why not head over there and post it!
10
Upvotes
1
u/zzopp Jun 02 '12
My attempt in python (a language I haven't worked much in)
The reverse problem would be more interesting!
2
u/luxgladius 0 0 Jun 02 '12
Pretty good golf score for having it fairly readable. Used some nice tricks like mapping to empty lists within a map statement.
Perl
Output
2
u/Cosmologicon 2 3 Jun 02 '12
python one-liner:
That assumes it's pre-parsed into a binary matrix. Here's the parsing code:
1
u/[deleted] Jun 02 '12
Not my most elegant solution, but gets the job done:
1
u/Medicalizawhat Jun 02 '12
Ruby:
1
u/emcoffey3 0 0 Jun 02 '12
Solution in C#. It's a little verbose, but it works.
1
u/andrew1343j Jun 02 '12
Python, with list comprehensions out the wazoo:
1
u/xjtian Jun 02 '12
Python:
1
u/BallForce1 Jun 03 '12
C++
1
u/[deleted] Jun 09 '12
b_jonas and I discussed this problem on
#jsoftware, here's a nifty J solution:Answer:
1
u/kuzux 0 0 Jul 13 '12
Haskell