Brilliant Cryptarithm

B R I × L L = I A N T \large \overline{BRI}\times\overline{LL}=\overline{IANT}

Above shown is a cryptarithm where each letter represents a distinct single digit non-negative integer where B , L , I B,L,I are non-zero. How many solutions are there to the cryptarithm above?


The answer is 6.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Chew-Seong Cheong
Jul 27, 2015

I use Python coding as follows:

 from itertools import permutations
 n = 0
 for p in permutations("0123456789",7):
     B = p[0]
     R = p[1]
     I = p[2]
     L = p[3]
     A = p[4]
     N = p[5]
     T = p[6]
     if B != '0':
         if int(B+R+I)*int(L+L)==int(I+A+N+T):
             n += 1
             print n, B+R+I+L+A+N+T

Moderator note:

Simple standard approach.

Is there a non-tedious case checking way to solve this problem? (I don't think so)

Generalised solver in C#.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
static void Main(string[] args)
{
    Console.WriteLine("Multiplication cryptarithm");

    Console.Write("Enter first number: ");
    string num1 = Console.ReadLine();

    Console.Write("Enter second number: ");
    string num2 = Console.ReadLine();

    Console.Write("Enter result: ");
    string result = Console.ReadLine();

    Console.WriteLine($"Found {(CountCryptarithmSolutions(num1, num2, result))} solution(s).");
}

private static int CountCryptarithmSolutions(string num1, string num2, string result)
{
    int numberOfSolutions= 0;
    char[] uniqueChars = UniqueChars(num1, num2, result);

    List<int[]> digitPermutations = new List<int[]>();
    List<int[]> validDigitPermutations = new List<int[]>();

    foreach (IEnumerable<int> i in GetPermutations(Enumerable.Range(0, 10), uniqueChars.Length))
    {
        List<int> j = new List<int>();

        foreach(int k in i)
        {
            j.Add(k);
        }

        digitPermutations.Add(j.ToArray());
    }

    int num1LeadIndex = Array.IndexOf(uniqueChars, num1[0]);
    int num2LeadIndex = Array.IndexOf(uniqueChars, num2[0]);
    int resultLeadIndex = Array.IndexOf(uniqueChars, result[0]);
    foreach (int[] perm in digitPermutations)
    {
        if (!(perm[num1LeadIndex] == 0 || perm[num2LeadIndex] == 0 || perm[resultLeadIndex] == 0))
        {
            validDigitPermutations.Add(perm);
        }
    }

    foreach (int[] validPerm in validDigitPermutations)
    {
        if (IntFromString(num1, validPerm, uniqueChars) * IntFromString(num2, validPerm, uniqueChars) == IntFromString(result, validPerm, uniqueChars))
        {
            ++numberOfSolutions;

            Console.WriteLine($"{IntFromString(num1, validPerm, uniqueChars)} * {IntFromString(num2, validPerm, uniqueChars)} = {IntFromString(result, validPerm, uniqueChars)}");
        }
    }

    return numberOfSolutions;
}

private static int IntFromString(string input, int[] digits, char[] letters)
{
    string output = string.Empty;

    foreach (char c in input)
    {
        output += digits[Array.IndexOf(letters, c)].ToString();
    }

    return int.Parse(output);
}

private static char[] UniqueChars(string num1, string num2, string result)
{
    string output = num1 + num2 + result;

    return String.Concat(output.OrderBy(c => c)).Distinct().ToArray();
}

private static IEnumerable<IEnumerable<T>> GetPermutations<T>(IEnumerable<T> list, int length)
{
    if (length == 1) return list.Select(t => new T[] { t });

    return GetPermutations(list, length - 1)
        .SelectMany(t => list.Where(e => !t.Contains(e)),
            (t1, t2) => t1.Concat(new T[] { t2 }));
}

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...