Calculations - help needed

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
neutrox
Posts: 194
Joined: 05 Mar 2012 15:23

Calculations - help needed

Post by neutrox »

Hi.
I'm working on a code to select a number of files, skipping a certain amount and selecting the given number again and so on.

Having a total of files, the total of files on each pack and the skipped files once a pack is completed
I'd like to know in advance:
how many sets it's expected I'll end with?
how many skipped files?
how many remainders?

So how to calculate?

For example a total of 26 files:

Packs of 4 (known nr) files skipping each 2 (known nr) I'll get 4 sets (total of skipped: 10 files, 2 * 4 + 2 remainders)

Packs of 5 (known nr) files skipping each 3 (known nr) I'll get 3 sets (total of skipped: 11 files, 3 * 3 + 2 remainders)

Packs of 7 (known nr) files skipping each 4 (known nr) I'll get 2 sets (total of skipped: 12 files, 2 * 4 + 4 remainders)

After a couple of hours I decided to ask for help. Hope you understand.

highend
Posts: 13317
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Calculations - help needed

Post by highend »

Hope you understand
I'm not sure...

Code: Select all

  $totalFiles = 25;
  $packFiles = 5;
  $skipFiles = 3;
  $remainders = 0;
  $skipped = 0;
  $sets = 0;

  $sets = $totalFiles / ($packFiles + $skipFiles);
  $sets = gettoken($sets, 1, ".");
  
  $remainders = ($totalFiles % (($packFiles + $skipFiles) * $sets));
  $skipped = ($skipFiles * $sets) + $remainders;
  text "Sets: " . $sets . <crlf> . "Skipped files: " . $skipped . <crlf> . "Remainders: " . $remainders;
  
One of my scripts helped you out? Please donate via Paypal

neutrox
Posts: 194
Joined: 05 Mar 2012 15:23

Re: Calculations - help needed

Post by neutrox »

I have tested your code, highend, and it differs from actual results made by:

Code: Select all

//shame: prediction code, beta: $p = 1; $a = 1; $z = 26; $r = ""; $top = 1; while($a <= $z) { if($top <= 4) { $p++; } elseif($top > 4) { $stop = 1;  } $top++; $a++; } echo $p+1;
//work = total - curpos - 1;

   end(getinfo("CountSelected") < 1), "Pick a file first!";
   end(getinfo("CountSelected") > 1), "Only one!!";

   $pack = "6"; // number of files that will be selected in each pack
   $skip = "2"; // skips - minimum value is "1";

   if ($skip < 1) { end 1, "Ended: Value '$skip' is not valid as a skip!"; }
   elseif ($skip >= 1) {   }

   $first = get("focusedpos");

   sel a;
      $lines = get(selecteditemspathnames);

   $total = gettoken($lines, count, "<crlf>");

   $container = "";
   sel $first;
   $skipscontrol = $skip;
   $skip = $skip + 1; // shame
   $skips = 0;
   $ctrl = 1;
   WHILE ($ctrl <= $total) {

   sel +, $pack;
   $linesdo = get(selecteditemspathnames);
   $container = "$container" . "$linesdo<crlf>";

   $last = gettoken($linesdo, $pack, "<crlf>");
   selectitems ($last);

   sel "+$skip"; // skip 2 - sel "+3"; skip 5 - sel "+6";

   $skips = $skips + $skipscontrol; // shame

//debug===================
/*
   $test = get("focusedpos");
   if ($test > 279) { step; }
   elseif ($test <= 279) {   }
*/

   if ($mark != 1) { $total = $total - $pack; $mark = 1; }
   elseif ($mark == 1) {   }

   $ctrl = get("focusedpos"); // shame
                        }

   selectitems ("$container");
   #1048; // focus 1st item
   echo "Skipped approx. $skips items. Check carefully the end of the list!";
The prediction part also could be used to improve the last package handling as my current code totally fails on certain occasions like the relation between total of files not being a multiple of packs and skips.

If you or someone else happen to have a variant that could be used please share.

highend
Posts: 13317
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Calculations - help needed

Post by highend »

Show me some values that your are using and what my code calculates from them.
One of my scripts helped you out? Please donate via Paypal

Muroph
Posts: 561
Joined: 21 Aug 2007 16:13

Re: Calculations - help needed

Post by Muroph »

try this

Code: Select all

$in=input("Parameters","<total>,<pack>,<skip>");
  $total=gettoken($in,1,",");
  $pack=gettoken($in,2,",");
  $skip=gettoken($in,3,",");
  $n=gettoken($total/($pack+$skip).".",1,".");
  $r=$total-(($pack+$skip)*$n);
  $sk=$n*$skip+$r;
  text <<<OUT
Total=$total
Pack=$pack
Skip=$skip

Sets=$n
Skipped=$sk
Remainder=$r
OUT
My shared scripts:
TeraCopy Integration, Tag Manager, Comments Menu, Text Replacer, Image and Media Tools, Checksum Calculator, Video Calculator
only 5 URLs are allowed on the sig...

neutrox
Posts: 194
Joined: 05 Mar 2012 15:23

Re: Calculations - help needed

Post by neutrox »

parameters: total, packs, skips, remainders
actual code: 27, 3setsx6, 2x2, 5 remainders (2 of which are skips)
muroph code: 27, 3setsx6, 2x9, 3 remainders
highend cod: 27, 3setsx6, 2x9, 3 remainders

actual code: 27, 2setsx4+1setx7, 5x2, 2 remainders
muroph code: 27, 3setsx4, 5x15, 0 remainders
highend cod: 27, 3setsx5, 5x15, 0 remainders

total of files, sets x files, stated x sets of skips, remainders

As stated my code is failing in forming the last set of files which impacts in skips calculation. Please help.

Fresh code for the selection containing precise predictions prior to actual packaging is acceptable, of course.

highend
Posts: 13317
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Calculations - help needed

Post by highend »

I have absolutely no idea what you're talking about.

My code computes the values that you provided in the first post.
actual code: 27, 2setsx4+1setx7, 5x2, 2 remainders
to select a number of files, skipping a certain amount and selecting the given number again and so on.
What? You wanted a script to select repeating blocks of files. Since when does this include a non repeating (+1setx7) block???
One of my scripts helped you out? Please donate via Paypal

neutrox
Posts: 194
Joined: 05 Mar 2012 15:23

Re: Calculations - help needed

Post by neutrox »

That's why I asked:
As stated my code is failing in forming the last set of files which impacts in skips calculation. Please help.
This is all i could came up with, it is failing and the initial calculations are important for the user.
Sorry for some confusion, pal...

Post Reply