Skip to main content
fixed bug, same length
Source Link

Perl 6, 35 bytes

{$_+=($*=-1**$++*$++until1)*$++until .is-prime;$_}

Try it online!

This uses Veitcel's technique for generating the list of 0, -1, 2, -3 but simplifies it greatly to ($*=-1)*$++ using the anonymous state variables available in P6 (I originally had -1 ** $++ * $++ using, but when golfed the anonymous state variables available in P6negative loses precedence). There's a built in prime checker but unfortunately the until prevents the automagically returned value so there's an extra $_ hanging around.

Try it online!

Perl 6, 35 bytes

{$_+=-1**$++*$++until .is-prime;$_}

This uses Veitcel's technique for generating the list of 0, -1, 2, -3 but simplifies it greatly to -1 ** $++ * $++ using the anonymous state variables available in P6. There's a built in prime checker but unfortunately the until prevents the automagically returned value so there's an extra $_ hanging around.

Try it online!

Perl 6, 35 bytes

{$_+=($*=-1)*$++until .is-prime;$_}

Try it online!

This uses Veitcel's technique for generating the list of 0, -1, 2, -3 but simplifies it greatly to ($*=-1)*$++ using the anonymous state variables available in P6 (I originally had -1 ** $++ * $++, but when golfed the negative loses precedence). There's a built in prime checker but unfortunately the until prevents the automagically returned value so there's an extra $_ hanging around.

Source Link

Perl 6, 35 bytes

{$_+=-1**$++*$++until .is-prime;$_}

This uses Veitcel's technique for generating the list of 0, -1, 2, -3 but simplifies it greatly to -1 ** $++ * $++ using the anonymous state variables available in P6. There's a built in prime checker but unfortunately the until prevents the automagically returned value so there's an extra $_ hanging around.

Try it online!