function getCigar() {
let s =''
const ops = 'MID'
for(let i = 0; i < 10; i++) {
const len = Math.floor(Math.random()*100)
const op = ops[Math.floor(Math.random()*3)]
s+=len+op
}
return s
}
const s = getCigar()
const ops = s.split(/([MIDNSHPX=])/)
let lenOnRef=0
for(let i = 0; i < ops.length; i+=2) {
const len = +ops[i]
const op = ops[i+1]
if(op==='D'||op==='M') {
lenOnRef+=len
}
}
const s = getCigar()
let currLen=''
let lenOnRef=0
for(let i = 0; i < s.length; i++) {
const d = s.codePointAt(i)
if(d>48&&d<57) {
currLen+=d
}
else {
len = +currLen
op = s[i]
if(op==='D'||op==='M') {
lenOnRef+=+len
}
currLen=''
}
}
const s = getCigar()
let currLen=''
let lenOnRef=0
for(let i = 0; i < s.length; i++) {
const d = s[i]
if(d>="0"&&d<="9") {
currLen+=d
}
else {
len = +currLen
op = d
if(op==='D'||op==='M') {
lenOnRef+=+len
}
currLen=''
}
}