Post History
Brachylog, 16 bytes g₂;.z∋zbᵗ×ᵐ/ℤ↰|w Try it online! This is a function submission, which inputs n from the left and A from the right (as a list of two-element lists). Output is to standard out...
#1: Initial revision
# [Brachylog], 16 bytes
g₂;.z∋zbᵗ×ᵐ/ℤ↰|w
[Try it online!][TIO-ks7xdgx9]
This is a function submission, which inputs *n* from the left and *A* from the right (as a list of two-element lists). Output is to standard output.
## Explanation
g₂;.z∋zbᵗ×ᵐ/ℤ↰|w
g₂ place two list wrappers around the left input
;. append the right input
z cycling zip; because the left input is length 1,
this pairs it with each element of the right input
∋ find {the first} element for which no assertions fail
[at this point, the element looks like [[n], [num, denom]]
for some pair [num, denom] in A]
z rearrange to [[n, num], [n, denom]]
bᵗ remove first of last pair ([[n, num], [denom]])
×ᵐ take product of each inner list ([n×num, denom])
/ℤ divide; assert result (n×num÷denom) is an integer
↰ recurse (loop back to start of program)
| if all else fails (i.e. ∋ found no elements)
w output the current value to standard output
[Brachylog]: https://github.com/JCumin/Brachylog
[TIO-ks7xdgx9]: https://tio.run/##SypKTM6ozMlPN/r/P/1RU5O1XtWjju6qpIdbpx@e/nDrBP1HLUsetW2oKf//39DA0szQ2NTc2Ph/dLS5hY6paaxOtKmOMZA01AGxDQ11jMBC5rGxAA "Brachylog – Try It Online"
