(phixonline)-->
with javascript_semantics
constant numbers = {" ## #", -- 0
" ## #", -- 1
" # ##", -- 2
" #### #", -- 3
" # ##", -- 4
" ## #", -- 5
" # ####", -- 6
" ### ##", -- 7
" ## ###", -- 8
" # ##"} -- 9
procedure decode(string bar_code)
bar_code = trim(bar_code)
if length(bar_code)=95
and bar_code[1..3]="# #"
and bar_code[46..50]=" # # "
and bar_code[93..95]="# #" then
for reversed=false to true do
sequence r = {}
for i=1 to 12 do
integer st = iff(i<=6?i*7-3:i*7+2)
string number = bar_code[st..st+6]
if i>6 then number = substitute_all(number," #X","X #") end if
r &= find(number,numbers)-1
end for
if not find(-1,r) then
if remainder(sum(sq_mul(r,{3,1,3,1,3,1,3,1,3,1,3,1})),10) then
printf(1,"invalid checksum\n")
else
printf(1,"%v%s\n",{r,iff(reversed?" (upside down)","")})
end if
return
end if
bar_code = reverse(bar_code)
end for
end if
printf(1,"invalid\n")
end procedure
constant bar_codes = split("""
# # # ## # ## # ## ### ## ### ## #### # # # ## ## # # ## ## ### # ## ## ### # # #
# # # ## ## # #### # # ## # ## # ## # # # ### # ### ## ## ### # # ### ### # # #
# # # # # ### # # # # # # # # # # ## # ## # ## # ## # # #### ### ## # #
# # ## ## ## ## # # # # ### # ## ## # # # ## ## # ### ## ## # # #### ## # # #
# # ### ## # ## ## ### ## # ## # # ## # # ### # ## ## # # ### # ## ## # # #
# # # # ## ## # # # # ## ## # # # # # #### # ## # #### #### # # ## # #### # #
# # # ## ## # # ## ## # ### ## ## # # # # # # # # ### # # ### # # # # #
# # # # ## ## # # ## ## ### # # # # # ### ## ## ### ## ### ### ## # ## ### ## # #
# # ### ## ## # # #### # ## # #### # #### # # # # # ### # # ### # # # ### # # #
# # # #### ## # #### # # ## ## ### #### # # # # ### # ### ### # # ### # # # ### # #
""","\n",true)
for i=1 to length(bar_codes) do
decode(bar_codes[i])
end for