在php麻烦中使用数学

时间:2018-04-14 15:32:17

标签: javascript php jquery math

编辑2:见下文。如果用javascript或jquery可以实现这一点,我愿意走那条路。

我正在开展一个项目,到目前为止一切都在游泳,直到我进入数学墙。

目前我们通过逆向工程手工解决了一个我们已经知道答案的数字(2114),但我们每个人的工作方式略有不同,有时因为我们都不是很好如果计算器略有不同,我们总会得到结果。因此需要能够解决问题的东西。并将其添加到我们的Intranet。

任何帮助解决这个问题都会很棒。谢谢。 <击> 规则;

<击>

获取590之间的数字(差距) - &gt; 4500

计算出Panel&amp; amp;的尺寸。使用以下规则填补这一空白所需的填充;

面板必须=奇数

填充(如果需要)必须=偶数&amp;数量不超过面板数量<1。

面板的最小尺寸= 590 面板的最大尺寸= 705

填充的最小尺寸= 75 填充的最大尺寸= 175

以下是我到目前为止的情况,这是我的第13次尝试。

编辑:这段代码“适用于某一点”,但是(间隙)越大,我得到的越多和迷茫,代码越长,看似多余。我觉得有一个方程式可以用两行来完成它但是在这里我写了几百行来回走动,最后遗漏了一些东西,或者只是简单的错误。并且是的,只需要尽可能少的面板和填充(在尺寸指南内)填补空白。

$max_size = 705;

$min_size = 590;

$panel_qty = 3;
$infill_qty = 0;

$infills_max = 150;
$infills_min = 50;

$cut_off = 0;

$gremain = 0;


// devide by panels #

$gap = $new_width / $panel_qty;

// check if gap too big
    if ($gap > $max_size) {

        $infill_qty = 2;

        // get difference between gap and max_size
        $gremain = ($panel_qty * ($gap - $max_size)) / $infill_qty;

            // makesure gremain is higher then infills min
            if ($gremain < $infills_min) {
                //cut off from panels

                $gremain_total = $gremain * 2;

                $cut_off = $gremain_total / 6;

                $small_cut_off = $cut_off;
                $large_cut_off = $cut_off;

                if ($cut_off < 10) {
                    $small_cut_off = 0;
                    $large_cut_off = $gremain_total / 2;
                }

                $infill_qty = 0;

            } elseif ($gremain > $infills_max) {
                // more infills

                $infill_qty = 4;

                $gremain = ($panel_qty * ($gap - $max_size)) / $infill_qty;

                    if ($gremain < $infills_min) {
                    //cut off from panels

                        $down_size = ($gremain * 4) - ($infills_min * 2);

                        $gremain_total = $down_size * 2;

                        $cut_off = $gremain_total / 6;

                        $small_cut_off = $cut_off;
                        $large_cut_off = $cut_off;

                        if ($cut_off < 10) {
                            $small_cut_off = 0;
                            $large_cut_off = $gremain_total / 2;
                        }

                        $gremain = $down_size / 2;

                        $infill_qty = 2;

                    } elseif ($gremain > $infills_max){


                        if ($gremain < 410) {

                            // cut off panels

                            $gremain_total = $gremain * 2;

                            $cut_off = $gremain_total / 6;

                            $small_cut_off = $cut_off;
                            $large_cut_off = $cut_off;

                            if ($cut_off < 10) {
                                $small_cut_off = 0;
                                $large_cut_off = $gremain_total / 2;
                            } 

                        } elseif ($gremain > 410) {
                            // more panels
                        }
                    }

            }

    }


}

<击>

编辑2: 规则;

获取590之间的数字(差距) - &gt; 4500

计算出Panel&amp; amp;的尺寸。使用以下规则填补这一空白所需的填充;

小组必须=奇数(除非它是2,所以1,2,3,5,7,9)

填充(如果需要)必须=偶数&amp;除非面板数量为1或2

,否则数量不超过面板数量不超过1,但不超过面板数量

面板的最小尺寸=面板的最大尺寸640 = 705

填充的最小尺寸= 75填充的最大尺寸= 175 (填充最大/分钟有一些空间但不多)

基本上这就是我的需要:

width = panel-width * panel-quantity + infill-width * infill-quantity

我输入'宽度',它将输出4个值; '面板宽度,面板数量,填充宽度,填充量'

下面是我目前的(第16次)尝试,它可以达到一定程度,但一旦数字开始超过3000或低于2000,这一切似乎都非常错误。

// input - 3 for adjustment
$new_width = 2515 - 3;

$un_cut = 740;

$max_size = 705;

$min_size = 640;

$infills_max = 175;
$infills_min = 75;

$cut_off = 0;

$gremain = 0;

$small_cut_off = 0;
$large_cut_off = 0;
$d1ginw = 0;
$d1ginqty = 0;

$infill_size = 0;


// see how many max size penls fit
$gpanels = floor($new_width / $max_size);
    // make sure odd number
    if ($gpanels < 3){
        // its cool
    } elseif ($gpanels % 2 == 0){
        $gpanels = $gpanels - 1;
    }

// get remainer
$gremain = floor($new_width - ($gpanels * $max_size));

// check if panels can be cut down alone or need infills
$infill_check = floor($gremain / ($infills_max - $infills_min));

    // make sure odd number
    if ($infill_check == $gpanels){
        if ($gpanels < 3){
            // all good
        } else {
            $infill_check = $infill_check - 1;
        }
    }

    if ($infill_check > $gpanels) {
        // needs infills
    } elseif ($infill_check < $gpanels) {
        // cut panels only
        $cut_off = $gremain / ($gpanels * 2);

        // make sure cut off not too small
        if ($cut_off < 10) {
            $small_cut_off = 0;
            $large_cut_off = $gremain / 2;
        } elseif ($cut_off > 65) {
            // need infills too
            $infill_qty = 1;

            $infill_size = $gremain * $infill_qty;

                if ($infill_size > $infills_max) {

                    $infill_qty = 2;

                    $infill_size = $gremain * $infill_qty;

                        if ($infill_size > $infills_max) {

                            // check how much over




                        }

                } elseif ($infill_size < $infills_min) {

                    // get remainder
                    $left_after_infill = $gremain - ($infills_min * $infill_qty);

                    $infill_qty = 1;
                    $infill_size = $infills_min;

                    $cut_off = $left_after_infill / $gpanels;

                    if ($cut_off < 10) {
                        $small_cut_off = 0;
                        $large_cut_off = $gremain_total / 2;
                    }

                }


        }

        $small_cut_off = $cut_off; // move
        $large_cut_off = $cut_off; // move

    }


if ($infill_size == 0) {$d1ginw = $infill_size;} else {$d1ginw = $infill_size + 35;}

$d1ginqty = $infill_qty;


$d1gsmlsize = floor(($un_cut - ($max_size + 35)) / 2 + $small_cut_off);
$d1glrgsize = floor(($un_cut - ($max_size - 5)) / 2 + $large_cut_off);

$d1gsmlqty = $gpanels - 1;
$d1glrgqty = 1;

0 个答案:

没有答案