Project Euler 176
@see http://projecteuler.net/index.php?section=problems&id=176
♥0 |
Line 54 |
Modified 2010-02-19 17:03:03 |
MIT License
archived:2017-03-30 04:41:00
ActionScript3 source code
/**
* Copyright uwi ( http://wonderfl.net/user/uwi )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/d8yt
*/
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.utils.getTimer;
// @see http://projecteuler.net/index.php?section=problems&id=176
public class Euler176 extends Sprite {
private var _tf : TextField;
public function Euler176() {
_tf = new TextField();
_tf.width = 465;
_tf.height = 465;
addChild(_tf);
var s : int = getTimer();
tr(solve());
var g : int = getTimer();
tr((g - s) + " ms");
}
private function solve() : Number
{
var a:uint, b:uint, c:uint, d:uint, e:uint;
var min : Number = Number.MAX_VALUE;
for(a = 0;a <= 4;a++){ // 5
for(b = 0;b <= 4;b++){ // 7
for(c = 0;c <= 4;c++){ // 11
for(d = 0;d <= 4;d++){ // 13
for(e = 0;e <= 4;e++){ // 19
var base : Array = [1, 1, 1, 1, 1]; // 2, 3, 5, 7, 11
base[a] *= 5;
base[b] *= 7;
base[c] *= 11;
base[d] *= 13;
base[e] *= 19;
var num : Number =
Math.pow(2, (base[0] + 1) / 2) *
Math.pow(3, (base[1] - 1) / 2) *
Math.pow(5, (base[2] - 1) / 2) *
Math.pow(7, (base[3] - 1) / 2) *
Math.pow(11, (base[4] - 1) / 2);
if(num < min){
min = num;
// tr(min, base[0], base[1], base[2], base[3], base[4]);
}
}
}
}
}
}
return min;
}
private function tr(...o : Array) : void
{
_tf.appendText(o + "\n");
_tf.scrollV = _tf.maxScrollV;
}
}
}