Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions analizadorLexico.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let cadena = "(79,34)Holaafklndfoi(10asldkfj)(98,902843)lnkjasdlnkfjas(34,56)Bingopingolingo";

let regex = /\((\d+,\d+)\)((?:(?!\(\d+,\d+\)).)*)/g; // 2 groups

let match; // locate each match in regex

while ((match = regex.exec(cadena)) !== null) { // As long as there are matches in the chain
console.log("(" + match[1] + ")" + match[2]); // group the matches
}
11 changes: 11 additions & 0 deletions analizadorLexico.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
$cadena = "(79,34)Holaafklndfoi(10asldkfj)(98,902843)lnkjasdlnkfjas(34,56)Bingopingolingo";

$regex = '/\((\d+,\d+)\)((?:(?!\(\d+,\d+\)).)*)/';

preg_match_all($regex, $cadena, $matches, PREG_SET_ORDER);

foreach ($matches as $match) {
echo "(" . $match[1] . ")" . $match[2] . "\n";
}
?>
33 changes: 33 additions & 0 deletions capicua.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
let number = 48;

function invertNumber(n) {
let numberStr = n.toString(); // convert string to number
let invertedStr = numberStr.split('').reverse().join(''); // divide string, reverse that string & 'joins' the numbers
return parseInt(invertedStr); // convert string to number integer
}

function isCapicua(n) { // 33
let str = n.toString();
let invertedStr = str.split('').reverse().join('');
return str === invertedStr; // 132 === 231 - false
}

function findCapicua(num) { // 48
let count = 0; // number of iterations

while (true) {
let reversedNum = invertNumber(num); // 48 -> 84
let sum = num + reversedNum; // 132

count++;

if (isCapicua(sum)) {
console.log(sum + " " + count);
break;
} else {
num = sum; // number = 132
}
}
}

findCapicua(number);
Empty file added capicua.php
Empty file.