Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

95
Task/UPC/11l/upc.11l Normal file
View file

@ -0,0 +1,95 @@
V LEFT_DIGITS = [
## # = 0,
## # = 1,
# ## = 2,
#### # = 3,
# ## = 4,
## # = 5,
# #### = 6,
### ## = 7,
## ### = 8,
# ## = 9
]
V RIGHT_DIGITS = Dict(LEFT_DIGITS.items(), (k, v) -> (k.replace( , s).replace(#, ).replace(s, #), v))
V END_SENTINEL = # #
V MID_SENTINEL = # #
F decodeUPC(input)
F decode(candidate)
V pos = 0
V part = candidate[pos .+ :END_SENTINEL.len]
I part == :END_SENTINEL
pos += :END_SENTINEL.len
E
R (0B, [Int]())
[Int] output
L 6
part = candidate[pos .+ 7]
pos += 7
I part C :LEFT_DIGITS
output [+]= :LEFT_DIGITS[part]
E
R (0B, output)
part = candidate[pos .+ :MID_SENTINEL.len]
I part == :MID_SENTINEL
pos += :MID_SENTINEL.len
E
R (0B, output)
L 6
part = candidate[pos .+ 7]
pos += 7
I part C :RIGHT_DIGITS
output [+]= :RIGHT_DIGITS[part]
E
R (0B, output)
part = candidate[pos .+ :END_SENTINEL.len]
I part == :END_SENTINEL
pos += :END_SENTINEL.len
E
R (0B, output)
V sum = 0
L(v) output
I L.index % 2 == 0
sum += 3 * v
E
sum += v
R (sum % 10 == 0, output)
V candidate = input.trim( )
V out = decode(candidate)
I out[0]
print(out[1])
E
out = decode(reversed(candidate))
I out[0]
print(out[1] Upside down)
E
I out[1].len == 12
print(Invalid checksum)
E
print(Invalid digit(s))
V barcodes = [
# # # ## # ## # ## ### ## ### ## #### # # # ## ## # # ## ## ### # ## ## ### # # # ,
# # # ## ## # #### # # ## # ## # ## # # # ### # ### ## ## ### # # ### ### # # # ,
# # # # # ### # # # # # # # # # # ## # ## # ## # ## # # #### ### ## # # ,
# # ## ## ## ## # # # # ### # ## ## # # # ## ## # ### ## ## # # #### ## # # # ,
# # ### ## # ## ## ### ## # ## # # ## # # ### # ## ## # # ### # ## ## # # # ,
# # # # ## ## # # # # ## ## # # # # # #### # ## # #### #### # # ## # #### # # ,
# # # ## ## # # ## ## # ### ## ## # # # # # # # # ### # # ### # # # # # ,
# # # # ## ## # # ## ## ### # # # # # ### ## ## ### ## ### ### ## # ## ### ## # # ,
# # ### ## ## # # #### # ## # #### # #### # # # # # ### # # ### # # # ### # # # ,
# # # #### ## # #### # # ## ## ### #### # # # # ### # ### ### # # ### # # # ### # #
]
L(barcode) barcodes
decodeUPC(barcode)