UPC: Difference between revisions
Content added Content deleted
(julia example) |
|||
Line 266: | Line 266: | ||
mats, dig, dsum = filter(!isempty, m.captures), Int[], 0 |
mats, dig, dsum = filter(!isempty, m.captures), Int[], 0 |
||
for mat in mats |
for mat in mats |
||
append!(dig, [ptod1[x.match] for x in eachmatch(r"(.......)", mat) |
append!(dig, [ptod1[x.match] for x in eachmatch(r"(.......)", mat) |
||
if haskey(ptod1, x.match)]) |
if haskey(ptod1, x.match)]) |
||
append!(dig, [ptod2[x.match] for x in eachmatch(r"(.......)", mat) |
append!(dig, [ptod2[x.match] for x in eachmatch(r"(.......)", mat) |
||
if haskey(ptod2, x.match)]) |
if haskey(ptod2, x.match)]) |
||
end |
end |
||
dsum += sum([(isodd(i) ? 3 : 1) * n for (i, n) in enumerate(dig)]) |
dsum += sum([(isodd(i) ? 3 : 1) * n for (i, n) in enumerate(dig)]) |
||
(dsum % 10 == 0) && return prod(string.(dig)) |
|||
return prod(string.(dig)) |
|||
end |
|||
end |
end |
||
return "" |
return "" |
||
end |
end |
||
Line 310: | Line 308: | ||
653483540435 |
653483540435 |
||
</pre> |
</pre> |
||
=={{header|Perl}}== |
=={{header|Perl}}== |