notice: Flash editor updated! Join the development! Thanks to MiniBuilder


embed

FORKED

IMO 1960 Problem 01 IMO 1962 Problem 01 [diff(29)]

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- forked from _ex_'s IMO 1960 Problem 01 -->
  3. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
  4.                 width="480" height="360" backgroundColor="#FFFFFF" xmlns="*">
  5.     <mx:ApplicationControlBar dock="true" width="100%">
  6.         <mx:Label id="lblProblem" x="10" y="10" width="380" height="140">
  7.             <mx:text>
  8.             <![CDATA[
  9.      IMO 1962 Problem 01
  10.      Find the smallest natural number n which has the following
  11.      properties:
  12.      (a) Its decimal representation has 6 as the last digit.
  13.      (b) If the last digit 6 is erased and placed in front of
  14.          the remaining digits, the resulting number is four
  15.          times as large as the original number n.
  16.             ]]>
  17.             </mx:text>
  18.         </mx:Label>
  19.         <mx:Button id="btnSolve" x="395" y="115" click="solve();" label="Solve!" />
  20.     </mx:ApplicationControlBar>
  21.     <mx:Script>
  22.         <![CDATA[
  23.             public function solve():void {
  24.                 txtResult.text = "";
  25.                 var k:int = 1;
  26.                 var k_up:int = 10;    // Minimum (10^p) greater that k.
  27.                 while (true) {
  28.                     var n:int = (10 * k) + 6;
  29.                     var m:int = (6 * k_up) + k;
  30.                     // Check
  31.                     if (m == 4 * n) {
  32.                         txtResult.text += "ANSWER: " + n;
  33.                         break;
  34.                     }
  35.                     ++k;
  36.                     if (k >= k_up) {
  37.                         k_up *= 10;
  38.                     }
  39.                 }
  40.             }
  41.         ]]>
  42.     </mx:Script>
  43.     <mx:TextArea id="txtResult" x="5" y="15" width="470" height="190" />
  44. </mx:Application>
noswf
Get Adobe Flash Player