Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 14 characters in body
Source Link
Jo King
  • 48.1k
  • 6
  • 130
  • 187

Perl 6, 36 - 50 = -14 points

{$^a;first {/$a/&&$_%%one ^$_},2..*}

Try it online!

Considering $_%%one ^$_ is the only 2 bytes smaller(削除) smaller (削除ここまで) larger than .is-prime, I think it's worth it for the bonus. This times out for the last test case.

Explanation:

{ } # Anonymous code block
 $^a; # Assign input to $a
 first ,2..* # Find the first number
 { } # Which
 /$a/ # Contains the input
 && # And
 $_%%one ^$_ # Is prime

Perl 6, 36 - 50 = -14 points

{$^a;first {/$a/&&$_%%one ^$_},2..*}

Try it online!

Considering $_%%one ^$_ is the only 2 bytes smaller than .is-prime, I think it's worth it for the bonus. This times out for the last test case.

Explanation:

{ } # Anonymous code block
 $^a; # Assign input to $a
 first ,2..* # Find the first number
 { } # Which
 /$a/ # Contains the input
 && # And
 $_%%one ^$_ # Is prime

Perl 6, 36 - 50 = -14 points

{$^a;first {/$a/&&$_%%one ^$_},2..*}

Try it online!

Considering $_%%one ^$_ is the only 2 bytes (削除) smaller (削除ここまで) larger than .is-prime, I think it's worth it for the bonus. This times out for the last test case.

Explanation:

{ } # Anonymous code block
 $^a; # Assign input to $a
 first ,2..* # Find the first number
 { } # Which
 /$a/ # Contains the input
 && # And
 $_%%one ^$_ # Is prime
Source Link
Jo King
  • 48.1k
  • 6
  • 130
  • 187

Perl 6, 36 - 50 = -14 points

{$^a;first {/$a/&&$_%%one ^$_},2..*}

Try it online!

Considering $_%%one ^$_ is the only 2 bytes smaller than .is-prime, I think it's worth it for the bonus. This times out for the last test case.

Explanation:

{ } # Anonymous code block
 $^a; # Assign input to $a
 first ,2..* # Find the first number
 { } # Which
 /$a/ # Contains the input
 && # And
 $_%%one ^$_ # Is prime

AltStyle によって変換されたページ (->オリジナル) /