fork download
  1. function solve(s) {
  2.  
  3. var w = s.match(/\w/g).filter(function (x, i, a) {return a.indexOf(x) === i}).map(function (x) {return RegExp(x, 'g')})
  4.  
  5. var t = ''
  6.  
  7. function c(s, n, a) {
  8.  
  9. if (n === w.length) {
  10. if (!s.match(/(?:^|\D)0/)) t += 'if('+s+')return "'+s+'";'
  11. return
  12. }
  13.  
  14. a.forEach(function (m, i, a) {
  15. a = a.slice()
  16. a.splice(i, 1)
  17. c(s.replace(w[n], m), n+1, a)
  18. })
  19.  
  20. }
  21.  
  22. c(s, 0, [0,1,2,3,4,5,6,7,8,9])
  23.  
  24. return (new Function( t ))()
  25.  
  26. }
  27.  
  28.  
  29. solve('SEND+MORE==MONEY')
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty