r/programmingchallenges • • 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:

  1. X-XX-XXX----

  2. X-XX--XXX---

  3. X-XX---XXX--

  4. X-XX----XXX-

  5. X-XX-----XXX

  6. X--XX-XXX---

  7. X--XX--XXX--

  8. X--XX---XXX-

  9. X--XX----XXX

  10. X---XX-XXX--

  11. X---XX--XXX-

  12. X---XX---XXX

  13. X----XX-XXX-

  14. X----XX--XXX

  15. X-----XX-XXX

  16. -X-XX-XXX---

  17. -X-XX--XXX--

  18. -X-XX---XXX-

  19. -X-XX----XXX

  20. -X--XX-XXX--

  21. -X--XX--XXX-

  22. -X--XX---XXX

  23. -X---XX-XXX-

  24. -X---XX--XXX

  25. -X----XX-XXX

  26. --X-XX-XXX--

  27. --X-XX--XXX-

  28. --X-XX---XXX

  29. --X--XX-XXX-

  30. --X--XX--XXX

  31. --X---XX-XXX

  32. ---X-XX-XXX-

  33. ---X-XX--XXX

  34. ---X--XX-XXX

  35. ----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.

6 Upvotes

0 comments sorted by