1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
krok68 [10]
2 years ago
14

a cryptarithm is a mathematical puzzle where the goal is to find the correspondence between letters and digits such that the giv

en arithmetic equation consisting of letters holds true. given a cryptarithm as an array of strings crypt, count the number of its valid solutions. the solution is valid if each letter represents a different digit, and the leading digit of any multi-digit number is not zero. crypt has the following structure: [word1, word2, word3], which stands for the word1 word2
Computers and Technology
1 answer:
Leokris [45]2 years ago
3 0

Using the knowledge in computational language in C++ it is possible to write a code that  cryptarithm is a mathematical puzzle where the goal is to find the correspondence between letters and digits

<h3>Writting the code:</h3>

<em>#include <bits/stdc++.h></em>

<em>using namespace std;</em>

<em>// chracter to digit mapping, and the inverse</em>

<em>// (if you want better performance: use array instead of unordered_map)</em>

<em>unordered_map<char, int> c2i;</em>

<em>unordered_map<int, char> i2c;</em>

<em>int ans = 0;</em>

<em>// limit: length of result</em>

<em>int limit = 0;</em>

<em>// digit: index of digit in a word, widx: index of a word in word list, sum: summation of all word[digit]  </em>

<em>bool helper(vector<string>& words, string& result, int digit, int widx, int sum) { </em>

<em>    if (digit == limit) {</em>

<em>        ans += (sum == 0);</em>

<em>        return sum == 0;</em>

<em>    }</em>

<em>    // if summation at digit position complete, validate it with result[digit].</em>

<em>    if (widx == words.size()) {</em>

<em>        if (c2i.count(result[digit]) == 0 && i2c.count(sum%10) == 0) {</em>

<em>            if (sum%10 == 0 && digit+1 == limit) // Avoid leading zero in result</em>

<em>                return false;</em>

<em>            c2i[result[digit]] = sum % 10;</em>

<em>            i2c[sum%10] = result[digit];</em>

<em>            bool tmp = helper(words, result, digit+1, 0, sum/10);</em>

<em>            c2i.erase(result[digit]);</em>

<em>            i2c.erase(sum%10);</em>

<em>            ans += tmp;</em>

<em>            return tmp;</em>

<em>        } else if (c2i.count(result[digit]) && c2i[result[digit]] == sum % 10){</em>

<em>            if (digit + 1 == limit && 0 == c2i[result[digit]]) {</em>

<em>                return false;</em>

<em>            }</em>

<em>            return helper(words, result, digit+1, 0, sum/10);</em>

<em>        } else {</em>

<em>            return false;</em>

<em>        }</em>

<em>    }</em>

<em>    // if word[widx] length less than digit, ignore and go to next word</em>

<em>    if (digit >= words[widx].length()) {</em>

<em>        return helper(words, result, digit, widx+1, sum);</em>

<em>    }</em>

<em>    // if word[widx][digit] already mapped to a value</em>

<em>    if (c2i.count(words[widx][digit])) {</em>

<em>        if (digit+1 == words[widx].length() && words[widx].length() > 1 && c2i[words[widx][digit]] == 0) </em>

<em>            return false;</em>

<em>        return helper(words, result, digit, widx+1, sum+c2i[words[widx][digit]]);</em>

<em>    }</em>

<em>    // if word[widx][digit] not mapped to a value yet</em>

<em>    for (int i = 0; i < 10; i++) {</em>

<em>        if (digit+1 == words[widx].length() && i == 0 && words[widx].length() > 1) continue;</em>

<em>        if (i2c.count(i)) continue;</em>

<em>        c2i[words[widx][digit]] = i;</em>

<em>        i2c[i] = words[widx][digit];</em>

<em>        bool tmp = helper(words, result, digit, widx+1, sum+i);</em>

<em>        c2i.erase(words[widx][digit]);</em>

<em>        i2c.erase(i);</em>

<em>    }</em>

<em>    return false;</em>

<em>}</em>

<em>void isSolvable(vector<string>& words, string result) {</em>

<em>    limit = result.length();</em>

<em>    for (auto &w: words) </em>

<em>        if (w.length() > limit) </em>

<em>            return;</em>

<em>    for (auto&w:words) </em>

<em>        reverse(w.begin(), w.end());</em>

<em>    reverse(result.begin(), result.end());</em>

<em>    int aa = helper(words, result, 0, 0, 0);</em>

<em>}</em>

