hi, is it possible to make a generator from a custom lazy sequence? For practice, I was trying to use test-check to test FizzBuzz problem - I want a generator that returns multiples of 3 but not of 5 or 15
gen/such-that would suffice here for casual use
but it gave up when I tried
Give it a higher max-tries, like 100
itโs help to invert your thinking for stuff like this
generate a number, then use fmap to multiply by 3 so you always generate multiples of 3
could then use such-that over that to exclude multiples of 5 if needed
Ok I had tried generate a number, then use fmap to multiply by 3 so you always generate multiples of 3
but didn't apply such-that to exclude multiples of 5, let me try, thank you for all replies!
yeah I forgot to say the multiply part
you could still use such-that without multiplying, it'd just be even slower and you'd probable need an even higher max-tries
if you want to be fancy you can use some number theory to generate a good distribution of such numbers w/o filtering
could get it to work! thank you!
you could gen a set of non-5 numbers, then multiply all of them and by 3 to generate only numbers divisible by 3 but not 5 :)
@alexmiller that's just moving the filtering to the first generator, right?
yeah
the fancy thing I have in mind is basically (gen/let [fifteens gen/int, threes (gen/choose 1 4)] (+ (* 15 fifteens) (* 3 threes)))
I think that'd work