Skip to main content
Commonmark migration
Source Link

#PowerShell, 35 Bytes

PowerShell, 35 Bytes

param($a)$a-match'^(?!(..+)\1+$)..' 

Uses the same regex from Martin's Retina answer, as that's way shorter than anything that will wind up using the [math]:: libraries one would normally use. Expects input as command-line argument in unary format.

Corrected from initial version (which was apparently specific to the particular PowerShell implementation I coded it on) thanks to Jonathan Leech-Pepin. Grr undocumented version differences.

Examples:

PS C:\Tools\Scripts\golfing> .\is-this-number-a-prime.ps1 111111 False PS C:\Tools\Scripts\golfing> .\is-this-number-a-prime.ps1 1111111 True 

###Bonus - PowerShell pipeline input, 29 Bytes

Bonus - PowerShell pipeline input, 29 Bytes

%{$_-match'^(?!(..+)\1+$)..'} 

Same as the above, just called differently, which shaves bytes. For example,

PS C:\Tools\Scripts\golfing> 111111 | %{$_-match'^(?!(..+)\1+$)..'} False 

#PowerShell, 35 Bytes

param($a)$a-match'^(?!(..+)\1+$)..' 

Uses the same regex from Martin's Retina answer, as that's way shorter than anything that will wind up using the [math]:: libraries one would normally use. Expects input as command-line argument in unary format.

Corrected from initial version (which was apparently specific to the particular PowerShell implementation I coded it on) thanks to Jonathan Leech-Pepin. Grr undocumented version differences.

Examples:

PS C:\Tools\Scripts\golfing> .\is-this-number-a-prime.ps1 111111 False PS C:\Tools\Scripts\golfing> .\is-this-number-a-prime.ps1 1111111 True 

###Bonus - PowerShell pipeline input, 29 Bytes

%{$_-match'^(?!(..+)\1+$)..'} 

Same as the above, just called differently, which shaves bytes. For example,

PS C:\Tools\Scripts\golfing> 111111 | %{$_-match'^(?!(..+)\1+$)..'} False 

PowerShell, 35 Bytes

param($a)$a-match'^(?!(..+)\1+$)..' 

Uses the same regex from Martin's Retina answer, as that's way shorter than anything that will wind up using the [math]:: libraries one would normally use. Expects input as command-line argument in unary format.

Corrected from initial version (which was apparently specific to the particular PowerShell implementation I coded it on) thanks to Jonathan Leech-Pepin. Grr undocumented version differences.

Examples:

PS C:\Tools\Scripts\golfing> .\is-this-number-a-prime.ps1 111111 False PS C:\Tools\Scripts\golfing> .\is-this-number-a-prime.ps1 1111111 True 

Bonus - PowerShell pipeline input, 29 Bytes

%{$_-match'^(?!(..+)\1+$)..'} 

Same as the above, just called differently, which shaves bytes. For example,

PS C:\Tools\Scripts\golfing> 111111 | %{$_-match'^(?!(..+)\1+$)..'} False 
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

#PowerShell, 35 Bytes

param($a)$a-match'^(?!(..+)\1+$)..' 

Uses the same regex from Martin's Retina answerRetina answer, as that's way shorter than anything that will wind up using the [math]:: libraries one would normally use. Expects input as command-line argument in unary format.

Corrected from initial version (which was apparently specific to the particular PowerShell implementation I coded it on) thanks to Jonathan Leech-PepinJonathan Leech-Pepin. Grr undocumented version differences.

Examples:

PS C:\Tools\Scripts\golfing> .\is-this-number-a-prime.ps1 111111 False PS C:\Tools\Scripts\golfing> .\is-this-number-a-prime.ps1 1111111 True 

###Bonus - PowerShell pipeline input, 29 Bytes

%{$_-match'^(?!(..+)\1+$)..'} 

Same as the above, just called differently, which shaves bytes. For example,

PS C:\Tools\Scripts\golfing> 111111 | %{$_-match'^(?!(..+)\1+$)..'} False 

#PowerShell, 35 Bytes

param($a)$a-match'^(?!(..+)\1+$)..' 

Uses the same regex from Martin's Retina answer, as that's way shorter than anything that will wind up using the [math]:: libraries one would normally use. Expects input as command-line argument in unary format.

Corrected from initial version (which was apparently specific to the particular PowerShell implementation I coded it on) thanks to Jonathan Leech-Pepin. Grr undocumented version differences.

Examples:

PS C:\Tools\Scripts\golfing> .\is-this-number-a-prime.ps1 111111 False PS C:\Tools\Scripts\golfing> .\is-this-number-a-prime.ps1 1111111 True 

###Bonus - PowerShell pipeline input, 29 Bytes

%{$_-match'^(?!(..+)\1+$)..'} 

Same as the above, just called differently, which shaves bytes. For example,

PS C:\Tools\Scripts\golfing> 111111 | %{$_-match'^(?!(..+)\1+$)..'} False 

#PowerShell, 35 Bytes

param($a)$a-match'^(?!(..+)\1+$)..' 

Uses the same regex from Martin's Retina answer, as that's way shorter than anything that will wind up using the [math]:: libraries one would normally use. Expects input as command-line argument in unary format.

Corrected from initial version (which was apparently specific to the particular PowerShell implementation I coded it on) thanks to Jonathan Leech-Pepin. Grr undocumented version differences.

Examples:

PS C:\Tools\Scripts\golfing> .\is-this-number-a-prime.ps1 111111 False PS C:\Tools\Scripts\golfing> .\is-this-number-a-prime.ps1 1111111 True 

###Bonus - PowerShell pipeline input, 29 Bytes

%{$_-match'^(?!(..+)\1+$)..'} 

Same as the above, just called differently, which shaves bytes. For example,

PS C:\Tools\Scripts\golfing> 111111 | %{$_-match'^(?!(..+)\1+$)..'} False 
Corrected functionality
Source Link
AdmBorkBork
  • 43.7k
  • 5
  • 107
  • 288

#PowerShell, 35 Bytes

[bool]$argsparam($a)$a-match'^(?!(..+)\1+$)..' 

Uses the same regex from Martin's Retina answer, as that's way shorter than anything that will wind up using the [math]:: libraries one would normally use. Expects input as command-line argument in unary format. Explicitly casts as a [bool] to return appropriate truthy/falsey value

Corrected from initial version (otherwise this would returnwhich was apparently specific to the literal string if true, and nothing if falseparticular PowerShell implementation I coded it on) thanks to Jonathan Leech-Pepin. Grr undocumented version differences.

Examples:

PS C:\Tools\Scripts\golfing> .\is-this-number-a-prime.ps1 111111 False PS C:\Tools\Scripts\golfing> .\is-this-number-a-prime.ps1 1111111 True 

###Bonus - PowerShell pipeline input, 29 Bytes

%{$_-match'^(?!(..+)\1+$)..'} 

Same as the above, just called differently, which shaves bytes. For example,

PS C:\Tools\Scripts\golfing> 111111 | %{$_-match'^(?!(..+)\1+$)..'} False 

#PowerShell, 35 Bytes

[bool]$args-match'^(?!(..+)\1+$)..' 

Uses the same regex from Martin's Retina answer, as that's way shorter than anything that will wind up using the [math]:: libraries one would normally use. Expects input as command-line argument in unary format. Explicitly casts as a [bool] to return appropriate truthy/falsey value (otherwise this would return the literal string if true, and nothing if false).

Examples:

PS C:\Tools\Scripts\golfing> .\is-this-number-a-prime.ps1 111111 False PS C:\Tools\Scripts\golfing> .\is-this-number-a-prime.ps1 1111111 True 

###Bonus - PowerShell pipeline input, 29 Bytes

%{$_-match'^(?!(..+)\1+$)..'} 

Same as the above, just called differently, which shaves bytes. For example,

PS C:\Tools\Scripts\golfing> 111111 | %{$_-match'^(?!(..+)\1+$)..'} False 

#PowerShell, 35 Bytes

param($a)$a-match'^(?!(..+)\1+$)..' 

Uses the same regex from Martin's Retina answer, as that's way shorter than anything that will wind up using the [math]:: libraries one would normally use. Expects input as command-line argument in unary format.

Corrected from initial version (which was apparently specific to the particular PowerShell implementation I coded it on) thanks to Jonathan Leech-Pepin. Grr undocumented version differences.

Examples:

PS C:\Tools\Scripts\golfing> .\is-this-number-a-prime.ps1 111111 False PS C:\Tools\Scripts\golfing> .\is-this-number-a-prime.ps1 1111111 True 

###Bonus - PowerShell pipeline input, 29 Bytes

%{$_-match'^(?!(..+)\1+$)..'} 

Same as the above, just called differently, which shaves bytes. For example,

PS C:\Tools\Scripts\golfing> 111111 | %{$_-match'^(?!(..+)\1+$)..'} False 
Source Link
AdmBorkBork
  • 43.7k
  • 5
  • 107
  • 288
Loading