5 kyu

Graphics Series #2: barcode EAN-13 part2

Description:

About barcode EAN-13

The EAN-13 barcode is used worldwide for marking products often sold at retail point of sale. I will not describe it in Kata in detail about it, because my poor English is certainly not better than Wikipedia. So, thanks to Wikipedia. Click here to view detailed information on barcode EAN-13.

Make sure you understand the rules, and then try to solve this kata ;-)

Rules of kata

First, in order to make your program easier, four data has been preload:

group  ----  First group of 6 digits
group=["LLLLLL","LLGLGG","LLGGLG",
       "LLGGGL","LGLLGG","LGGLLG",
       "LGGGLL","LGLGLG","LGLGGL",
       "LGGLGL"]
lcode  ----  L-digits
lcode=["0001101","0011001","0010011",
       "0111101","0100011","0110001",
       "0101111","0111011","0110111",
       "0001011"]
gcode  ----  G-digits
gcode=["0100111","0110011","0011011",
       "0100001","0011101","0111001",
       "0000101","0010001","0001001",
       "0010111"]
rcode  ----  R-digits
rcode=["1110010","1100110","1101100",
       "1000010","1011100","1001110",
       "1010000","1000100","1001000",
       "1110100"]

Hope that the data will help you solve this kata.

Second, your task is to write function encodeBarcode, argument digits is a string contains the 1-12 digits of barcode. You need to calculate the 13th digit (checksum digit) based on digits, then generate a barcode string, and return it. barcode string length=3+42+5+42+3=95, like this:

start 3 areas        center 5 areas                   end 3 areas    
     |                      |                             |
   "101...................01010..........................101"
                 |                           | 
    left 6 digit(6*7=42 areas)  right 6 digit(6*7=42 areas)

Graphics Series:

Puzzles
Games

Stats:

CreatedJun 17, 2016
PublishedJun 17, 2016
Warriors Trained373
Total Skips172
Total Code Submissions167
Total Times Completed56
JavaScript Completions56
Total Stars9
% of votes with a positive feedback rating100% of 24
Total "Very Satisfied" Votes24
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes0
Total Rank Assessments5
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • kazk Avatar
  • docgunthrop Avatar
  • JohanWiltink Avatar
Ad