Page 1 of 1

Help - alternate capitalization

Posted: 20 Jul 2015 02:13
by SkyFrontier
I'm trying to script a snippet which generates sequenced variations with alternated capitalization.

Code: Select all

a
A
aa
aA
Aa
AA
aaa
Aaa
aAa
aaA
AAa
aAA
AaA
AAA
The order is not important. This is valid, too:

Code: Select all

a
aa
aaa
aaaa
A
aA
aaA
aaaA
AA
aAA
aaAA
AAA
aAAA
AAAA
...
Key is: a variable indicating the maximum length for the string sequence, in case 3 for the 1st list, 4 for the second.
I just can't find a working logic to script it.
Please.

Re: Help - alternate capitalization

Posted: 20 Jul 2015 21:33
by totmad1
Hi
Don't know if this will be of any use to you.

Code: Select all

        $num = 3;
         $bin="2+ 4+ 8+ 16+ 32+ 64+ 128+ 256+ 512+ 1024";
         $sellist= gettoken($bin, $num, "+", t, 1);
          $count1= eval($sellist);
  //  Up to here is fine - first line is max length of string.
  //       $count1 = number of non repeated combinations possible.
  //   After was a way of creating binary numbers - not what you want.
  //   At this point in the past i've tried to use arrays unsuccessfully.
                  $count1=$count1 - 1; $lst="";
         while( $count1>0){
           $i= $count1;
          while($i> 0){
          $cvt= $i % 2;
          $lst= "$lst $cvt " ;
          $i= floor($i / 2);
            }
          $count1=$count1 - 1;
          if ($count1==0){
             $lst= "$lst <crlf> 0";
             }
          else{
          $lst= "$lst <crlf>";
          }
            }
              text $lst;

Re: Help - alternate capitalization

