The modulus validation
Jelly, 7 bytes
%⁼⁴
0ç#
This is a full program. Arguments are divisors, target moduli, and number of solutions, in that order.
Try it online!
How it works
0ç# Main link.
Left argument: D (array of divisors)
Right argument: M (array of target moduli)
Third argument: n (number of solutions)
0ç# Execute the helper link with k = 0, 1, 2, ... as left argument and D as the
right one until n of them return 1. Yield the array of matches.
%⁼⁴ Helper link. Left argument: k. Right argument: D
% Compute k % d for each d in D.
⁼⁴ Compare the result with M.
JavaScript (ES6), 74 70 69 bytes
Takes input as an integer n
and an array a
of [modulo, remainder]
arrays with currying syntax (n)(a)
.
n=>a=>eval('for(i=r=[];a.some(([b,c])=>i%b-c)||--n*r.push(i);i++);r')
Test cases
let f =
n=>a=>eval('for(i=r=[];a.some(([b,c])=>i%b-c)||--n*r.push(i);i++);r')
console.log(f(5)([[3, 2], [4, 1], [5, 3]]))
console.log(f(3)([[8, 0], [13, 3], [14, 8]]))
Perl 6, 33 bytes
{grep((*X%@^b)eqv@^c,0..*)[^$^a]}
Try it
The input is ( number-of-values, list-of-divisors, list-of-remainders )
Expanded:
{ # bare block lambda with placeholder parameters 「$a」 「@b」 「@c」
grep(
# WhateverCode lambda:
(
* # the value being tested
X% # cross modulus
@^b # with the divisors ( second parameter )
)
eqv # is that list equivalent with
@^c # the expected remainders ( third parameter )
# end of WhateverCode lambda
,
0 .. * # Range of all Integers starting with 0
)[ ^$^a ] # grab up-to 「$a」 values ( first parameter )
# ( 「^$a」 is the same as 「0 ..^ $a」 )
}