ISBN13 check digit: Difference between revisions
Content added Content deleted
Langurmonkey (talk | contribs) |
Langurmonkey (talk | contribs) |
||
Line 190: | Line 190: | ||
In this example, we map to multiple functions (actually 1 no-op). |
In this example, we map to multiple functions (actually 1 no-op). |
||
<lang langur>val .isbn13checkdigit = f(var .s) { |
<lang langur>val .isbn13checkdigit = f(var .s) { |
||
.s = replace(.s, RE/[\- ]/) |
|||
matching(re/^[0-9]{13}$/, .s) and |
|||
fold(f{+}, map([_, f .d x 3], map(f .c-'0', s2cp .s))) rem 10 == 0 |
fold(f{+}, map([_, f .d x 3], map(f .c-'0', s2cp .s))) rem 10 == 0 |
||
} |
} |
||
Line 210: | Line 211: | ||
In this example, we set a for loop value as it progresses. |
In this example, we set a for loop value as it progresses. |
||
<lang langur>val .isbn13checkdigit = f(var .s) { |
<lang langur>val .isbn13checkdigit = f(var .s) { |
||
.s = replace(.s, RE/[\- ]/) |
|||
var .alt = true |
var .alt = true |
||
matching(re/^[0-9]{13}$/, .s |
matching(re/^[0-9]{13}$/, .s) and |
||
for[=0] .d in map(f .c-'0', s2cp .s) { _for += if(.alt=not .alt: .d x 3; .d) } rem 10 == 0 |
for[=0] .d in map(f .c-'0', s2cp .s) { _for += if(.alt=not .alt: .d x 3; .d) } rem 10 == 0 |
||
} |
} |