Created
October 28, 2022 04:28
-
-
Save lucasdellasala/532c8082b5ce5869a398522932ca5773 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface TestCase { | |
input: string; | |
expected: string; | |
solution: number; | |
} | |
const TEST_CASES: TestCase[] = [ | |
{ | |
input: 'aca', | |
expected: 'aaa', | |
solution: 2 | |
}, | |
{ | |
input: 'aaabb', | |
expected: 'aaabb', | |
solution: 0 | |
}, | |
{ | |
input: 'aaaab', | |
expected: 'aaaaa', | |
solution: 1 | |
}, | |
{ | |
input: 'acdcd', | |
expected: 'aaddd', // || 'ccddd' ok || 'aaccc' mal, | |
solution: 3 | |
}, | |
]; | |
function getMinMoves(s: string) { | |
const len = s.length; | |
const comp: any = {} | |
// analysis | |
for (let i = 0; i < len; i++) { | |
const prev = s[i - 1]?.charCodeAt(0) - 97; | |
const current = s[i].charCodeAt(0) - 97; | |
const next = s[i + 1]?.charCodeAt(0) - 97; | |
const data = { prev, current, next }; | |
let match; | |
let matchPos; | |
let near; | |
let nearPos; | |
if (current === prev) { | |
near = prev; | |
nearPos = i - 1; | |
match = near; | |
matchPos = nearPos; | |
} | |
if (current === next) { | |
near = next; | |
nearPos = i + 1; | |
match = near; | |
matchPos = nearPos; | |
} | |
comp[i] = { | |
data, | |
near, | |
nearPos, | |
match, | |
matchPos, | |
done: match ? true : false, | |
}; | |
} | |
// solution | |
for (const key in comp) { | |
if (comp[key].done) { | |
continue; | |
} | |
} | |
console.log({ comp }); | |
return 2; | |
} | |
/* for(const test of TEST_CASES){ | |
const result = getMinMoves(test.input); | |
if (result === test.solution) { | |
console.log(`✅[SUCCESS] Input ${test.input} has ${test.solution} minimum moves to satisfy the condition.`) | |
} else { | |
console.log(`❌[FAIL] Input ${test.input} hasn't ${result} minimum moves to satisfy the condition.`) | |
} | |
} */ | |
function grouper(s: string) { | |
const l = s.length; | |
const list = transcript(s); | |
const y = Math.max(...list); | |
const x = Math.min(...list); | |
const m = getMaxMoves(list); | |
const d = Math.abs(y - x); | |
const a = d + 1; | |
const c = a ** l; | |
console.log({ s }, { list }, { l }, { m }, { y }, { x }, { d }, { a }, { c }); | |
} | |
function transcript(s: string) { | |
let list = []; | |
for (let i = 0; i < s.length; i++) { | |
list.push(s[i].charCodeAt(0) - 97); | |
} | |
return list; | |
} | |
function getMaxMoves(list: number[]) { | |
let counter = 0; | |
for (let i = 0; i < list.length - 1; i++) { | |
counter = counter + Math.abs((list[i] - list[i + 1])); | |
} | |
return counter; | |
} | |
grouper('aba'); | |
grouper('acad'); | |
grouper('ababe'); | |
function getCombs(combs: any[], min: number, max: number, len: number) { | |
// Escribir funcion recursiva que construya algo como combinations_aba | |
} | |
const combinations_aba = [ | |
[0, 0, 0], | |
[0, 0, 1], | |
[0, 0, 2], | |
[0, 1, 0], | |
[0, 1, 1], | |
[0, 1, 2], | |
[0, 2, 0], | |
[0, 2, 1], | |
[0, 2, 2], | |
[1, 0, 0], | |
[1, 0, 1], | |
[1, 0, 2], | |
[1, 1, 0], | |
[1, 1, 1], | |
[1, 1, 2], | |
[1, 2, 0], | |
[1, 2, 1], | |
[1, 2, 2], | |
[2, 0, 0], | |
[2, 0, 1], | |
[2, 0, 2], | |
[2, 1, 0], | |
[2, 1, 1], | |
[2, 1, 2], | |
[2, 2, 0], | |
[2, 2, 1], | |
[2, 2, 2] | |
] | |
// https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgCoQM5gMJwygbwChlTlQAHAVzAC5kspQBzAbhLIgA8KIFIAJvUYt2ZBgHsANjWASQ9EFQC2AI2jsAvkSIJ5WNAFEAyqgD62AILGT9dFlz4A2gF1kAXmROOpYuPGUNPQA5IhwwQA0Pv7cvPwQQsihcOFR-mQY0rLy9ABM0ZppZH7p5CDUdEkpcKqqkdHisXyCIdW19aWSMmByCsgADAVFvg1kgZXJKXXDMTzNCa3VqaOkmd299ACMQ9El6eOtCAJHHa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kg75UPQAjqOY4d7zRc8TEcTgLhppJaOsFj0gMwERPg45GpZulX0uFLhKDHHTwK7YzO-YZdlx1q+qpA7tYsqkHK8oYIqZ3y4uVwn81x7pEE5-y6VCnnhOV-yiv18VReu+K6qkRRNF5HMqBXfd4BPdJclKRpOlog3Kf2VcNcyEanUNy9TwjVNTluTt-lyA2gOruJ2HJqAYF5KSfM7ZixdjLL2FMjdxKkDKhVc0Tt97ayPmyXOQcC4w1mlPRQKh1BQFcAdDcegUSQBokaDy2pdRYgNF-S0yAzRTxtjybisFLRALvp0Kh4BoDskETQ1iyAk4hxrsSXUTtpK+inp6cR-pqRIOiKgqAbJREaCIHKIgzB9aG2gMSUIqhwjLQMQbI2JiwgCGCBYwx1jTE1AgPYxEWDda5wjGoWaIpVAm0VFKVwM4wZ9CUGoaAIT87EIiVAGc3IYmkLigqQwbsmCqGANqLB6IXREVVASccABHSyTcLKSnHGCZg8MRTVIkGoUAiN9BmBqHAXROgMx+IaVjDAzSzFP2iE4foM4hkDBcDMQZwyZz+nGSMkZuQxkDJGZsYZCzxATL9FM1ZZB1nLOQPMmZM5cgrIOXszZJyjl7K2aQJwuzZlXK8Lcs5AzHmXPGbs259yblTKeWs95hzPm7Iuf0AFhyfnbMBf88ZQLjkDOha2KFkzXmwu+aMhFGz4XIvRfszFQLPkXIudMnF-yiAuCIEAA |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
estrategia bloquear las parejas o grupos que ya cumplan la condicion (skipeando en el bucle generador de combinaciones)