Project Euler 90

by uwi
@see http://projecteuler.net/index.php?section=problems&id=90
♥0 | Line 72 | Modified 2009-06-27 12:26:33 | MIT License
play

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/1LNU
 */

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.utils.getTimer;
    // @see http://projecteuler.net/index.php?section=problems&id=90
    public class Euler90 extends Sprite {
        private var _tf : TextField;
  
        public function Euler90() {
            _tf = new TextField();
            _tf.width = 465;
            _tf.height = 465;
            addChild(_tf);
            
            var s : int = getTimer();
            _tf.appendText(solve().toString() + "\n");
            var g : int = getTimer();
            _tf.appendText((g - s).toString() + " ms\n");
        }
        
        private function solve() : int
        {
            var a : Array = new Array(6);
            var b : Array = new Array(6);
            var sqs : Array = [1, 4, 9, 16, 25, 36, 49, 64, 81];
            var ct : int = 0; 
            
            for(a[0] = 0;a[0] <= 9;a[0]++){
            for(a[1] = a[0] + 1;a[1] <= 9;a[1]++){
            for(a[2] = a[1] + 1;a[2] <= 9;a[2]++){
            for(a[3] = a[2] + 1;a[3] <= 9;a[3]++){
            for(a[4] = a[3] + 1;a[4] <= 9;a[4]++){
            for(a[5] = a[4] + 1;a[5] <= 9;a[5]++){
            for(b[0] = 0;b[0] <= 9;b[0]++){
            for(b[1] = b[0] + 1;b[1] <= 9;b[1]++){
            for(b[2] = b[1] + 1;b[2] <= 9;b[2]++){
            for(b[3] = b[2] + 1;b[3] <= 9;b[3]++){
            for(b[4] = b[3] + 1;b[4] <= 9;b[4]++){
            for(b[5] = b[4] + 1;b[5] <= 9;b[5]++){
                if(a > b)continue;
                var canset : Object = {};
                for(var i : int = 0;i < 6;i++){
                    for(var j : int = 0;j < 6;j++){
                        canset[a[i] * 10 + b[j]] = 1;
                        canset[b[i] * 10 + a[j]] = 1;
                        if(a[i] == 6){
                            canset[90 + b[j]] = 1;
                            canset[b[j] * 10 + 9] = 1;
                        }
                        if(a[i] == 9){
                            canset[60 + b[j]] = 1;
                            canset[b[j] * 10 + 6] = 1;
                        }
                        if(b[j] == 6){
                            canset[a[i] * 10 + 9] = 1;
                            canset[90 + a[i]] = 1;
                        }
                        if(b[j] == 9){
                            canset[a[i] * 10 + 6] = 1;
                            canset[60 + a[i]] = 1;
                        }
                    }
                }
                
                var f : Boolean = true;
                for each(var sq : int in sqs){
                    if(!canset[sq]){
                        f = false;
                        break;
                    }
                }
                if(!f)continue;
                ct++; 
                
                }}}}}}}}}}}}
             return ct;
        }
    }
}