Powershell, 89 bytes
"$args"-notmatch'(.)(.*)(.)'-or(($m=$Matches).1-ge$m.3-and(.\g(''+(+$m.1+$m.3)%10+$m.2)))
Important! The script calls itself recursively. So save the script as g.ps1
file in the current directory. Also you can call a script block variable instead script file (see the test script below). That calls has same length.
Note 1: The script uses a lazy evaluation of logic operators -or
and -and
. If "$args"-notmatch'(.)(.*)(.)'
is True
then the right subexpression of -or
is not evaluated. Also if ($m=$Matches).1-ge$m.3
is False
then the right subexpression of -and
is not evaluated too. So we avoid infinite recursion.
Note 2: The regular expression '(.)(.*)(.)'
does not contain start and end anchors because the expression (.*)
is greedy by default.
Test script
$g={
"$args"-notmatch'(.)(.*)(.)'-or(($m=$Matches).1-ge$m.3-and(&$g(''+(+$m.1+$m.3)%10+$m.2)))
}
@(
,(2632, $true)
,(92258, $true)
,(60282, $true)
,(38410, $true)
,(3210, $true)
,(2302, $true)
,(2742, $true)
,(8628, $true)
,(6793, $true)
,(1, $true)
,(2, $true)
,(10, $true)
,(100, $true)
,(55, $true)
,(121, $true)
,(6724, $false)
,(47, $false)
,(472, $false)
,(60247, $false)
,(33265, $false)
,(79350, $false)
,(83147, $false)
,(93101, $false)
,(57088, $false)
,(69513, $false)
,(62738, $false)
,(54754, $false)
,(23931, $false)
,(7164, $false)
,(5289, $false)
,(3435, $false)
,(3949, $false)
,(8630, $false)
,(5018, $false)
,(6715, $false)
,(340, $false)
,(2194, $false)
) | %{
$n,$expected = $_
#$result = .\g $n # uncomment this line to call a script file g.ps1
$result = &$g $n # uncomment this line to call a script block variable $g
# the script block call and the script file call has same length
"$($result-eq-$expected): $result <- $n"
}
Output:
True: True <- 2632
True: True <- 92258
True: True <- 60282
True: True <- 38410
True: True <- 3210
True: True <- 2302
True: True <- 2742
True: True <- 8628
True: True <- 6793
True: True <- 1
True: True <- 2
True: True <- 10
True: True <- 100
True: True <- 55
True: True <- 121
True: False <- 6724
True: False <- 47
True: False <- 472
True: False <- 60247
True: False <- 33265
True: False <- 79350
True: False <- 83147
True: False <- 93101
True: False <- 57088
True: False <- 69513
True: False <- 62738
True: False <- 54754
True: False <- 23931
True: False <- 7164
True: False <- 5289
True: False <- 3435
True: False <- 3949
True: False <- 8630
True: False <- 5018
True: False <- 6715
True: False <- 340
True: False <- 2194
Powershell, 90 bytes
No recursion. No file name dependency and no script block name dependency.
for($s="$args";$s[1]-and$s-ge$s%10){$s=''+(2+$s[0]+$s)%10+($s|% S*g 1($s.Length-2))}!$s[1]
A Powershell implicitly converts a right operand to a type of a left operand. Therefore, $s-ge$s%10
calculates right operand $s%10
as integer
and compare it as a string
because type of the left operand is string
. And 2+$s[0]+$s
converts a char $s[0]
and string $s
to integer
because left operand 2
is integer.
$s|% S*g 1($s.Length-2)
is a shortcut to $s.Substring(1,($s.Length-2))