-1

i need help in super permutation

i have 3 letters long string "fhd" i want to write each ones alternate in sindhi language but problem is that sindhi language has multiple alternates of each of above letter

so i have 3 list boxes one for each letter's alternates in sindhi each one for sindhi alterate letters and sounds of each string letter from "fhd"

f listbox have 3 items (alternate of f) which are ف، ڦ، په so list one represents alternates of F which are`=ف، ڦ، په items

list two have ح، ه، ھ alternate of h

list 3 have د، ڏ، ڊ alternates of D

the goal is to produce as many words as possible all containing three sindhi alternate letters containing 3 sindhi letters as alternate of english 'fhd'

what my path is write first alternate of f all the times list box f (first listbox) item counts

and in second side all other letters should be represented once

for h=0 to len {fahad}

first set as a=ف b=ه c=د second set as a=ف b=ح c=ڊ third set as a=ف b=ه c=ڏ، the words we made are فهد فحڊ فهڏ

you note ف is repeated all the three times till the third letter alternate of d د، ڊ، ڏis written all three times

the second bunch of words should be ڦهد ڦحڊ ڦهڏ here also second alternate of f ڦ is repeated all three times as usage of alternate of D ڊ، ڏ، د now the second letter h's alternate (which are two) each shold be reapated three times i mean the focus is second letter h's alternates فهد ڦهڊ فهڏ

then second alternate of have three times repeated

فحد ڦحڊ فحڏ

then first alternate of d=د فهد ڦحد فهد

then second alternate of d=ڊ،

فهڊ ڦحڊ فهڊ then third alternate of d=ڏ

فهڏ ڦحڏ ڦهڏ

actually i want to build roman translitration in this case there are more then one alterates of single english letter

i have database of sindhi words in back ground where i want to query all fhd's sindhi alternate words which one would be ok written in db that one replaced in sentences the word list which can be made as alternates of fhd should be

فهد فحڊ فهڏ

ڦحد ڦهڊ ڦحڏ

فهد ڦهڊ فهڏ

ڦحد فحڊ ڦحڏ

فهد ڦحد فهد

ڦحڊ فهڊ ڦحڊ

فهڏ ڦحڏ فهڏ this is the list i want to get, who can help me how to do it programettiaclly

i have done little plane but seems not working, can any or many may convert idea into real php programmng

this is the programing i have done for populating listboxes

<?php

        global $servername;
            global $username;
            global $password;
            global $dbname;


        $servername = "localhost";
        $username = "root";
        $password = "";
        $dbname = "tsrs";
        //////////////////////

        global $q;
        $q=array();

        //////////////////////
        for ($n=0; $n<=strlen("fahad"); $n++){

        $i=substr("fahad", $n, 1);
        //echo $i;

        /////////////////////
        $conn = new mysqli($servername, $username, $password, $dbname);
        // Check connection
        if ($conn->connect_error) {
           die("Connection failed: " . $conn->connect_error);
        } 
        mysqli_set_charset($conn,"utf8");
        $sql = "SELECT * FROM duplicate WHERE engletter='$i' order by id";
        $result = $conn->query($sql);
        global $m;
        $m=1;

        if ($result->num_rows > 0) {
        $altrntcount=$result->num_rows; 


            while($row = $result->fetch_assoc()) {
            $q[$n][$m]=$row['sinletter']    ;
            echo $q[$n][$m]."<BR>";

            $m=$m+1;
            }
            }

        }
        echo "<form>";

        for ($n=0; $n<=strlen("fahad"); $n++){
        $list[$n]="list".$n;
        echo $list[$n];
        echo "
        <select name=\"".$list[$n]."\">";

        for ($m=0; $m<=$altrntcount; $m++){
        if ($q[$n][$m]<>""){
        echo "<option value=\"".$q[$n][$m]."\">".$q[$n][$m]."</option>";

        }

        }
        echo "</select>";
        }
        echo "</form>";

    ?>

    here is the further idea way but needs logical help to run


        for n-0 to len(fhd)

        for  x=0 to 5   loop...... the maximum alternates of any english letter in sindhi are 5

        for w=0 to len(fhd)
        for m-0 to 5 looop
        if m=>list(w).countitems then
        h=0
        word(q)(c)=word(q)(c)+list(w).selectedindex=h
        h=h+1
        end if
        //m=m+1

        w=w+1
        loop
        loop

        if m=>5 then
        x=x+1
        end if
        if w=>len(fhd)
        n=n+1

        end if
        if x=>list(n).countitems then
        p=0

        word(q)=word{q}+list(n).selectedindex=p
        p=p+1
        end if

        loop
        loop
  • If you have 3 alternatives for 1st letter, 2 for 2nd and 3 for 3rd, the number of combinations is 3*2*3 = 18, and it's pretty straight forward, see e.g. [here for php](https://stackoverflow.com/q/8567082) and here [for SQL](https://stackoverflow.com/q/4481396). You get/want just 7 results, but it is not really clear why, so if there are additional rules (just assume we do not know anything about sindhi letters apart from what you specify in your question), you could just calculate all combinations and sieve out the incorrect ones, or make your question clearer. – Solarflare Dec 08 '19 at 08:30
  • And if there is nothing special about sindhi letters and it's more about how to generate combinations in general it might help make your question more readable if you replace the letters with e.g. "A","B","C" or "1","2","3",... For example, even if there is a pretty obvious logic in your list that would explain why it is 7 and not 18 combinations, at least I would probably not see it because all letters look very similar. See e.g. the first link, the op probably doesn't actually want to combine A1 with B1 in his actual problem, but it makes the question easier to understand. – Solarflare Dec 08 '19 at 08:37
  • Solarflare ؛ i have database at my hand containing almost 90% words of sindhi language......so if i have query of all possible words limited to 3 characters long in fhd case alternates so i may search my database all possible words. and database have correct word i will represent it with correct choice فهد – sindhuazahar Dec 08 '19 at 12:02
  • https://stackoverflow.com/questions/59235326/permutation-of-two-columns-in-mysql-table the answer of this question also may solve my problem.... u can see question also like this – sindhuazahar Dec 08 '19 at 12:24

1 Answers1

0

press submit button Twice or three time, how to solve it its an other matter but i have found all permutations of word "fahad" string in sindhi alternate

<?php 


global $servername;
    global $username;
    global $password;
    global $dbname;


$servername = "localhost";
$username = "root";
$password = "";
$dbname = "tsrs";
//////////////////////

global $q;
$q=array();

//////////////////////
for ($n=0; $n<=strlen("fahad"); $n++){

$i=substr("fahad", $n, 1);
//echo $i;

/////////////////////
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
   die("Connection failed: " . $conn->connect_error);
} 
mysqli_set_charset($conn,"utf8");
$sql = "SELECT * FROM duplicate WHERE engletter='$i' order by id";
$result = $conn->query($sql);
global $m;
$m=0;

if ($result->num_rows > 0) {
$altrntcount=$result->num_rows; 


    while($row = $result->fetch_assoc()) {
    $q[$n][$m]=$row['sinletter']    ;
    echo $q[$n][$m]."<BR>";

    $m=$m+1;
    }
    }

}
echo "<form method='post'>";

for ($n=0; $n<=strlen("fahad")-1; $n++){
$list[$n]="list".$n;
echo $list[$n];
echo "
<select name=\"".$list[$n]."\" id=\"".$list[$n]."\">";

for ($m=0; $m<=$altrntcount-1; $m++){
if ($q[$n][$m]<>""){
echo "<option value=\"".$q[$n][$m]."\">".$q[$n][$m]."</option>";

}

}
echo "</select>";  
}?> 
<input type="text" name="leng" id="leng" value="1" ><input type='submit' name='submit'></form>
<?php 
if(isset($_POST['submit'])){

for($i=0; $i<=strlen("fahad")-1; $i++){

    //echo $list[$i]; 





for ($x=0; $x<= $_POST['leng']+1; $x++){

    ?>

    <script>



    document.getElementById("leng").value = document.getElementById("<?php echo $list[$i]; ?>").length;

 </script>
 <?php

    echo $i."-i: I : ".$x.": X <BR>";

    echo $q[$i][$x];

}

}
echo "<h1>".($_POST['leng'])."zzz</h1>";







echo "-----<BR><BR><BR>++++++";



}
    ?>

<?php
global $q;


//$arrStart = array(
 //array('ف', 'ڦ', 'په'),
   // array('ح', 'ه'),
    //array('د', 'ڊ','ڏ')
//);

//$arrStart= $q[$i][$x];
$arrPositions = array();
$arrResult = array();

//get a starting position set for each sub array
for ($i = 0; $i < count($q); $i++)
    $arrPositions[] = 0;

//repeat until we've run out of items in $q[0]
while (array_key_exists($arrPositions[0], $q[0])) {
    $arrTemp = array();
    $blSuccess = true;

    //go through each of the first array levels
    for ($i = 0; $i < count($q); $i++) {
        //is there a item in the position we want in the current array?
        if (array_key_exists($arrPositions[$i], $q[$i])) {
            //add that item to our temp array
            $arrTemp[] = $q[$i][$arrPositions[$i]];
        } else {
            //reset this position, and raise the one to the left
            $arrPositions[$i] = 0;
            $arrPositions[$i - 1]++;
            $blSuccess = false;
        }
    }

    //this one failed due to there not being an item where we wanted, skip to next go
    if (!$blSuccess) continue;

    //successfully adding nex line, increase the right hand count for the next one
    $arrPositions[count($q) - 1]++;

    //add our latest temp array to the result
    $arrResult[] = $arrTemp;

}



    print_r($arrResult);





    if(isset($_POST['submit'])){

for($i=0; $i<=count($arrResult)-1; $i++){

    //echo $list[$i]; 


?>

    <script>



    document.getElementById("leng").value = document.getElementById("<?php echo $list[$i]; ?>").length;

 </script>
 <?php  

for ($x=0; $x<= $_POST['leng']+2; $x++){






    //echo $i."-i: I : ".$x.": X <BR><BR><BR>";

    echo $arrResult[$i][$x];

}
echo "<BR><BR>";
}
echo "<h1>".($_POST['leng'])."zzz</h1>";







echo "-----<BR><BR><BR>++++++";



}
?>