r/dailyprogrammer • u/fvandepitte 0 0 • Jan 25 '16
[2016-01-25] Challenge #251 [Easy] Create Nonogram description
Description
This week we are doing a challenge involving Nonograms
It is going to be a three parter:
- Create Nonogram description ([Easy])
- Solve Nonogram ([Intermediate/Hard])
- Working with multiple colors/characters ([Hard])
- Bonus: Make it an interactive game ([Intermediate])
What is a Nonogram?
Nonograms, also known as Hanjie, Picross or Griddlers, are picture logic puzzles in which cells in a grid must be colored or left blank according to numbers at the side of the grid to reveal a hidden picture. In this puzzle type, the numbers are a form of discrete tomography that measures how many unbroken lines of filled-in squares there are in any given row or column.
In a Nonogram you are given the number of elements in the rows and columns. A row/column where containing no element has a '0' all other rows/columns will have at least one number.
Each number in a row/column represent sets of elements next to each other.
If a row/column have multiple sets, the declaration of that row/column will have multiple numbers. These sets will always be at least 1 cell apart.
An example
| 2 | 1 | 1 | ||||
|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 2 | 1 | ||
| 2 | * | * | ||||
| 1 | 2 | * | * | * | ||
| 0 | ||||||
| 2 | 1 | * | * | * | ||
| 2 | * | * |
Formal Inputs & Outputs
Input description
Today you will recieve an image in ASCII with ' ' being empty and '*' being full. The number of rows and columns will always be a multiple of 5.
*
**
* *
* *
*****
Output description
Give the columns and rows for the input
Columns:
1 1
1 2 1 1 5
Rows:
1
2
1 1
1 1
5
Ins
1
*
**
* *
* *
*****
2
** *
*****
******
********
**********
* *
* ** * *
* ** * *
* ** *
********
3
***
**** **
****** ******
* **** ** *
****** *** **
****** *******
****** ********
* **********
* **********
* **********
* * **** ****
*** **** ****
**** ****
**** ****
**** ****
Bonus
Place the columns and rows in a grid like you would give to a puzzler
1 1
1 2 1 1 5
1
2
1 1
1 1
5
Finally
Have a good challenge idea?
Consider submitting it to /r/dailyprogrammer_ideas
7
u/Godspiral 3 3 Jan 25 '16 edited Jan 25 '16
In J,
fancy formatted version
6
u/TheBlackCat13 Jan 25 '16 edited Jan 25 '16
Here is my code for Python 3.x, with bonus:
And my solutions:
Edit: bug fixed
3
u/fvandepitte 0 0 Jan 25 '16
My submission in Haskell
In
Out
1
u/jjrobinson-github Jan 26 '16
Are the columns / rows of numbers in order they are encountered from top to bottom & left to right? Problem didn't specify, but all the examples seem to demonstrate that behavior.
3
u/casualfrog Jan 25 '16
JavaScript (no bonus):
3
u/Eggbert345 Jan 26 '16
JavaScript solution. Includes bonus, although it gets a little messed up when there are values > 9. I also had it print the puzzle itself.
I'm starting a new job soon that uses exclusively Node, so I'm trying to get better at JS. Any feedback is welcome.
3
u/Sirflankalot 0 1 Jan 28 '16 edited Jan 31 '16
C++11
A small solution that takes the filename as an argument and prints the headers and the image.
It doesn't handle numbers above 9 well and it throws it off. Not sure how to deal with that currently.Edit: thanks to /u/Iislsdum for the formatting help. Any help would be appreciated.Edit: Thanks to
2
u/EliteMasterEric Jan 25 '16
Hey, this is my first time here, I decided to throw together my solution to this in Python 3.x.
I managed to get it to work with the bonus challenge! What do you guys think? Any places where I can improve?
Output:
2
u/cook447 Jan 25 '16 edited Jan 25 '16
Solution in Java, no bonus yet .
Input
Output
2 digit numbers don't format nicely in the output but I might fix that later.
EDIT: It looks as if I don't really understand reddit's formatting so the input and output don't appear right. EDIT2: Fixed the formatting.
2
u/hyrulia Jan 25 '16 edited Jan 25 '16
Python3.5
output
2
u/regul Jan 26 '16
Python 2.7, using regexes
Bonus (using tabs because pretty-printing is a pain):
2
u/a_ctor Jan 26 '16 edited Jan 26 '16
In C#, 1593 chars - 1 line (with bonus & drawing the result)
Output:
1
u/downiedowndown Jan 25 '16
Swift 2 Learned about the
preconditionstatement today and this proved really useful here when parsing the input in the playground.1
u/Specter_Terrasbane Jan 26 '16
Python 2.7, with bonus:
Outputs
1
u/[deleted] Jan 26 '16 edited Jan 26 '16
c#
bonus output:
1
u/Minolwa Jan 26 '16
I thought I'd go all out on this one since it's going to be a weeklong challenge. I've created a github repository for a nonogram application.
Java solution:
https://github.com/ndsmith3/NonogramApp
Outputs:
Triangle:
House:
Elephant (formatting errors):
Elephant (hand-fixed):
I've been having some formatting issues (particularly on the elephant output), and would appreciate any and all feedback. Thanks!
1
u/saila456 Jan 26 '16
Lua just started to learn. in This solution id did not really care much bout the output formatting.
Output:
1
u/FrankRuben27 0 1 Jan 26 '16
In Python 2, w/ bonus:
1
u/[deleted] Jan 27 '16
R
Hey! I'm a statistician and I wanted to get better at R, so I decided to practice it for general purpose programming. Hacked together a solution that complies with the bonus specification!
Advice is always appreciated!
Input:
Prints out: from RStudio
1
u/fibonacci__ 1 0 Jan 30 '16
Python
Output
1
u/Iislsdum Jan 31 '16
C++ with bonus
I am just beginning to learn C++ (coming from Java), so feedback is encouraged!
Output 1:
Output 2:
Output 3:
1
u/pyThat Feb 01 '16
Go solution.
1
u/[deleted] Feb 03 '16
Python3
I didn't know if I was going to post this so some comments might be wierd.
Result:
0
u/[deleted] Jan 26 '16
[deleted] — view deleted comment
0
u/[deleted] Jan 25 '16
[deleted] — view deleted comment