sai-language
Version:
An object-oriented language designed to afford code comprehension and maintenance. Transpiles in-place to Javascript.
100 lines (96 loc) • 3.71 kB
JavaScript
#!/usr/bin/env node
// Javascript source for Impossible.sai transipled by SAI
//
"use strict";
var prototype=new function() {
this.Constructor=function(){};
this.__tobelocked=[];
this.__tobefrozen=[];
this.__contracts=[];
this.__unverified=true;
this.isof={};
return this;
}();
var $AI=require("sai-library");
// Generated code follows
var __context={"name":"Impossible.sai","loader":"SAI.GetSourceFromPaths","path":"Impossible/Impossible.sai","mtime":"2018-02-16T15:04:14.685Z","fetched":"2018-03-01T13:39:08.870Z"};
var _max = 100;
var isa = prototype.isa = 'Impossible';
var $bindfail = function(m) {
throw new Error("SAI: A call to " + m + " on object " + isa + " has come unbound from any instance of that object. (If this is not in error, mark the declaration of " + m + " as unbound.)");
}
prototype.isof['Impossible'] = {
version: '1.0.0',
isa: isa,
context: __context,
type: "main"
};
prototype.__tobelocked = prototype.__tobelocked.concat(["'Instantiate'", "isa"]);
prototype.__tobefrozen = prototype.__tobefrozen.concat(["isof"]);
var $1g = prototype['Instantiate'] || function() {};
prototype['Instantiate'] = function(p) {
var $_d, $_c, $_b, $5, _sgood, _pgood2, _sbad, _pgood, _label, _obj, _Countem, $4, $2, $0, _y, _x, _Candidates, $ = this['Instantiate'] ? this : $bindfail('Instantiate'); {
_Candidates = function*(p) {
{
var _x = 2,
$3 = _max;
for (; _x < $3; _x += 1) {
var _y = (_x + 1),
$1 = _max;
for (; _y < $1; _y += 1) {
if (($0 = (((_x + _y) < _max)))) {
yield({
x: _x,
y: _y,
sum: (_x + _y),
product: (_x * _y)
});
}
}
}
}
};
_Countem = function(p, _label) {
var _obj = p; {
$AI.debug_op('' + _label + ' candidate count: ' + _obj.length);
}
};
_pgood = [];
_sbad = [];
_pgood2 = [];
_sgood = [];
$AI.debug_op('Mathemetician\'s "Impossible" puzzle solver.');
$AI.debug_op(((undefined === ($_c = (($_d = $AI.map_op($AI.observe_op($AI.filter_op(($AI.audit_op($AI.observe_op($AI.filter_op(($AI.audit_op($AI.observe_op($AI.filter_op(($AI.audit_op($AI.audit_op($AI.observe_op($AI.collect_op(_Candidates()), function($_v) {
_Countem($_v, 'Initial');
}), function($_v, $_k) {
_pgood[$_v.product] = (((undefined !== ($_b = _pgood[$_v.product])) ? $_b : 0) + 1);
}), function($_v, $_k) {
if (($5 = ((_pgood[$_v.product] == 1)))) {
_sbad[$_v.sum] = true;
}
})), function($_v, $_k) {
return ((!(_sbad[$_v.sum])));
}), function($_v) {
_Countem($_v, 'Phase 2');
}), function($_v, $_k) {
_pgood2[$_v.product] = (((undefined !== ($_b = _pgood2[$_v.product])) ? $_b : 0) + 1);
})), function($_v, $_k) {
return ((_pgood2[$_v.product] == 1));
}), function($_v) {
_Countem($_v, 'Phase 3');
}), function($_v, $_k) {
_sgood[$_v.sum] = (((undefined !== ($_b = _sgood[$_v.sum])) ? $_b : 0) + 1);
})), function($_v, $_k) {
return ((_sgood[$_v.sum] == 1));
}), function($_v) {
_Countem($_v, 'Results');
}), function($_v, $_k) {
return 'Solution ' + ($_k + 1) + ': X=' + $_v.x + ', Y=' + $_v.y + '; sum=' + $_v.sum + ', product=' + $_v.product
})).join('\n')))) ? $_d : $_c));
}
};
$AI.finalizePrototype(prototype);
if (prototype.isof[prototype.isa].type === "singleton") { prototype.Constructor(); prototype.Instantiate(); }
var result=prototype.isof[prototype.isa].type === "main" ? prototype.constructor() : prototype;
exports=result; try { module.exports=result; } catch(e) {};
return result;