# Print the positive non-zero integer n-tuple(s) that solve an inequality within a bound

Suppose I have a linear inequality like

x0A0 + x1A1 + ... + xnAn <= C

with xi a non-zero positive integer and Ai and C a positive non-zero multiple of 0.01. Find all the positive integer n-tuples {x1,...,xn} such that:

D <= x0A0 + x1A1 + ... + xnAn <= C

where D is also a positive non-zero multiple of 0.01.

Challenge: Find the shortest code to produce the n-tuple solution(s) for any Ai, C, D.

Example: Let A0,A1=1, C = 2.5, and D=1.5. This gives

1.5 <= x01+x11 <= 2.5

Here, the (only) 2-tuple solution is {1,1}:

• Why not simply multiply the equations by 100 and have everything in terms of integers ? The multiples of 0.01 don't add anything – Ton Hospel Mar 14 '18 at 7:13
• Welcome to PPCG! I think this challenge has potential but needs some clarifications. Do I understand correctly that the program takes C, D and a vector A as input and then should return all vectors X? Adding some examples and test cases would also help to understand the challenge. – Laikoni Mar 14 '18 at 9:31
• Also, what are the y and z vectors? – user202729 Mar 14 '18 at 9:34
• @user202729 He means other solution tuples, they aren't extra variables – Ton Hospel Mar 14 '18 at 12:00
• This made enough sense to me. linkTIO – Kelly Lowder Mar 14 '18 at 19:08

(d#c)a=[x|x<-mapM(\_->[1..c])a,y<-[sum$zipWith(*)x a],y>=d,y<=c]  Try it online! Defines a funktion (#) which takes D as first argument, C as second argument and A as a list as last argument and returns a list of possible X as lists. E.g. (#) 1.5 3.5 [1,1] yields the three solutions [[1.0,1.0],[1.0,2.0],[2.0,1.0]]. ### 61 bytes with D and C integers: (d#c)a=[x|x<-mapM(\_->[1..c])a,elem(sum$zipWith(*)x a)[d..c]]

Try it online! E.g. (#) 2 5 [1,1,2] yields [[1,1,1],[1,2,1],[2,1,1]].
• @twoblacklinesinthemiddle I miss read your question before. In the first program the resulting value for a tuple x is y, so you can return (x,y) instead of just x: Try it online! – Laikoni Mar 15 '18 at 9:21