Create a X discount for every Nth product from the same category I know this is pretty complex task, I don't expect a solution, but a guide on where to start.

(Drupal 7 is in question)

I need to apply X% discount for every Nth products that are in the same category. Category, X and N needs to be imputed by user.

So far, I was able to make a rule (with fixed X, N and category) that calculates a needed total discount that needs to be subtracted from total amount.
How can I apply that number (or should I do something different?), and how to get user's input for X, N and category?

Thank you for any help.
Depending on how you've constructed your product data model, the Per-quantity category discount (% off) offer type supplied by the Commerce Discount Extra module should just work. It lets you specify how many products of which product category must be present on an order before the next one is discounted by any percentage (e.g. buy 2, get 1 free - 100% off). It's repeatable, meaning you can apply the discount any number of times on the same order so long as the right quantity is present, and you have some rudimentary sorting options - e.g. discount the cheapest or most expensive first.

If that solves it for ya, mark this answer as accepted. If you need a little more detail, feel free to add a comment and I'll help if I can. : )