Skip to content

Instantly share code, notes, and snippets.

@wasi0013
Created May 10, 2015 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wasi0013/2fab7d95175fd3924647 to your computer and use it in GitHub Desktop.
Save wasi0013/2fab7d95175fd3924647 to your computer and use it in GitHub Desktop.
SEND MORE MONEY riddle in Artificial Intelligence
#include"bits/stdc++.h"
/*
Problem Name: SEND MORE MONEY riddle in Artificial Intelligence
Problem Category:
-----------------
Constraint Optimisation Problem
Problem Description:
--------------------
SEND
+ MORE
------
MONEY
A Mathematical puzzles where digits are replaced by symbols
Find unique digits the letters represent, satisfying the above constraints
*/
int main(){
/* initial guess S E N D M O R Y */
int send,more,money, digit[]={ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
do{
send = digit[0]*1000 + digit[1]*100 + digit[2]*10 + digit[3];
more = digit[4]*1000 + digit[5]*100 + digit[6]*10 + digit[1];
money = digit[4]*10000 + digit[5]*1000 + digit[2]*100 + digit[1]*10+digit[7];
if( send>=1000 and more>=1000 and send+more == money ){
printf(" SEND\n MORE\n-----\nMONEY\n\n"
"%5d\n%5d\n-----\n%5d\n", send, more, money);
break;
}
}while(std::next_permutation(digit, digit+10));
return 0;
}
/**
output:
SEND
MORE
-----
MONEY
9567
1085
-----
10652
**/
// About me: http://about.me/wasi0013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment