Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let line = input.slice(0).shift();
- let pattern = /(?<symbols>[^\d]+)(?<number>\d+)/gm;
- let symbolSet = new Set();
- let matches = Array.from(line.matchAll(pattern));
- let output = [];
- if (matches.length > 0) {
- for (const match of matches) {
- if(Number(match[2]) !== 0){
- let currentMatch = match[1].toUpperCase().repeat(Number(match[2]));
- output.push(currentMatch);
- match[1].split("").forEach(symbol => {
- symbolSet.add(symbol.toUpperCase());
- });
- }
- }
- }
- console.log(`Unique symbols used: ${Array.from(symbolSet).length}`);
- console.log(output.join(""));
- }
Advertisement
Add Comment
Please, Sign In to add comment