Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
84
Task/UPC/EasyLang/upc.easy
Normal file
84
Task/UPC/EasyLang/upc.easy
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
proc trim . s$ .
|
||||
a = 1
|
||||
while substr s$ a 1 = " "
|
||||
a += 1
|
||||
.
|
||||
b = len s$
|
||||
while substr s$ b 1 = " "
|
||||
b -= 1
|
||||
.
|
||||
s$ = substr s$ a (b - a + 1)
|
||||
.
|
||||
func$ rev s$ .
|
||||
a$[] = strchars s$
|
||||
for i to len a$[] div 2
|
||||
swap a$[i] a$[len a$[] - i + 1]
|
||||
.
|
||||
return strjoin a$[]
|
||||
.
|
||||
func$ invert s$ .
|
||||
for c$ in strchars s$
|
||||
if c$ = " "
|
||||
r$ &= "#"
|
||||
else
|
||||
r$ &= " "
|
||||
.
|
||||
.
|
||||
return r$
|
||||
.
|
||||
digs$[] = [ " ## #" " ## #" " # ##" " #### #" " # ##" " ## #" " # ####" " ### ##" " ## ###" " # ##" ]
|
||||
func[] decode_upc upc$ .
|
||||
subr getdigs
|
||||
for _ to 6
|
||||
h$ = substr upc$ pos 7
|
||||
for dig to 10
|
||||
d$ = digs$[dig]
|
||||
if isright = 1
|
||||
d$ = invert d$
|
||||
.
|
||||
if h$ = d$
|
||||
break 1
|
||||
.
|
||||
.
|
||||
if dig = 11
|
||||
return [ ]
|
||||
.
|
||||
dig -= 1
|
||||
digs[] &= dig
|
||||
sum += dig * sumf
|
||||
sumf = 4 - sumf
|
||||
pos = pos + 7
|
||||
.
|
||||
.
|
||||
if len upc$ <> 95
|
||||
return [ ]
|
||||
.
|
||||
if substr upc$ 1 3 <> "# #"
|
||||
return [ ]
|
||||
.
|
||||
pos = 4
|
||||
sumf = 3
|
||||
getdigs
|
||||
if substr upc$ pos 5 <> " # # "
|
||||
return [ ]
|
||||
.
|
||||
pos += 5
|
||||
isright = 1
|
||||
getdigs
|
||||
if substr upc$ 1 3 <> "# #"
|
||||
return [ ]
|
||||
.
|
||||
if sum mod 10 <> 0
|
||||
return [ ]
|
||||
.
|
||||
return digs[]
|
||||
.
|
||||
barcodes$[] = [ " # # # ## # ## # ## ### ## ### ## #### # # # ## ## # # ## ## ### # ## ## ### # # # " " # # # ## ## # #### # # ## # ## # ## # # # ### # ### ## ## ### # # ### ### # # # " " # # # # # ### # # # # # # # # # # ## # ## # ## # ## # # #### ### ## # # " " # # ## ## ## ## # # # # ### # ## ## # # # ## ## # ### ## ## # # #### ## # # # " " # # ### ## # ## ## ### ## # ## # # ## # # ### # ## ## # # ### # ## ## # # # " " # # # # ## ## # # # # ## ## # # # # # #### # ## # #### #### # # ## # #### # # " " # # # ## ## # # ## ## # ### ## ## # # # # # # # # ### # # ### # # # # # " " # # # # ## ## # # ## ## ### # # # # # ### ## ## ### ## ### ### ## # ## ### ## # # " " # # ### ## ## # # #### # ## # #### # #### # # # # # ### # # ### # # # ### # # # " " # # # #### ## # #### # # ## ## ### #### # # # # ### # ### ### # # ### # # # ### # # " ]
|
||||
for s$ in barcodes$[]
|
||||
trim s$
|
||||
r[] = decode_upc s$
|
||||
if r[] = [ ]
|
||||
r[] = decode_upc rev s$
|
||||
.
|
||||
print r[]
|
||||
.
|
||||
90
Task/UPC/FreeBASIC/upc.basic
Normal file
90
Task/UPC/FreeBASIC/upc.basic
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
Sub decode(bar_code As String)
|
||||
Dim As String numbers(9) => { _
|
||||
" ## #", _ '-- 0
|
||||
" ## #", _ '-- 1
|
||||
" # ##", _ '-- 2
|
||||
" #### #", _ '-- 3
|
||||
" # ##", _ '-- 4
|
||||
" ## #", _ '-- 5
|
||||
" # ####", _ '-- 6
|
||||
" ### ##", _ '-- 7
|
||||
" ## ###", _ '-- 8
|
||||
" # ##" } '-- 9
|
||||
Dim As Integer i, j
|
||||
Dim As String temp
|
||||
|
||||
bar_code = Trim(bar_code)
|
||||
If Len(bar_code) = 95 And Mid(bar_code, 1, 3) = "# #" And Mid(bar_code, 46, 5) = " # # " And Mid(bar_code, 93, 3) = "# #" Then
|
||||
For reversed As Integer = 0 To 1
|
||||
Dim r(11) As Integer
|
||||
For i = 1 To 12
|
||||
Dim st As Integer = Iif(i <= 6, i * 7 - 3, i * 7 + 2)
|
||||
Dim number As String = Mid(bar_code, st, 7)
|
||||
If i > 6 Then
|
||||
temp = ""
|
||||
For j = 1 To Len(number)
|
||||
Select Case Mid(number, j, 1)
|
||||
Case " " : temp += "#"
|
||||
Case "#" : temp += " "
|
||||
Case Else: temp += Mid(number, j, 1)
|
||||
End Select
|
||||
Next
|
||||
number = temp
|
||||
End If
|
||||
r(i - 1) = -1
|
||||
For j = 0 To 9
|
||||
If number = numbers(j) Then
|
||||
r(i - 1) = j
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
Next
|
||||
Dim valid As Integer = 1
|
||||
For i = 0 To 11
|
||||
If r(i) = -1 Then
|
||||
valid = 0
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
If valid Then
|
||||
Dim sum As Integer = 0
|
||||
For i = 0 To 11
|
||||
sum += r(i) * Iif(i Mod 2 = 0, 3, 1)
|
||||
Next
|
||||
If sum Mod 10 = 0 Then
|
||||
For i = 0 To 11
|
||||
Print r(i);
|
||||
Next
|
||||
Print Iif(reversed, " (upside down)", "")
|
||||
Else
|
||||
Print "invalid checksum"
|
||||
End If
|
||||
Exit Sub
|
||||
End If
|
||||
temp = ""
|
||||
For i = Len(bar_code) To 1 Step -1
|
||||
temp += Mid(bar_code, i, 1)
|
||||
Next
|
||||
bar_code = temp
|
||||
Next
|
||||
End If
|
||||
Print " invalid"
|
||||
End Sub
|
||||
|
||||
Dim bar_codes(9) As String
|
||||
bar_codes(0) = " # # # ## # ## # ## ### ## ### ## #### # # # ## ## # # ## ## ### # ## ## ### # # # "
|
||||
bar_codes(1) = " # # # ## ## # #### # # ## # ## # ## # # # ### # ### ## ## ### # # ### ### # # # "
|
||||
bar_codes(2) = " # # # # # ### # # # # # # # # # # ## # ## # ## # ## # # #### ### ## # # "
|
||||
bar_codes(3) = " # # ## ## ## ## # # # # ### # ## ## # # # ## ## # ### ## ## # # #### ## # # # "
|
||||
bar_codes(4) = " # # ### ## # ## ## ### ## # ## # # ## # # ### # ## ## # # ### # ## ## # # # "
|
||||
bar_codes(5) = " # # # # ## ## # # # # ## ## # # # # # #### # ## # #### #### # # ## # #### # # "
|
||||
bar_codes(6) = " # # # ## ## # # ## ## # ### ## ## # # # # # # # # ### # # ### # # # # # "
|
||||
bar_codes(7) = " # # # # ## ## # # ## ## ### # # # # # ### ## ## ### ## ### ### ## # ## ### ## # # "
|
||||
bar_codes(8) = " # # ### ## ## # # #### # ## # #### # #### # # # # # ### # # ### # # # ### # # # "
|
||||
bar_codes(9) = " # # # #### ## # #### # # ## ## ### #### # # # # ### # ### ### # # ### # # # ### # # "
|
||||
|
||||
For i As Integer = 0 To 9
|
||||
decode(bar_codes(i))
|
||||
Next
|
||||
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue