NikitosKnyaz Posted September 22 Share Posted September 22 the program must be solved using cycles. starts with (1/2). Quote Link to comment https://forums.phpfreaks.com/topic/324183-how-to-calculate-a-certain-number-of-times-a-fraction/ Share on other sites More sharing options...
Barand Posted September 22 Share Posted September 22 Here's a cycle you can use to do your homework Quote Link to comment https://forums.phpfreaks.com/topic/324183-how-to-calculate-a-certain-number-of-times-a-fraction/#findComment-1635700 Share on other sites More sharing options...
NikitosKnyaz Posted September 22 Author Share Posted September 22 Seriously? Quote Link to comment https://forums.phpfreaks.com/topic/324183-how-to-calculate-a-certain-number-of-times-a-fraction/#findComment-1635701 Share on other sites More sharing options...
Barand Posted September 22 Share Posted September 22 If it's your homework assignment, yes. If it isn't, what have you tried so far? Quote Link to comment https://forums.phpfreaks.com/topic/324183-how-to-calculate-a-certain-number-of-times-a-fraction/#findComment-1635702 Share on other sites More sharing options...
jodunno Posted September 23 Share Posted September 23 you're supposed to recreate a paper with fake math problems? well, why don't you just scan it? maybe we can use html and svg to recreate the paper. You'll have to draw the svg arrows yourself, i have no time for that or the squiggly scribble. <html> <head> <title>paper tigers</title> <style> body { font-family: "Helvetica", "Open Sans", "Arial Narrow", sans-serif; } span.circled { padding: 1px; border: solid 1px #000000; border-radius: 50%; } div.textForm { display: inline-block; position: absolute; top: 3em; left: 16em; width: 8em; height: auto; } .invisibleInput { margin: 2px; width: 6em; height: 1.2em; border: solid 4px #000000; border-radius: 30%; } .htmlform { display: inline-block; text-indent: 1em; } .submit { display: inline-block; position: absolute; left: 2em; width: 3.5em; padding: 4px; border: solid 4px #000000; } .babold { font-weight: bold; } .parity { margin-left: 13em; font-family: "Arial Narrow", sans-serif; font-size: 0.9em; } .penned { font-family: "Comic Sans MS", "Open Sans", "Arial", sans-serif; color: #5c4ea1; } th, td { padding: 0px 3px; font-family: "Comic Sans MS", "Open Sans", "Arial", sans-serif; color: #5c4ea1; } .divider { margin: 0px; padding: 0px; width: 100%; height: 1px; background: #5c4ea1; } .th { font-weight: normal; } </style> </head> <body> <?php echo '<div class="textForm"><div class="babold htmlform">html form</div>'.PHP_EOL; echo '<div class="invisibleInput"></div>'.PHP_EOL; echo '<div class="babold submit">submit</div></div>'.PHP_EOL; $n = 3; $nm = $n-1; function numerator(int $n = 0, int $circled = 0) { if ($n === 1) { return 1; } $numerator = array (); $n*= 2; $nm = $n-1; for ($i = 1; $i < $n; $i+=2) { if ($circled && $i===$nm) { $numerator[] = '<span class="circled">'.$i.'</span>'; continue; } $numerator[] = $i; } return join('.', $numerator); } function denominator($n) { if ($n === 1) { return 2; } $denominator = array (); $n*= 2; for ($i = 2; $i <= $n; $i+=2) { $denominator[] = $i; } return join('.', $denominator); } echo '<p class="babold">limit fraction</p>'.PHP_EOL; echo '<p class="penned">N = 3</p>'.PHP_EOL; /* $_POST['n'] = 3 ///////////////////////////////////////////////////////////////////////*/ $numerators = array(); $denominators = array(); for ($i = 1; $i <= $n; $i++) { $numerators[] = numerator($i, 0); $denominators[] = denominator($i); } echo '<table>'; echo '<tbody>'; echo '<tr>'; echo '<td>S = </td>'; for ($i = 0; $i < $n; $i++) { echo '<td><table><tr><td>' . $numerators[$i] . '</td></tr><tr><td class="divider"></td></tr>' . '<tr><td>' . $denominators[$i] . '</td></tr></table>' . (($i===$nm) ? '</td><td>=</td>':'</td><td>+</td>').PHP_EOL; } echo '</tr>'; echo '</tbody></table>'.PHP_EOL; echo '<span class="babold parity">in each new fraction the number increases by "2".</span>'.PHP_EOL; /* $_POST['n'] = 4 ///////////////////////////////////////////////////////////////////////*/ $n = 4; $nm = $n-1; $numerators = array(); $denominators = array(); for ($i = 1; $i <= $n; $i++) { $numerators[] = numerator($i, 1); $denominators[] = denominator($i); } echo '<table>'; echo '<tbody><thead><th class="th">N = 4</th></thead>'; echo '<tr>'; echo '<td>S = </td>'; for ($i = 0; $i < $n; $i++) { echo '<td><table><tr><td>' . $numerators[$i] . '</td></tr><tr><td class="divider"></td></tr>' . '<tr><td>' . $denominators[$i] . '</td></tr></table>' . (($i===$nm) ? '':'</td><td>+</td>').PHP_EOL; } echo '</tr>'; echo '</tbody></table>'.PHP_EOL; /* $_POST['n'] = 5 ///////////////////////////////////////////////////////////////////////*/ $n = 5; $nm = $n-1; $numerators = array(); $denominators = array(); for ($i = 1; $i <= $n; $i++) { $numerators[] = numerator($i, 0); $denominators[] = denominator($i); } echo '<table>'; echo '<tbody><thead><th class="th">N = 5</th></thead>'; echo '<tr>'; echo '<td>S = </td>'; for ($i = 0; $i < $n; $i++) { echo '<td><table><tr><td>' . $numerators[$i] . '</td></tr><tr><td class="divider"></td></tr>' . '<tr><td>' . $denominators[$i] . '</td></tr></table>' . (($i===$nm) ? '':'</td><td>+</td>').PHP_EOL; } echo '</tr>'; echo '</tbody></table>'.PHP_EOL; ?> </body></html> and, honestly, this is the worst code that i could think of. I hope that you fail 🙂 cheating gets you nowehere, unless you're bodybuilding. The Arnold cheat is quite good. I gained 2 inches using the Arnold cheat. Quote Link to comment https://forums.phpfreaks.com/topic/324183-how-to-calculate-a-certain-number-of-times-a-fraction/#findComment-1635737 Share on other sites More sharing options...
Barand Posted September 23 Share Posted September 23 I gained four inches just by giving up rugby, squash and badminton. 1 Quote Link to comment https://forums.phpfreaks.com/topic/324183-how-to-calculate-a-certain-number-of-times-a-fraction/#findComment-1635739 Share on other sites More sharing options...
jodunno Posted September 23 Share Posted September 23 11 minutes ago, Barand said: I gained four inches just by giving up rugby, squash and badminton. you, Sir, have a wonderful sense of humour. I like you 🙂 Quote Link to comment https://forums.phpfreaks.com/topic/324183-how-to-calculate-a-certain-number-of-times-a-fraction/#findComment-1635743 Share on other sites More sharing options...
Barand Posted September 27 Share Posted September 27 I'm guessing the assignment deadline has passed, so for the sake of others reading the thread, here's one solution... <?php $a = 1; $b = 2; $c = []; $d = []; $N = 8; $tdata1 = $tdata2 = ""; $vals = []; for ($i=1, $a=1, $b=2; $i<=$N; $i++, $a+=2, $b+=2) { $c[] = $a; $d[] = $b; $exp = '<u>' . join('.', $c) . "</u><br>" . join('.', $d); $tdata1 .= "<td>$exp</td>"; $val = number_format(array_product($c) / array_product($d), 5) ; $tdata2 .= "<td>$val</td>"; } ?> <table border='1'> <tr><th>Fraction</th> <?=$tdata1?> </tr> <tr><th>Decimal</th> <?=$tdata2?> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/324183-how-to-calculate-a-certain-number-of-times-a-fraction/#findComment-1636347 Share on other sites More sharing options...
jodunno Posted September 27 Share Posted September 27 an html table is not a good idea if n > 16. Even lists surrender to the spatial demands. Here is my take on the matter. I work off of the old saying, "2 plus 2 is 4". <?php $n = (int) 5; /* $_POST['n'] from <input type="number" name="n"> */ $fourSure = function($x) { $i = $j = (int) 2; $e = array(); $e['d'] = $e['n'] = array(); for (; $x > 0; $x--) { for (; $i < $x; $i+=2, $j+=4) { $e['n'][] = $j >> 1; $e['d'][] = $i; }} return join('·', $e['n']) . ' ÷ ' . join('·', $e['d']); }; $n = $n*2+2; echo '<ul style="font-family: sans-serif; list-style-type: none;">S = '; for ($i=4; $i <= $n; $i+=2) { echo '<li>'.$fourSure($i).'</li>'; } echo '</ul>'; ?> to each his own. Quote Link to comment https://forums.phpfreaks.com/topic/324183-how-to-calculate-a-certain-number-of-times-a-fraction/#findComment-1636360 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.