ABCD * D = DCBA (Puzzle+Solution)

April 7, 2017 § Leave a comment

The Puzzle

“ABCD * D = DCBA”, Replace every character with a number to make the equation mathematically right.

The Solution using brute-force algorithm

#include<bits/stdc++.h>
using namespace std;
int main(){
    for(int a=0;a<=9;a++){
        for(int b=0;b<=9;b++)if(a!=b){
            for(int c=0;c<=9;c++)if(a!=c && b!=c){
                for(int d=0;d<=9;d++)if(a!=d && b!=d && c!=d){
                        if((a*1000+b*100+c*10+d)*d == (d*1000+c*100+b*10+a))
                            return cout<<"abcd\n"<<a<<b<<c<<d,0;
                }
            }
        }
    }

    return 0;
}

The final answer is 1089.

Advertisements

Tagged:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading ABCD * D = DCBA (Puzzle+Solution) at Orange Notes.

meta

%d bloggers like this: