Anonymous user
UPC: Difference between revisions
m
→{{header|REXX}}: added/changed whitespace and comments, checked for errors better, split some compound statements, spelled out some error conditions.
m (→{{header|REXX}}: added/changed whitespace and comments, checked for errors better, split some compound statements, spelled out some error conditions.) |
|||
Line 2,084:
#.7= ' ### ##'
#.8= ' ## ###' /* [↓] right─sided UPC digits.*/
#.9= ' # ##' ;
say center('UPC', 14, "─") '
@.=.
@.1 = ' # # # ## # ## # ## ### ## ### ## #### # # # ## ## # # ## ## ### # ## ## ### # # # '
Line 2,098:
@.9 = ' # # ### ## ## # # #### # ## # #### # #### # # # # # ### # # ### # # # ### # # # '
@.10= ' # # # #### ## # #### # # ## ## ### #### # # # # ### # ### ### # # ### # # # ### # '
do j=1 while @.j\==.; $= @.j
if left($, 3) \==ends | right($, 3) \==ends then txt= 'bad fence'
$= substr($, 4, L - length(ends)*2) /*elide "ends". */
$= delstr($, length($)
sum= 0 /*initialize SUM*/
else sum= sum + d /* " " 1. */
if
say center(
end /*j*/ /*stick a fork in it, we're all done. */</lang>
▲ if left($, 3)\=='# #' | right($, 3)\=="# #" then txt= 'bad fence'
▲ if L\==95 & txt=='' then txt= 'bad len'
▲ $= substr($, 4, L - 3 - 3); sum= 0 /*elide ends.*/
▲ $= delstr($, length($) % 2 - 1, 5) /* " middle.*/
▲ if txt=='' then do k=1 for 12; parse var $ x +7 $ /*get UPC dig.*/
▲ do d=0 for 10; if x==#.d | x==##.d then leave /*valid digit?*/
▲ end /*d*/
▲ if d==10 & k\==12 then do; txt= 'reversed'; leave; end
▲ if d==10 then do; txt= 'bad dig'; leave; end
▲ if k//2 then sum= sum + 3 * d /*mult. by 3.*/
▲ else sum= sum + d /* " " 1.*/
▲ txt= txt || d
▲ end /*k*/
▲ if sum//10 \== 0 then txt= 'bad chksum' /*invalid sum?*/
▲ end /*j*/ /*stick a fork in it, we're all done. */</lang>
{{out|output|text= when using the internal default input:}}
<pre>
─────UPC────── ---123456712345671234567123456712345671234567-----123456712345671234567123456712345671234567---
924773271019 # # # ## # ## # ## ### ## ### ## #### # # # ## ## # # ## ## ### # ## ## ### # # #
403944441050 # # # ## ## # #### # # ## # ## # ## # # # ### # ### ## ## ### # # ### ### # # #
reversed # # # # # ### # # # # # # # # # # ## # ## # ## # ## # # #### ### ## # #
reversed # # ## ## ## ## # # # # ### # ## ## # # # ## ## # ### ## ## # # #### ## # # #
reversed # # # # ## ## # # # # ## ## # # # # # #### # ## # #### #### # # ## # #### # #
214575875608 # # # ## ## # # ## ## # ### ## ## # # # # # # # # ### # # ### # # # # #
reversed # # # # ## ## # # ## ## ### # # # # # ### ## ## ### ## ### ### ## # ## ### ## # #
706466743030 # # ### ## ## # # #### # ## # #### # #### # # # # # ### # # ### # # # ### # # #
</pre>
|