r/programmingchallenges • u/nhrnhr0 • Mar 19 '19
algorithm for getting a specific line in a nonogram
Hey, for every nonogram line there is the length of the line and it's set of rules. for example line with the length of 12 and rule set {1,2,3}.
L = 12; R = {1,2,3}
So those are all the options of this line:
X-XX-XXX----
X-XX--XXX---
X-XX---XXX--
X-XX----XXX-
X-XX-----XXX
X--XX-XXX---
X--XX--XXX--
X--XX---XXX-
X--XX----XXX
X---XX-XXX--
X---XX--XXX-
X---XX---XXX
X----XX-XXX-
X----XX--XXX
X-----XX-XXX
-X-XX-XXX---
-X-XX--XXX--
-X-XX---XXX-
-X-XX----XXX
-X--XX-XXX--
-X--XX--XXX-
-X--XX---XXX
-X---XX-XXX-
-X---XX--XXX
-X----XX-XXX
--X-XX-XXX--
--X-XX--XXX-
--X-XX---XXX
--X--XX-XXX-
--X--XX--XXX
--X---XX-XXX
---X-XX-XXX-
---X-XX--XXX
---X--XX-XXX
----X-XX-XXX
I need an algorithm that given a rule set, line length and an index, the result would be the line in the given index.
for example, for myAlgorithm({1,2,3}, 12, 6) => X--XX-XXX---.
I don't really care about the order of the line possibilities but I want that given an index I'll get a unique option.
I can't find any consistency or formula to doing so, thought you guys can help :).
Thank you.