Solve problem 7 task 2

This commit is contained in:
Dimitri Lozeve 2020-05-19 18:08:44 +02:00
parent 0097080190
commit 4c4af05b5f

View file

@ -121,10 +121,22 @@
⍝ Problem 7, Task 1 - CheckDigit ⍝ Problem 7, Task 1 - CheckDigit
CheckDigit←{10|-⍵+.×113 1} CheckDigit←{10|-⍵+.×113 1}
∇ bits←WriteUPC digits ⍝ Left and right representations of digits. Decoding
⍝ the binary representation from decimal is more
⍝ compact than writing everything explicitly.
lrepr←⍉(72)13 25 19 61 35 49 47 59 55 11
rrepr←~¨lrepr
∇ bits←WriteUPC digits;left;right
⍝ 2020 APL Problem Solving Competition Phase II ⍝ 2020 APL Problem Solving Competition Phase II
⍝ Stub function for Problem 7, Task 2 - WriteUPC ⍝ Problem 7, Task 2 - WriteUPC
⍝ Put your code and comments below here :If (11=≢digits)∧∧/digits∊0,9
left←,lrepr[1+6↑digits;]
right←,rrepr[1+6↓digits,CheckDigit digits;]
bits←1 0 1,left,0 1 0 1 0,right,1 0 1
:Else
bits←¯1
:EndIf
∇ digits←ReadUPC bits ∇ digits←ReadUPC bits