DeyaEldeen DeyaEldeen - 3 months ago 7
PHP Question

how to construct an SQLite3 database with all possible words with 3 letters?

say I need to build a database with all possible 3 letters combinations

AAA|ABA|ACA|...
AAB|ABB|ACB|...
AAC|ABC|ACC|...
...|...|...|...


what is the approach to do that?

~ a mac can run python or php, so any of these 2 languages would be more preferred, thanks.

Answer

If you're only after A-Z then you can simply use a 3-level for loop, example

<?php

for ($x=65; $x<=91; $x++) {
    for ($y=65; $y<=91; $y++) {
        for ($z=65; $z<=91; $z++) {
            $chars = chr($x).chr($y).chr($z);
            // persist to database
        }
    }
}

These aren't words, just every possible combination of 3 A-Z characters

Comments