<em />

<em>int main()</em>

<em>{</em>

<em>    ans = 0;</em>

<em>    vector<string> words={"GREEN" , "BLUE"} ;</em>

<em>    string result = "BLACK";</em>

<em>    isSolvable(words, result);</em>

<em>    cout << ans << "\n";</em>

<em>    return 0;</em>

<em>}</em>

See more about C++ code at brainly.com/question/19705654

#SPJ1

You might be interested in
Is backing up computer files done on the hard drive?
8_murik_8 [283]
Yes but if the hard drive stops working you will lose your files so it's better to backup your files to a cloud like iCloud by Apple.
5 0
3 years ago
Read 2 more answers
The ________ utility automatically creates duplicates of your libraries, desktops, contacts, and favorites to another storage lo
olga55 [171]

Answer:

The correct answer for the given question is option(A) i.e File History.

Explanation:

In computer system file history is an backup application which create backup of your data which are stored in your libraries, desktops, contacts, and favorites to another storage location .It creates back up of your data  to another location when your personal files has been changed.

The user can check the file history option in computer system

open control panel >>system and security >> file system

7 0
3 years ago
The basic difference between RAM and ROM memory is: Question 5 options: A) RAM is nonvolatile while ROM is volatile. B) RAM is r
schepotkina [342]

The basic difference between RAM and ROM memory is RAM is read/write while ROM Is read-only.

Explanation:

  • A ROM, non-volatile memory, does not use to store data, but RAM is volatile and requires power to store data.
  • ROM is not given usually as a specification, but RAM is typically specified when buying a computer.
  • We can write data only once in ROM. However, once it is written, we can read it any number of times. RAM is the main memory in a computer, and read from and write to it much faster than other storage types. RAM is used to store files in use on the computer.

Hence the basic difference between RAM and ROM memory is RAM is read/write while ROM Is read-only.

6 0
3 years ago
The concepts of ________________, _________________, and _________________ for covert acts are pivotal to understanding state-on
DIA [1.3K]

The concepts of Power, anonymity and political utility for covert acts are pivotal to understanding state-on-state interactions within cyberspace.

<h3>What is Anonymity?</h3>
  • Anonymity describes cases where the interim person's identity is anonymous.
  • Some writers have argued that anonymity, though technically accurate, does not capture what is more centrally at stake in contexts of anonymity.
  • The essential concept here is that an individual is non-identifiable, unavailable, or untrackable.
  • Anonymity is seen as a technique, or a way of realizing, sure other values, such as solitude, or liberty.
  • Over the past few years, anonymity tools used on the dark web by offenders and harmful users have drastically changed the ability of law enforcement to use conventional surveillance Techni.

To learn more about Anonymity, refer to:

brainly.com/question/28115737

#SPJ4

3 0
1 year ago
How could you insert a new row between rows 20 and 21?
podryga [215]
Highlight the row(20), then click on the insert cells button under the home ribbon.
3 0
3 years ago
Read 2 more answers
Other questions:
  • Which group on the sparkline tools design tab would you choose if you wanted to change the data source of the sparkline? (1 poin
    10·1 answer
  • What are the three modes of the 3D transform manipulator
    12·1 answer
  • Token stories of success and upward mobility (illustrated by Oprah, Ross Perot, and Madonna) reinforce ________ and perpetuate t
    8·1 answer
  • Explain the saying "Dress for the position you want, not the position you have."
    6·2 answers
  • Implement RandMultipByVal function, which gets one integervariable as its argument
    12·1 answer
  • You want to use a terminal program to terminal into a cisco router. what protocol should i use
    8·1 answer
  • When backing up a database, what is added to the file name?<br> On g metrix
    9·1 answer
  • HELP ASAP 10 POINTS COMPUTER SCIENCE
    14·2 answers
  • How many constructors are there in the following class declaration?class CashRegister { public: CashRegister(); CashRegister(int
    8·1 answer
  • How to send an email to multiple recipients individually outlook
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!