New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SEND + MORE = MONEY #78

Closed
williamwsmith opened this Issue Sep 25, 2013 · 3 comments

Comments

Projects
None yet
2 participants
@williamwsmith

williamwsmith commented Sep 25, 2013

Tried to solve this classic problem just for fun in NOOLS. Goes off and never returns and Chrome says it died. Based it on a CLIPS version found here:

http://commentsarelies.blogspot.com/2006/11/send-more-money-in-clips.html

I formulated this NOOLS file below and "asserted" all the Digits (0..9). Any ideas?
Thought it might be a good baseline test.

rule SendMoreMoney {
when {
s : Digit s.value != 0 { value : s1 };
e : Digit e.value != s1 { value: e1};
n : Digit n.value != s1 && n.value != e1 { value : n1 };
d : Digit d.value != s1 && d.value != e1 && d.value != n1 { value : d1 };
m : Digit m.value != s1 && m.value != e1 && m.value != n1 && m.value != d1 && m.value != 0 { value : m1 };
o : Digit o.value != s1 && o.value != e1 && o.value != n1 && o.value != d1 && o.value != m1 { value : o1 };
r : Digit r.value != s1 && r.value != e1 && r.value != n1 && r.value != d1 && r.value != m1 && r.value != o1 { value : r1 };
y : Digit y.value != s1 && y.value != e1 && y.value != n1 && y.value != d1 && y.value != m1 && y.value != o1 && y.value != r1 { value : y1 };
test : Digit s1_1000 + e1_100 + n1_10 + d1
+ m1_1000 + o1_100 + r1_10 + e1 ==
m1_10000 + o1_1000 + n1_100 + e1_10 + y1;

}
then {
    emit('pathDone', {sout : s, eout : e, nout : n, dout : d, mout : m, oout: o, rout : r, yout : y});
}

}

@doug-martin

This comment has been minimized.

Show comment
Hide comment
@doug-martin

doug-martin Sep 25, 2013

Contributor

Try

//sendMoreMoney.nools

rule SendMoreMoney {
    when {
        s : Number s != 0;
        e : Number e != s;
        n : Number n != s && n != e;
        d : Number d != s && d != e && d != n;
        m : Number m != 0 && m != s && m != e && m != n && m != d;
        o : Number o != s && o != e && o != n && o != d && o != m;
        r : Number r != s && r != e && r != n && r != d && r != m && r != o;
        y : Number y != s && y != e && y != n && y != d && y != m && y != o && y != r
            && (s*1000 + e*100 + n*10 + d + m*1000 + o*100 + r*10 + e) == (m*10000 + o*1000 + n*100 + e*10 + y);
    }
    then {
        console.log('pathDone', {s : s, e : e, n : n, d : d, m : m, o: o, r : r, y : y});
        console.log((s*1000 + e*100 + n*10 + d + m*1000 + o*100 + r*10 + e));
        console.log((m*10000 + o*1000 + n*100 + e*10 + y))
    }
}

//sendMoreMoney.js
"use strict";

var nools = require("nools"),
    flow = nools.compile(__dirname + "/sendMoreMoney.nools");

var start = new Date(),
    session;
console.log("starting");
(session = flow.getSession(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)).match().then(function () {
    console.log("%dms", +(new Date()) - start);
    session.dispose();
});
Contributor

doug-martin commented Sep 25, 2013

Try

//sendMoreMoney.nools

rule SendMoreMoney {
    when {
        s : Number s != 0;
        e : Number e != s;
        n : Number n != s && n != e;
        d : Number d != s && d != e && d != n;
        m : Number m != 0 && m != s && m != e && m != n && m != d;
        o : Number o != s && o != e && o != n && o != d && o != m;
        r : Number r != s && r != e && r != n && r != d && r != m && r != o;
        y : Number y != s && y != e && y != n && y != d && y != m && y != o && y != r
            && (s*1000 + e*100 + n*10 + d + m*1000 + o*100 + r*10 + e) == (m*10000 + o*1000 + n*100 + e*10 + y);
    }
    then {
        console.log('pathDone', {s : s, e : e, n : n, d : d, m : m, o: o, r : r, y : y});
        console.log((s*1000 + e*100 + n*10 + d + m*1000 + o*100 + r*10 + e));
        console.log((m*10000 + o*1000 + n*100 + e*10 + y))
    }
}

//sendMoreMoney.js
"use strict";

var nools = require("nools"),
    flow = nools.compile(__dirname + "/sendMoreMoney.nools");

var start = new Date(),
    session;
console.log("starting");
(session = flow.getSession(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)).match().then(function () {
    console.log("%dms", +(new Date()) - start);
    session.dispose();
});
@doug-martin

This comment has been minimized.

Show comment
Hide comment
@doug-martin

doug-martin Sep 25, 2013

Contributor

This does use quite a bit of memory because of all the cross products that are created 362,880 locally it ran in ~20 seconds assertion and firing the rules.

Contributor

doug-martin commented Sep 25, 2013

This does use quite a bit of memory because of all the cross products that are created 362,880 locally it ran in ~20 seconds assertion and firing the rules.

@williamwsmith

This comment has been minimized.

Show comment
Hide comment
@williamwsmith

williamwsmith Sep 26, 2013

Appreciate the response. I will give a try. I was very happy to stumble apon NOOLS. Have been looking for something like this in javascript for many years.

williamwsmith commented Sep 26, 2013

Appreciate the response. I will give a try. I was very happy to stumble apon NOOLS. Have been looking for something like this in javascript for many years.

doug-martin added a commit to doug-martin/nools that referenced this issue Oct 14, 2013

v0.2.0
* Nools now supports true modify!!!
   * This is a major leap forward for `nools` opening the door for more complex actions and expressions in the rules.
* Added support from for `from` conditions in the `rhs`.
* Fixed issue [#81](noolsjs#81).
* Fixed issue [#82](noolsjs#82).
* Added new `sudoku` web example.
* Added [Send More Money](http://en.wikipedia.org/wiki/Verbal_arithmetic) benchmark see [#78](noolsjs#78).

@doug-martin doug-martin referenced this issue Oct 14, 2013

Merged

v0.2.0 #83

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment