Size: a a a

2020 June 20

L

Lupusregina[beta] in pro.js
Denis Efremov
2**26 это уже 67КК
?
источник

DE

Denis Efremov in pro.js
источник

L

Lupusregina[beta] in pro.js
а что это
источник

DE

Denis Efremov in pro.js
На 27 не хватает памяти
источник

DE

Denis Efremov in pro.js
Дерево из двух букв глубиною 26 описывает 67КК вариантов
источник

L

Lupusregina[beta] in pro.js
Denis Efremov
Дерево из двух букв глубиною 26 описывает 67КК вариантов
мой вариант посмотри
источник

L

Lupusregina[beta] in pro.js
источник

DE

Denis Efremov in pro.js
function getRandomLetter() {
 return String.fromCharCode((Math.random() * 25 + 97) ^ 0);
}
let i = 0
const obj = {}
let tmp = obj
const I = 25
function addProps (index = 0, o = {}) {
 if (index < I) {
   const l1 = getRandomLetter()
   const l2 = getRandomLetter()
   o[l1] = {}
   o[l1] = addProps(index + 1, o[l1])    
   o[l2] = {}
   o[l2] = addProps(index + 1, o[l2])    
   return o
 }
 o['a'] = true
 o['b'] = true
 return o
}
console.time(I)
tmp = addProps(0, tmp)
console.timeEnd(I)

function makeString(o, p = '') {
 if (typeof o === 'boolean') {
   return p
 }
 const key = Object.keys(o)[Math.random() ^ 0]
 return makeString(o[key], p + key)
}

makeString(tmp)
источник

S

Syntax Highlight Bot in pro.js
Denis Efremov
function getRandomLetter() {
 return String.fromCharCode((Math.random() * 25 + 97) ^ 0);
}
let i = 0
const obj = {}
let tmp = obj
const I = 25
function addProps (index = 0, o = {}) {
 if (index < I) {
   const l1 = getRandomLetter()
   const l2 = getRandomLetter()
   o[l1] = {}
   o[l1] = addProps(index + 1, o[l1])    
   o[l2] = {}
   o[l2] = addProps(index + 1, o[l2])    
   return o
 }
 o['a'] = true
 o['b'] = true
 return o
}
console.time(I)
tmp = addProps(0, tmp)
console.timeEnd(I)

function makeString(o, p = '') {
 if (typeof o === 'boolean') {
   return p
 }
 const key = Object.keys(o)[Math.random() ^ 0]
 return makeString(o[key], p + key)
}

makeString(tmp)
источник

DE

Denis Efremov in pro.js
10 сек и 33КК вариантов
источник

DE

Denis Efremov in pro.js
Ой 16КК
источник

DE

Denis Efremov in pro.js
Но всё равно
источник

L

Lupusregina[beta] in pro.js
Lupusregina[beta]
class Node {
 constructor(char, parent, inc = true) {
   this.parent = parent
   this.char = char
   this.children = []
   this.leaf = false
   this.numLeafs = 1

   if ( inc )
     while(parent) {
       parent.numLeafs++
       parent = parent.parent
     }
 }
}
class Tree {
 constructor() {
   this.root = new Node("", null, false)
   this.root.numLeafs = 0
 }
 
 add(word, node = this.root) {
   for(let i = 0; i < word.length; i++) {
     const char = word[i]
     const childNode = node.children.find(n => n.char[0] === char)
     if ( childNode ) {
       if ( childNode.char.length === 1 ) {
         node = childNode
         continue
       } else {
         const word1 = childNode.char.slice(1)
         childNode.char = childNode.char[0]
         childNode.children.push( new Node(word1, childNode, false) )
         this.add(word.slice(i + 1), childNode)
         break
       }
     } else {
       node.children.push( new Node(word.slice(i), node, true) )
       break
     }
   }
 }
 getAllNumNodes(children = this.root.children) {
   return children.reduce((s, node) => s + 1 + this.getAllNumNodes(node.children), 0)
 }
 likeStringCount(pattern) {
   let node = this.root

   next:
   while(1) {
     if ( !pattern.length )
       return node.numLeafs

     let children = node.children
     for(const childNode of children) {
       if ( childNode.children.length ) {
         if ( childNode.char === pattern[0] ) {
           pattern = pattern.slice(1)
           node = childNode
           continue next;
         }
       } else {
         if ( childNode.char.indexOf(pattern) === 0 ) {
           pattern = ""
           node = childNode
           continue next;
         }
       }
     }
     
     return 0
   }
 }
}
const t = new Tree

function getStringRand(len = 100) {
 let s = ""
 while(len--)
   s += String.fromCharCode(97 + (Math.random()*25|0))
 return s
}

console.time('init')
for(let i = 0; i < 1e6; i++) {
 const s = getStringRand()
 t.add( s )
}
console.timeEnd('init')

function like(pattern) {
 let tn = Date.now()
   const count = t.likeStringCount(pattern)
 tn = Date.now() - tn
 console.log(`(time: ${ tn }msec) Like '${ pattern }.*' count: ` + count)
}
like('a')
like('ab')
like('abc')
like('abce')
надо в бинарный вид это перевести
источник

L

Lupusregina[beta] in pro.js
что бы память не ело
источник

DE

Denis Efremov in pro.js
function getRandomLetter() {
 return String.fromCharCode((Math.random() * 25 + 97) ^ 0).repeat(4);
}
let tmp = {}
const I = 25
function addProps (index = 0, o = {}) {
 if (index < I) {
   const l1 = getRandomLetter()
   const l2 = getRandomLetter()
   o[l1] = {}
   o[l1] = addProps(index + 1, o[l1])    
   o[l2] = {}
   o[l2] = addProps(index + 1, o[l2])    
   return o
 }
 return true
}
console.time(I)
tmp = addProps(0, tmp)
console.timeEnd(I)

function makeString(o, p = '') {
 if (typeof o === 'boolean') {
   return p
 }
 const key = Object.keys(o)[Math.random() ^ 0]
 return makeString(o[key], p + key)
}
console.time('toStr')
const res = makeString(tmp)
console.timeEnd('toStr')
console.log(res)
источник

S

Syntax Highlight Bot in pro.js
Denis Efremov
function getRandomLetter() {
 return String.fromCharCode((Math.random() * 25 + 97) ^ 0).repeat(4);
}
let tmp = {}
const I = 25
function addProps (index = 0, o = {}) {
 if (index < I) {
   const l1 = getRandomLetter()
   const l2 = getRandomLetter()
   o[l1] = {}
   o[l1] = addProps(index + 1, o[l1])    
   o[l2] = {}
   o[l2] = addProps(index + 1, o[l2])    
   return o
 }
 return true
}
console.time(I)
tmp = addProps(0, tmp)
console.timeEnd(I)

function makeString(o, p = '') {
 if (typeof o === 'boolean') {
   return p
 }
 const key = Object.keys(o)[Math.random() ^ 0]
 return makeString(o[key], p + key)
}
console.time('toStr')
const res = makeString(tmp)
console.timeEnd('toStr')
console.log(res)
источник

L

Lupusregina[beta] in pro.js
Denis Efremov
function getRandomLetter() {
 return String.fromCharCode((Math.random() * 25 + 97) ^ 0).repeat(4);
}
let tmp = {}
const I = 25
function addProps (index = 0, o = {}) {
 if (index < I) {
   const l1 = getRandomLetter()
   const l2 = getRandomLetter()
   o[l1] = {}
   o[l1] = addProps(index + 1, o[l1])    
   o[l2] = {}
   o[l2] = addProps(index + 1, o[l2])    
   return o
 }
 return true
}
console.time(I)
tmp = addProps(0, tmp)
console.timeEnd(I)

function makeString(o, p = '') {
 if (typeof o === 'boolean') {
   return p
 }
 const key = Object.keys(o)[Math.random() ^ 0]
 return makeString(o[key], p + key)
}
console.time('toStr')
const res = makeString(tmp)
console.timeEnd('toStr')
console.log(res)
а как ты отсюда получишь число слов
источник

DE

Denis Efremov in pro.js
2 ^ длина строки - 1
источник

DE

Denis Efremov in pro.js
function getRandomLetter() {
 return String.fromCharCode((Math.random() * 25 + 97) ^ 0).repeat(4);
}
let tmp = {}
const I = 25
function addProps (index = 0, o = {}) {
 if (index < I) {
   const l1 = getRandomLetter()
   const l2 = getRandomLetter()
   o[l1] = {}
   o[l1] = addProps(index + 1, o[l1])    
   o[l2] = {}
   o[l2] = addProps(index + 1, o[l2])    
   return o
 }
 return true
}
console.time(I)
tmp = addProps(0, tmp)
console.timeEnd(I)

function makeString(o, p = '') {
 if (typeof o === 'boolean') {
   return p
 }
 const key = Object.keys(o)[Math.round(Math.random())]
 return makeString(o[key], p + key)
}
console.time('toStr')
const res = makeString(tmp)
console.timeEnd('toStr')
console.log(res)
console.log(res.length)
источник

S

Syntax Highlight Bot in pro.js
Denis Efremov
function getRandomLetter() {
 return String.fromCharCode((Math.random() * 25 + 97) ^ 0).repeat(4);
}
let tmp = {}
const I = 25
function addProps (index = 0, o = {}) {
 if (index < I) {
   const l1 = getRandomLetter()
   const l2 = getRandomLetter()
   o[l1] = {}
   o[l1] = addProps(index + 1, o[l1])    
   o[l2] = {}
   o[l2] = addProps(index + 1, o[l2])    
   return o
 }
 return true
}
console.time(I)
tmp = addProps(0, tmp)
console.timeEnd(I)

function makeString(o, p = '') {
 if (typeof o === 'boolean') {
   return p
 }
 const key = Object.keys(o)[Math.round(Math.random())]
 return makeString(o[key], p + key)
}
console.time('toStr')
const res = makeString(tmp)
console.timeEnd('toStr')
console.log(res)
console.log(res.length)
источник