By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,918 Members | 2,246 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,918 IT Pros & Developers. It's quick & easy.

Cryptarithmetic Help

P: 1
hey guys have got any idea of how to write a code for CRYPTARITHMETIC on --- PROJ + GOOD = EASY
Oct 4 '06 #1
Share this Question
Share on Google+
3 Replies


100+
P: 144
Your question makes no sense. You need to be more specific, and word it better. My impression is you are working on a project that needs decent crypto support that is fairly easy to implement.
Oct 4 '06 #2

Banfa
Expert Mod 5K+
P: 8,916
I get the impression that he is trying to solve the alphametic puzzle

Expand|Select|Wrap|Line Numbers
  1.  PROJ
  2. +GOOD
  3. -----
  4.  EASY
  5.  
Which has multiple (100) solutions.

The brute force way is to assign digits to each letter in a loop and check the result to see if it is correct outputing correct results.
Oct 4 '06 #3

100+
P: 293
D_C
Well there are 10 letters, ADEGJOPRSY, and I assume it's in decimal. Typically, each letter is unique. If it's in hexadecimal or a higher base, then it becomes much more difficult. You can think A has 10 possible values, D has 9 possible values, E has 8, and as a result there are 10! or 3628800 possibilities, assuming it's base 10 arithmetic.

There is some information though, for example G+P+carry = E <= 9, carry either being 0 or 1. As a result, G and P are not 9, possibly not 8. Each number is four letters/digits long, and I would focus on the carries. Each digit either has a carry or not a carry, and that gives 8 possibilities.

Take the least significant digits, D+J = Y. If there is no carry, then 0 < D,J < Y <= 9. D and J must be nonzero, otherwise D = Y or J = Y. That hinges on the uniqueness requirement. Also, 2*O = S. Otherwise, 0 <= Y < D,J <= 9 and O+O+1 = S.

If the problem is in decimal, then there must be at least one carry that causes a result to be zero. Also, it's probably easier to not consider each carry, because it may lead to duplicates. While you can prune some options, after that I would greedily select whichever number has the most possibilities (probably 5).
Oct 4 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.