Anonymous user
ISBN13 check digit: Difference between revisions
→{{header|PL/M}}
m (→{{header|F#}}) |
|||
Line 2,125:
978-1788399081: GOOD
978-1788399083: BAD</pre>
=={{header|Powershell}}==
<lang Powershell>
function Get-ISBN13 {
$codes = (
"978-1734314502",
"978-1734314509",
"978-1788399081",
"978-1788399083"
)
foreach ($line in $codes) {
$sum = $null
$codeNoDash = $line.Replace("-","")
for ($i = 0; $i -lt $codeNoDash.length; $i++) {
if (($i % 2) -eq 1) {
$sum += [decimal]$codeNoDash[$i] * 3
}else {
$sum += [decimal]$codeNoDash[$i]
}
}
if (($sum % 10) -eq 0) {
Write-Host "$line Good"
}else {
Write-Host "$line Bad"
}
}
}
Get-ISBN13
</lang>
{{out}}
<pre>
978-1734314502 Good
978-1734314509 Bad
978-1788399081 Good
978-1788399083 Bad
</pre>
=={{header|PureBasic}}==
|