Posted: 20 Jul 2015 22:12
by SkyFrontier
You again. :lol:
(take a look at this, if you already haven't!)
Well, it's something to think about. It SEEMS to be in the right direction, totmad1. I'll work on it later and post any solution I may come with (will try to dumbly revert numbers into proper cased alphas - regexreplace).
Also, will try to automate the progression table - as well as other thing I missed in the meantime I stopped writing this, sorry... :oops:
And again: thanks much! :cup:

Re: Help - alternate capitalization

Posted: 20 Jul 2015 22:36
by SkyFrontier
Done.
-still have to perform a check code (or visual checking, which I don't rely... maybe a simple formatlist(sde) will suffice...???), but it seems this is right - yet dirty:

Code: Select all

            $num = 5;

   $max = 1023;
   $bin = 2;
   $tk = 2;
// step;
   while ($tk < $max) {
   $fct = 2;
   $tk = $tk * $fct;
   $bin = $bin . "+ " . $tk;
                      }

   $bin = trim($bin, "+ ");
//             $bin="2+ 4+ 8+ 16+ 32+ 64+ 128+ 256+ 512+ 1024";
             $sellist= gettoken($bin, $num, "+", t, 1);
              $count1= eval($sellist);
      //  Up to here is fine - first line is max length of string.
      //       $count1 = number of non repeated combinations possible.
      //   After was a way of creating binary numbers - not what you want.
      //   At this point in the past i've tried to use arrays unsuccessfully.
                      $count1=$count1 - 1; $lst="";
             while( $count1>0){
               $i= $count1;
              while($i> 0){
              $cvt= $i % 2;
              $lst= "$lst $cvt " ;
              $i= floor($i / 2);
                }
              $count1=$count1 - 1;
              if ($count1==0){
                 $lst= "$lst <crlf> 0";
                 }
              else{
              $lst= "$lst <crlf>";
              }
                }
   $lst = regexreplace("$lst", "1", "A");
   $lst = regexreplace("$lst", "0", "a");
   $lst = regexreplace("$lst", " ", "");

                  text $lst;
edit: No. SDE is not the way. Doc: " Duplicates are matched case-insensitive (A==a). " :|
edit 2: No. It's missing some desired results. :cry:
I'll try to tweak it more and see what happens. Thanks.

Re: Help - alternate capitalization

Posted: 20 Jul 2015 23:11
by FluxTorpedoe
Hi'
Here's one ugly convoluted —but working— script (while waiting for someone to post a proper one):

Code: Select all

  set $lst;
  foreach($j, "2|4|8"){
    set $i;
    $a = ($j<4)? "property" : "";
    $b = ($j<8)? "property" : "";
    while($i++ < $j){
      $lst = $lst.eval($b($i/4%2)).eval($a($i/2%2)).$i%2."<crlf>";
    } 
  }
  $lst = regexreplace("$lst", "1", "A");
  $lst = regexreplace("$lst", "0", "a");
  text $lst;
With a length of 4:

Code: Select all

  set $lst;
  foreach($j, "2|4|8|16"){
    set $i;
    $a = ($j<4)? "property" : "";
    $b = ($j<8)? "property" : "";
    $c = ($j<16)? "property" : "";
    while($i++ < $j){
      $lst = $lst.eval($c($i/8%2)).eval($b($i/4%2)).eval($a($i/2%2)).$i%2."<crlf>";
    } 
  }
  $lst = regexreplace("$lst", "1", "A");
  $lst = regexreplace("$lst", "0", "a");
  text $lst;
Note: the eval(property()) is just a dirty way to blank-out the first digits when unneeded.

Hope this helps, 8)
Flux

Re: Help - alternate capitalization

Posted: 20 Jul 2015 23:29
by SkyFrontier
Hi there, Flux!

It works, it seems to work 5x5.
Only problem is, by past experiences*, I may not be able to convert it into a flexible solution, ie, being able to shove any number of string lengths into an initial variable.
Will try, tho...

Thanks much!

_________
*Reference: Dynamically Created Variables and Values Attribution

Re: Help - alternate capitalization

Posted: 20 Jul 2015 23:44
by Marco
I don't know if I'm reinventing the wheel.
If you can write proper bintodec() and dectobin() user functions then it's

Code: Select all

 $length = 3;

 $permutations = "";
 $top_counter = 1;

 while ($top_counter <= $length) {
  $counter = 0;
  $format = strrepeat("0", $length);
  $max = bintodec(strrepeat("1", $length));

  while ($counter <= $max) {
   $string = format(dectobin($counter), $format);
   $permutations = $permutations . $string . <crlf>;
  };
 };

  $permutations = regexreplace($permutations, 1, A);
  $permutations = regexreplace($permutations, 0, a);

Re: Help - alternate capitalization

Posted: 21 Jul 2015 05:18
by SkyFrontier
Hello, Marco.

Once I played with bin 2 dec 2 bin and I recall one of them was error-prone. If someone has such a code, I'd like to ask for a release.

Also, hex 2 dec 2 hex: same thing, one was accurate, another was not. Please.

Thanks for the contribution. :beer:
(hey, where's the Archive? My dropbox is now plenty of space! :roll: :wink: )

@FluxMissile:

Well, well... I forgot I learned some tricks over time, so...

Code: Select all

// as Leo Cohen would say, "aaaah!, the wonders of a Load()..." :P

//============== test tool, beta:
//$tst = formatlist(<clipboard>, c, <crlf>); $otkCNT = gettoken($tst, count, <crlf>); $tst = formatlist($tst, d, <crlf>); echo "original:          $otkCNT<crlf>" . "now it haves: " . gettoken($tst, count, <crlf>) . " items.";

       $max = 102; // needed for reference progression table

   $LalphaU = "A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z";

   status "$max items on the go. Cya!";

       $bin = 2;
       $tk = 2;

       while ($tk < $max) {
       $fct = 2;
       $tk = $tk * $fct;
       $bin = $bin . "|" . $tk;
                          }
   $re = "";
   $reX = "";



       $bin = trim($bin, "|");
   $tt = gettoken($bin, count, "|");

   $a1 = <<<#
   set $lst;
   foreach($j, "$bin"){
   set $i;
#;
   $a3 = '    while($i++ < $j){' . "<crlf>";

   foreach($tk1, "$bin", "|") {

   if($tk == "") { step; break; }
   else {  }
   $tk = $tk1 * 2; // lazy fix
   $tst = gettoken($bin, -1, "|");
   $tst2 = strpos("$bin", "$tk");
   if($tst2 == "-1") { break; }
   else {  }

   $op++;

   $reX = '.eval($' . gettoken($LalphaU, $op, "|") . '($i/' . "$tk1" . '%2))' . "$reX";
   
   $z = '   $' . gettoken($LalphaU, $op, "|") . " = ($j<" . "$tk" . ")? " . quote("property") . " : " . quote("") . ";";
   $re = "$re" . "$z" . "<crlf>";
                              }
   $a2 = "$re" . "<crlf>";
   $a4 = '      $' . 'lst = $' . lst . "$reX" . '.$' . 'i' . '%' . '2.' . quote('<crlf>') . ';';
   $a5 = "<crlf>                    }" . "<crlf>                                    }" . "<crlf>" . '   $' . 'lst = regexreplace("$' . 'lst", ' . quote("1") . ', ' . quote("A") . ');' . "<crlf>";
   $a6 = '   $' . 'lst = regexreplace("$' . 'lst", ' . quote("0") . ', ' . quote("a") . ');' . "<crlf>";

   $a7 = "<crlf>" . '   status "done!"; text ' . quote("$" . 'cnt items:<crlf 2>$' . 'tst') . ";" . '   status "";';

   $a7c = "<crlf>" . '   $' . 'tst = gettoken($' . 'lst, $' . 'max, <crlf>, , 1);';
   $a7d = "<crlf>" . '   $' . 'cnt = gettoken($' . 'tst, count, <crlf>);';
   $a7A = "<crlf>" . '   $' . 'max = ' . "$max" . ';';
   $a8 = "$a1" . "$a2" . "$a3" . "$a4" . "$a5" . "$a6" . "$a7A" . "$a7c" . "$a7d" . "$a7";

   wait 1000;
   if($max <= "1023") {
   status "Please wait..."; wait 1000;
                      }
   else { beep 800,100; status "Please wait, this WILL take a time!", "FF0000", "alert"; }
   load $a8, , s;
I just couldn't produce a reliable test code but for rude analysis on the smaller segments, all seems ok. (If someone can help with a uniqueness token verification code, case-sensitive, please do so!)

Re: Help - alternate capitalization

Posted: 21 Jul 2015 13:53
by bdeshi
SkyFrontier wrote:Once I played with bin 2 dec 2 bin and I recall one of them was error-prone. If someone has such a code, I'd like to ask for a release.
these should be enough for this case:

Code: Select all

//lite conversion: unsigned, no fractions, no funny business
FUNCTION dectobin($d){ set $b; while ($d != 0){$b = ($d%2).$b; $d = floor($d/2);} return $b; }
FUNCTION bintodec($b){ $l=strlen($b); $i=0; while ($i < $l){$d=$d + (2^($l-$i-1))*substr($b,$i,1); $i++;} return $d; }
although I think the same functions (but more fleshed out) have been already posted here somewhere... hmm.

Re: Help - alternate capitalization

Posted: 21 Jul 2015 17:17
by SkyFrontier
Thanks, Sammay!
Will try to find it later.
Do you happen to have any hex/dec pair in the sleeve...?

Re: Help - alternate capitalization

Posted: 21 Jul 2015 19:35
by bdeshi
There's a hextodec and a hextobin function here http://www.xyplorer.com/xyfc/viewtopic. ... 22#p122093