Skip to main content
no recursive alternative added.
Source Link
mazzy
  • 7.2k
  • 2
  • 13
  • 23

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))


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))

added 13 characters in body
Source Link
mazzy
  • 7.2k
  • 2
  • 13
  • 23

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 with same bytes instead script file (see the test script below). That calls has same length.

$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 byteslength "$($result-eq-$expected): $result <- $n" } 

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 with same bytes instead script file (see the test script below).

$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 bytes "$($result-eq-$expected): $result <- $n" } 

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.

$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" } 
comments
Source Link
mazzy
  • 7.2k
  • 2
  • 13
  • 23

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.

$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 separate script file g.ps1 $result = &$g $n #  commentuncomment this line to call a separate script fileblock variable $g # the script block call and the script file call has same bytes "$($result-eq-$expected): $result <- $n" } 

Note: 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.

$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 separate script file $result = &$g $n #  comment this line to call a separate script file # the script block call and the script file call has same bytes "$($result-eq-$expected): $result <- $n" } 

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.

$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 bytes "$($result-eq-$expected): $result <- $n" } 
deleted 1 character in body
Source Link
mazzy
  • 7.2k
  • 2
  • 13
  • 23
Loading
Source Link
mazzy
  • 7.2k
  • 2
  • 13
  • 23
Loading