Solve problem 7 task 2
This commit is contained in:
parent
0097080190
commit
4c4af05b5f
1 changed files with 15 additions and 3 deletions
|
@ -121,10 +121,22 @@
|
||||||
⍝ Problem 7, Task 1 - CheckDigit
|
⍝ Problem 7, Task 1 - CheckDigit
|
||||||
CheckDigit←{10|-⍵+.×11⍴3 1}
|
CheckDigit←{10|-⍵+.×11⍴3 1}
|
||||||
|
|
||||||
∇ bits←WriteUPC digits
|
⍝ Left and right representations of digits. Decoding
|
||||||
|
⍝ the binary representation from decimal is more
|
||||||
|
⍝ compact than writing everything explicitly.
|
||||||
|
lrepr←⍉(7⍴2)⊤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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue