Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let data = input[0].split(/[,\s]+/g);
- let reg = /^.*?(?<matchgroup>\@{6,}|\${6,}|\^{6,}|\#{6,}).*?$/;
- for (const line of data) {
- let noMatch = false;
- if (line.length === 20) {
- let left = line.substring(0, 10);
- let right = line.substring(10);
- if(left.match(reg) !== null && right.match(reg) !== null){
- if(left.match(reg).groups.matchgroup[0] === right.match(reg).groups.matchgroup[0]){
- let length =
- left.match(reg).groups.matchgroup.length < right.match(reg).groups.matchgroup.length ?
- left.match(reg).groups.matchgroup.length : right.match(reg).groups.matchgroup.length ;
- let symbol = left.match(reg).groups.matchgroup[0];
- let jackpot = length === 10? ' Jackpot!': '';
- console.log(`ticket "${line}" - ${length}${symbol}${jackpot}`);
- }else{
- noMatch = true;
- }
- }else{
- noMatch = true;
- }
- if(noMatch){
- console.log(`ticket "${line}" - no match`);
- }
- } else {
- console.log(`invalid ticket`);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement