SEND + MORE = MONEY: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: spotted an unnecessary test) |
|||
Line 368: | Line 368: | ||
</pre> |
</pre> |
||
=={{header|jq}}== |
|||
{{works with|jq}} |
|||
'''Works with gojq, the Go implementation of jq, and with fq''' |
|||
Straight out of the [https://en.wikipedia.org/wiki/Jq_(programming_language) wikipedia] page, except for {} instead of [] in the last line: |
|||
<syntaxhighlight lang=jq> |
|||
def send_more_money: |
|||
def choose(m;n;used): ([range(m;n+1)] - used)[]; |
|||
def num(a;b;c;d): 1000*a + 100*b + 10*c + d; |
|||
def num(a;b;c;d;e): 10*num(a;b;c;d) + e; |
|||
first( |
|||
1 as $m |
|||
| 0 as $o |
|||
| choose(8;9;[]) as $s |
|||
| choose(2;9;[$s]) as $e |
|||
| choose(2;9;[$s,$e]) as $n |
|||
| choose(2;9;[$s,$e,$n]) as $d |
|||
| choose(2;9;[$s,$e,$n,$d]) as $r |
|||
| choose(2;9;[$s,$e,$n,$d,$r]) as $y |
|||
| select(num($s;$e;$n;$d) + num($m;$o;$r;$e) == num($m;$o;$n;$e;$y)) |
|||
| [$s,$e,$n,$d,$m,$o,$r,$e,$m,$o,$n,$e,$y] ); |
|||
send_more_money |
|||
</syntaxhighlight> |
|||
{{output}} |
|||
<pre> |
|||
{"s":9,"e":5,"n":6,"d":7,"m":1,"o":0,"r":8,"y":2} |
|||
</pre> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
A hoary old task, solved with pencil before electricity was a thing. |
A hoary old task, solved with pencil before electricity was a thing. |
||
Line 403: | Line 430: | ||
end |
end |
||
</syntaxhighlight>{{out}} 9567 + 1085 == 10652 |
</syntaxhighlight>{{out}} 9567 + 1085 == 10652 |
||
=={{header|Pascal}}== |
=={{header|Pascal}}== |
||
==={{header|Free Pascal}}=== |
==={{header|Free Pascal}}=== |