Skip to main content
2 of 4
Corrected functionality
AdmBorkBork
  • 43.7k
  • 5
  • 107
  • 288

#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 
AdmBorkBork
  • 43.7k
  • 5
  • 107
  • 288