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

replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

PowerShell v2+, (削除) 108 (削除ここまで) 99 bytes

Ooof. The lack of any sort of built-in prime calculation/checking really hurts here.

param($n)for(){for(;'1'*++$i-match'^(?!(..+)1円+$)..'){if("$i"-like"*$n*"){if(++$o-eq$n){$i;exit}}}}

Takes input $n, enters an infinite for() loop. Each iteration, we use a for loop wrapped around the PowerShell regex prime checker PowerShell regex prime checker (h/t to Martin) to turn it into a prime generator by incrementing $i each time through the loop. (For example, running just for(){for(;'1'*++$i-match'^(?!(..+)1円+$)..'){$i}} will output 2, 3, 5, 7... separated by newlines).

Then a simple -like check to see if $n is somewhere in $i, and increment our counter $o. If we've reached where $n and $o are equal, output $i and exit. Otherwise we continue through the for to find the next prime and the process repeats.

PowerShell v2+, (削除) 108 (削除ここまで) 99 bytes

Ooof. The lack of any sort of built-in prime calculation/checking really hurts here.

param($n)for(){for(;'1'*++$i-match'^(?!(..+)1円+$)..'){if("$i"-like"*$n*"){if(++$o-eq$n){$i;exit}}}}

Takes input $n, enters an infinite for() loop. Each iteration, we use a for loop wrapped around the PowerShell regex prime checker (h/t to Martin) to turn it into a prime generator by incrementing $i each time through the loop. (For example, running just for(){for(;'1'*++$i-match'^(?!(..+)1円+$)..'){$i}} will output 2, 3, 5, 7... separated by newlines).

Then a simple -like check to see if $n is somewhere in $i, and increment our counter $o. If we've reached where $n and $o are equal, output $i and exit. Otherwise we continue through the for to find the next prime and the process repeats.

PowerShell v2+, (削除) 108 (削除ここまで) 99 bytes

Ooof. The lack of any sort of built-in prime calculation/checking really hurts here.

param($n)for(){for(;'1'*++$i-match'^(?!(..+)1円+$)..'){if("$i"-like"*$n*"){if(++$o-eq$n){$i;exit}}}}

Takes input $n, enters an infinite for() loop. Each iteration, we use a for loop wrapped around the PowerShell regex prime checker (h/t to Martin) to turn it into a prime generator by incrementing $i each time through the loop. (For example, running just for(){for(;'1'*++$i-match'^(?!(..+)1円+$)..'){$i}} will output 2, 3, 5, 7... separated by newlines).

Then a simple -like check to see if $n is somewhere in $i, and increment our counter $o. If we've reached where $n and $o are equal, output $i and exit. Otherwise we continue through the for to find the next prime and the process repeats.

Saved 9 bytes by swapping the while for a for and indexof for like
Source Link
AdmBorkBork
  • 43.7k
  • 5
  • 107
  • 288

PowerShell v2+, 108(削除) 108 (削除ここまで) 99 bytes

Ooof. The lack of any sort of built-in prime calculation/checking really hurts here.

param($n)for(){whilefor('1'*++$i;'1'*++$i-notmatch'^match'^(?!(..+)1円+$)..'){}if("$i".indexof("$n")+1-like"*$n*"){if(++$o-eq$n){$i;exit}}}}

Takes input $n, enters an infinite for() loop. Each iteration, we use a whilefor loop wrapped around the PowerShell regex prime checker (h/t to Martin) to turn it into a prime generator by incrementing $i each time through the whileloop. (For example, running just for(){whilefor('1'*++$i;'1'*++$i-notmatch'^match'^(?!(..+)1円+$)..'){}$i}} will output 2, 3, 5, 7... separated by newlines).

Then a simple .indexOf()-like check to see if $n is somewhere in $i, and increment our counter $o. If we've reached where $n and $o are equal, output $i and exit. Otherwise we continue through the for to find the next prime via the while and the process repeats.

PowerShell v2+, 108 bytes

Ooof. The lack of any sort of built-in prime calculation/checking really hurts here.

param($n)for(){while('1'*++$i-notmatch'^(?!(..+)1円+$)..'){}if("$i".indexof("$n")+1){if(++$o-eq$n){$i;exit}}}

Takes input $n, enters an infinite for() loop. Each iteration, we use a while loop wrapped around the PowerShell regex prime checker (h/t to Martin) to turn it into a prime generator by incrementing $i each time through the while. (For example, running just for(){while('1'*++$i-notmatch'^(?!(..+)1円+$)..'){}$i} will output 2, 3, 5, 7... separated by newlines).

Then a simple .indexOf() check to see if $n is somewhere in $i, and increment our counter $o. If we've reached where $n and $o are equal, output $i and exit. Otherwise we continue through the for to find the next prime via the while and the process repeats.

PowerShell v2+, (削除) 108 (削除ここまで) 99 bytes

Ooof. The lack of any sort of built-in prime calculation/checking really hurts here.

param($n)for(){for(;'1'*++$i-match'^(?!(..+)1円+$)..'){if("$i"-like"*$n*"){if(++$o-eq$n){$i;exit}}}}

Takes input $n, enters an infinite for() loop. Each iteration, we use a for loop wrapped around the PowerShell regex prime checker (h/t to Martin) to turn it into a prime generator by incrementing $i each time through the loop. (For example, running just for(){for(;'1'*++$i-match'^(?!(..+)1円+$)..'){$i}} will output 2, 3, 5, 7... separated by newlines).

Then a simple -like check to see if $n is somewhere in $i, and increment our counter $o. If we've reached where $n and $o are equal, output $i and exit. Otherwise we continue through the for to find the next prime and the process repeats.

Source Link
AdmBorkBork
  • 43.7k
  • 5
  • 107
  • 288

PowerShell v2+, 108 bytes

Ooof. The lack of any sort of built-in prime calculation/checking really hurts here.

param($n)for(){while('1'*++$i-notmatch'^(?!(..+)1円+$)..'){}if("$i".indexof("$n")+1){if(++$o-eq$n){$i;exit}}}

Takes input $n, enters an infinite for() loop. Each iteration, we use a while loop wrapped around the PowerShell regex prime checker (h/t to Martin) to turn it into a prime generator by incrementing $i each time through the while. (For example, running just for(){while('1'*++$i-notmatch'^(?!(..+)1円+$)..'){}$i} will output 2, 3, 5, 7... separated by newlines).

Then a simple .indexOf() check to see if $n is somewhere in $i, and increment our counter $o. If we've reached where $n and $o are equal, output $i and exit. Otherwise we continue through the for to find the next prime via the while and the process repeats.

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