A computer science problem by Rocco Dalto

Computer Science Level pending

Let + + , * , - , and ÷ \div be operations of addition, multiplication, subtraction, and division of integers, respectively.

I A M N O T ÷ A + L I A R = T R U E \lfloor I - AM * NOT \div A + LIAR \rfloor = TRUE

In the cryptogram shown above each letter represents a digit. Let a 1 a_{1} be the maximum value for T R U E \overline{TRUE} , b 1 b_{1} be the minimum value for T R U E \overline{TRUE} and n 1 n_{1} be all possible values of I A M N O T ÷ A + L I A R = T R U E \: \lfloor \overline{I} - \overline{AM} * \overline{NOT} \div \overline{A} + \overline{LIAR}\rfloor = \overline{TRUE} and m 1 = a 1 b 1 + n 1 m_{1} = a_{1} - b_{1} + n_{1} .

I A M N O T ÷ A + L A Z Y = L A D Y \lfloor I * AM - NOT \div A + LAZY \rfloor = LADY

In the second cryptogram shown above each letter represents a digit. Let a 2 a_{2} be the maximum value for L A D Y \overline{LADY} , b 2 b_{2} be the minimum value for L A D Y \overline{LADY} and n 2 n_{2} be all possible values of I A M N O T ÷ A + L A Z Y = L A D Y \: \lfloor \overline{I} * \overline{AM} - \overline{NOT} \div \overline{A} + \overline{LAZY}\rfloor = \overline{LADY} and m 2 = a 2 b 2 + n 2 m_{2} = a_{2} - b_{2} + n_{2} .

Find: m 1 + m 2 . m_{1} + m_{2}.

Note: You can create a program (in any language) to find m 1 m_{1} and m 2 . m_{2}.

I wrote a program A A that when executed gets the input and writes a program B B to solve cryptograms to a text file, then I saved the text file using a different extension, complied it and ran program B B .

So, for the first cryptogram you would just need to run program A A and save the text file (using a different extension) containing program B 1 B_{1} and execute it, then for the second cryptogram run program A A again and save the text file(using a different extension) containing program B 2 B_{2} and execute it.

I chose two cryptograms so that program A A can generate the two cryptograms as stated above. Writing two separate programs for each cryptogram would be tedious and that was not my intention. Essential, you just need to write program A A .

Assume I chose N N cryptograms. Write program A A to generate all N N cryptograms as stated above.

Refer to previous problem. . .


The answer is 18828.

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.

1 solution

Rocco Dalto
Mar 6, 2017

I used Free Pascal to construct the program:

Program A : A:

program for_brillant; uses mathunit;

type arraytype = array[1 .. 1000] of longint;

 chararray = array[1 .. 1000] of char;

var myfile:text;

s:string;

n:longint;

numwords:longint;

hold:text;

sizeword:arraytype;

procedure getinput;

var j:longint;

begin

writeln('Enter string of characters including +, *, -, /, and =, but no spaces');

read(s);

n:= length(s);

writeln;

writeln('Enter number of words');

readln(numwords);

writeln;

writeln('Enter length of each word');

for j:= 1 to numwords do

begin

read(sizeword[j]);

end;

end;

procedure eliminate;

type darraytype = array[1 .. 300,1 .. 300] of char;

 strarray = array[1 .. 300] of string;

var j,k:longint;

notequal:boolean;

counter,counter2,total,total2,newtotal:longint;

w,z,y,x,p:chararray;

equal:boolean;

v:darraytype;

sum:strarray;

e,a,b,c,f:string;

symbol:chararray;

count:longint;

begin

count:= 0;

for j:= 1 to n do

begin

if (s[j] = '*') or (s[j] = '+') or (s[j] = '-') or (s[j] = '/') then

begin

count:= count + 1;

symbol[count]:= s[j];

end;

end;

counter:= 0;

for j:= 1 to n - 1 do

begin

notequal:= true;

for k:= j + 1 to n do

begin

if (s[j] = s[k]) then

notequal:= false;

end;

if notequal and (s[j] <> '+') and (s[j] <> '*') and (s[j] <> '=')

and (s[j] <> '-') and (s[j] <> '/') then

begin

counter:= counter + 1;

w[counter]:= s[j];

end;

end;

total:= counter + 1;

w[total]:= s[n];

z[1]:= s[1];

counter:= 1;

for j:= 1 to n do

begin

if (s[j] = '+') or (s[j] = '=') or (s[j] = '*') or (s[j] = '-') or

(s[j] = '/') then

begin

counter:= counter + 1;

z[counter]:= s[j + 1];

end;

end;

counter2:= 0;

for j:= 1 to counter - 1 do

begin

notequal:= true;

for k:= j + 1 to counter do

begin

if (z[j] = z[k]) then

notequal:= false;

end;

if notequal then

begin

counter2:= counter2 + 1;

y[counter2]:= z[j];

end;

end;

total2:= counter2 + 1;

y[total2]:= z[counter];

counter:= 0;

counter2:= 0;

for j:= 1 to total do

begin

notequal:= true;

for k:= 1 to total2 do

begin

if w[j] = y[k] then

begin

notequal:= false;

counter:= counter + 1;

x[counter]:= w[j];

end;

end;

if notequal then

begin

counter2:= counter2 + 1;

z[counter2]:= w[j];

end;

end;

assign(myfile, 'myfile7.txt');

rewrite(myfile);

writeln(myfile,'program for brillant 3;');

writeln(myfile,'type arraytype = array[1 .. 5000] of longint;');

writeln(myfile,'var z1:arraytype;');

writeln(myfile);

writeln(myfile);

writeln(myfile,'function LINTpower(base,exponent:longint):longint;');

writeln(myfile,'var n,product:longint;');

writeln(myfile);

writeln(myfile,'begin');

    writeln(myfile,'product:= 1;');

writeln(myfile,'for n:= 1 to exponent do');

writeln(myfile,'begin');

writeln(myfile,'product:= base * product;');

writeln(myfile,'end;');

    writeln(myfile,'LINTpower:= product;');

writeln(myfile,'end;');

writeln(myfile);

writeln(myfile);

writeln(myfile, 'function minnum(a:arraytype; last:longint):longint;');

writeln(myfile,'var j,n:longint;');

writeln(myfile,'small:longint;');

writeln(myfile);

  writeln(myfile,'begin');

        writeln(myfile,'small:= a[1];');

writeln(myfile,'for j:= 2 to last do');

writeln(myfile,'begin');

writeln(myfile,'if a[j] < small then');

        writeln(myfile,'small:= a[j];');

writeln(myfile,'end;');

writeln(myfile,'minnum:= small;');

    writeln(myfile,'end;');

    writeln(myfile);

writeln(myfile,'function maxnum(a:arraytype; last:longint):longint;');

writeln(myfile,'var j,n:longint;');

writeln(myfile,'large:longint;');

  writeln(myfile,'begin');

        writeln(myfile,'large:= a[1];');

writeln(myfile,'for j:= 2 to last do');

writeln(myfile,'begin');

writeln(myfile,'if a[j] > large then');

        writeln(myfile,'large:= a[j];');

writeln(myfile,'end;');

writeln(myfile,'maxnum:= large;');

    writeln(myfile,'end;');

    writeln(myfile);

writeln(myfile,'procedure getsum; ');

writeln(myfile);

write(myfile,'var ');

for j:= 1 to counter do

begin

write(myfile,x[j],',');

end;

for j:= 1 to counter2 do

begin

if j < counter2 then

write(myfile, z[j],',')

else

write(myfile, z[j]);

end;

write(myfile,':longint;');

writeln(myfile);

write(myfile,' bool:boolean;');

writeln(myfile);

write(myfile,' j1:longint;');

writeln(myfile);

write(myfile,' a1,a2,a3,answer:longint; ');

writeln(myfile, 'sum:arraytype;');

writeln(myfile);

writeln(myfile);

writeln(myfile,'begin');

writeln(myfile);

writeln(myfile,'bool:= false;');

writeln(myfile,'j1:= 1;');

for j:= 1 to counter do

begin

writeln(myfile,'for ', x[j],':= 1 to 9 do ');

writeln(myfile,'begin')

end;

for j:= 1 to counter2 do

begin

writeln(myfile,'for ', z[j],':= 0 to 9 do ' );

writeln(myfile,'begin');

end;

for j:= 1 to counter do

begin

p[j]:= x[j];

end;

for j:= 1 to counter2 do

begin

p[j + counter]:= z[j];

end;

newtotal:= counter + counter2;

write(myfile,' if ');

for j:= 1 to newtotal - 1 do

begin

for k:= j + 1 to newtotal do

begin

if k mod 5 = 0 then

write(myfile);

writeln(myfile);

if j < newtotal - 1 then

write(myfile, '(',p[j], ' <> ', p[k],') and ')

else

write(myfile, '(',p[j], ' <> ', p[k],')');

end;

end;

write(myfile, ' then');

writeln(myfile);

writeln(myfile, 'begin' );

assign(hold,'hold.txt');

rewrite(hold);

for j:= 1 to n do

begin

if (s[j] <> '+') and (s[j] <> '*') and (s[j] <> '=') and (s[j] <> '-')

and (s[j] <> '/') then

begin

write(hold,s[j]);

end;

end;

reset(hold);

for j:= 1 to numwords do

begin

for k:= 1 to sizeword[j] do

begin

read(hold,v[k,j]);

end;

end;

sum[1]:= '';

for j:= 1 to numwords do

begin

if j <= numwords - 1 then

write(myfile,'z1[',j,']:= ')

else

write(myfile,'sum[j1]:= ');

for k:= 1 to sizeword[j] do

begin

str(sizeword[j] - k,e);

if k < sizeword[j] then

sum[j]:= sum[j] + ' ' + v[k,j] + ' * lintpower(10,' + e + ') + '

else

sum[j]:= sum[j] + ' ' + v[k,j] + ' * lintpower(10,' + e + ')';

end;

write(myfile,sum[j],';');

writeln(myfile);

end;

{put condition and equation here}

count:= 0;

write(myfile,' if ');

a:= '';

for k:= 1 to numwords do

begin

if k <= numwords - 2 then

begin

str(k,b);

count:= count + 1;

a:= a + 'z1[' + b + ']' + symbol[count];

end

else

begin

str(numwords - 1,c);

b:= 'z1[' + c + ']';

end;

f:= 'sum[j1]';

end;

write(myfile, 'trunc(' + a + b, ') = ', f);

write(myfile,' then ');

writeln(myfile,'begin');

writeln(myfile,'bool:= true;');

writeln(myfile,'j1:= j1 + 1;');

writeln(myfile,'end;');

writeln(myfile,'end;');

close(hold);

writeln(myfile);

for j:= 1 to newtotal do

begin

writeln(myfile, 'end;');

end;

writeln(myfile);

writeln(myfile,'if bool then');

writeln(myfile,'begin');

writeln(myfile,'a3:= j1 - 1;');

writeln(myfile);

writeln(myfile,'a2:= maxnum(sum,a3);');

writeln(myfile,'a1:= minnum(sum,a3);');

writeln(myfile,'writeln(''max = '', a2);');

writeln(myfile,'writeln(''min = '', a1);');

writeln(myfile,'writeln(''n = '', a3);');

writeln(myfile,'answer:= a2 - a1 + a3;');

writeln(myfile,'writeln(''answer = '', answer);');

writeln(myfile,'end;');

writeln(myfile);

writeln(myfile,' end; ');

writeln(myfile);

writeln(myfile);

writeln(myfile,'begin');

writeln(myfile,'getsum;');

writeln(myfile,'readln;');

writeln(myfile,'end.');

close(myfile);

end;

begin

getinput;

eliminate;

readln;

end.

Now run program A A and enter the data for the first cryptogram. Program A A has now written program B 1 B_{1} to the textfile "myfile7.txt".

For program B 1 : B_{1}:

Go to text file "myfile7.txt" and save it with a different extension( I saved it using cryptogram several operators.pas).

You can just run the textfile "myfile7.txt" and get the results if you so desire.

Program cryptogram several operators.pas is:

program for brillant 3;

type arraytype = array[1 .. 5000] of longint;

var z1:arraytype;

function LINTpower(base,exponent:longint):longint;

var n,product:longint;

begin

product:= 1;

for n:= 1 to exponent do

begin

product:= base * product;

end;

LINTpower:= product;

end;

function minnum(a:arraytype; last:longint):longint;

var j,n:longint;

small:longint;

begin

small:= a[1];

for j:= 2 to last do

begin

if a[j] < small then

small:= a[j];

end;

minnum:= small;

end;

function maxnum(a:arraytype; last:longint):longint;

var j,n:longint;

large:longint;

begin

large:= a[1];

for j:= 2 to last do

begin

if a[j] > large then

large:= a[j];

end;

maxnum:= large;

end;

procedure getsum;

var n,l,i,a,t,m,o,r,u,e:longint;

bool:boolean;

j1:longint;

a1,a2,a3,answer:longint; sum:arraytype;

begin

bool:= false;

j1:= 1;

for n:= 1 to 9 do

begin

for l:= 1 to 9 do

begin

for i:= 1 to 9 do

begin

for a:= 1 to 9 do

begin

for t:= 1 to 9 do

begin

for m:= 0 to 9 do

begin

for o:= 0 to 9 do

begin

for r:= 0 to 9 do

begin

for u:= 0 to 9 do

begin

for e:= 0 to 9 do

begin

if

(n <> l) and

(n <> i) and

(n <> a) and

(n <> t) and

(n <> m) and

(n <> o) and

(n <> r) and

(n <> u) and

(n <> e) and

(l <> i) and

(l <> a) and

(l <> t) and

(l <> m) and

(l <> o) and

(l <> r) and

(l <> u) and

(l <> e) and

(i <> a) and

(i <> t) and

(i <> m) and

(i <> o) and

(i <> r) and

(i <> u) and

(i <> e) and

(a <> t) and

(a <> m) and

(a <> o) and

(a <> r) and

(a <> u) and

(a <> e) and

(t <> m) and

(t <> o) and

(t <> r) and

(t <> u) and

(t <> e) and

(m <> o) and

(m <> r) and

(m <> u) and

(m <> e) and

(o <> r) and

(o <> u) and

(o <> e) and

(r <> u) and

(r <> e) and

(u <> e) then

begin

z1[1]:= i * lintpower(10,0);

z1[2]:= a * lintpower(10,1) + m * lintpower(10,0);

z1[3]:= n * lintpower(10,2) + o * lintpower(10,1) + t * lintpower(10,0);

z1[4]:= a * lintpower(10,0);

z1[5]:= l * lintpower(10,3) + i * lintpower(10,2) + a * lintpower(10,1) + r * lintpower(10,0);

sum[j1]:= t * lintpower(10,3) + r * lintpower(10,2) + u * lintpower(10,1) + e * lintpower(10,0);

if trunc(z1[1]-z1[2]*z1[3]/z1[4]+z1[5]) = sum[j1] then begin

bool:= true;

j1:= j1 + 1;

end;

end;

end;

end;

end;

end;

end;

end;

end;

end;

end;

end;

if bool then

begin

a3:= j1 - 1;

a2:= maxnum(sum,a3);

a1:= minnum(sum,a3);

writeln('max = ', a2);

writeln('min = ', a1);

writeln('n = ', a3);

answer:= a2 - a1 + a3;

writeln('answer = ', answer);

end;

end;

begin

getsum;

readln;

end.

Running cryptogram several operators.pas we obtain:

a 1 = 8073 , b 1 = 1056 , n 1 = 95 m 1 = 7112 . a_{1} = 8073, \: b_{1} = 1056, \: n_{1} = 95 \implies m_{1} = \boxed{7112}.

Now run program A A and enter the data for the second cryptogram. Program A A has now written program B 2 B_{2} to the textfile "myfile7.txt".

For program B 2 : B_{2}:

Go to text file "myfile7.txt" and save it with a different extension( I saved it using using cryptogram several operators2.pas).

Program cryptogram several operators2.pas is:

program for brillant 3;

type arraytype = array[1 .. 5000] of longint;

var z1:arraytype;

function LINTpower(base,exponent:longint):longint;

var n,product:longint;

begin

product:= 1;

for n:= 1 to exponent do

begin

product:= base * product;

end;

LINTpower:= product;

end;

function minnum(a:arraytype; last:longint):longint;

var j,n:longint;

small:longint;

begin

small:= a[1];

for j:= 2 to last do

begin

if a[j] < small then

small:= a[j];

end;

minnum:= small;

end;

function maxnum(a:arraytype; last:longint):longint;

var j,n:longint;

large:longint;

begin

large:= a[1];

for j:= 2 to last do

begin

if a[j] > large then

large:= a[j];

end;

maxnum:= large;

end;

procedure getsum;

var i,n,l,a,m,o,t,z,d,y:longint;

bool:boolean;

j1:longint;

a1,a2,a3,answer:longint; sum:arraytype;

begin

bool:= false;

j1:= 1;

for i:= 1 to 9 do

begin

for n:= 1 to 9 do

begin

for l:= 1 to 9 do

begin

for a:= 1 to 9 do

begin

for m:= 0 to 9 do

begin

for o:= 0 to 9 do

begin

for t:= 0 to 9 do

begin

for z:= 0 to 9 do

begin

for d:= 0 to 9 do

begin

for y:= 0 to 9 do

begin

if

(i <> n) and

(i <> l) and

(i <> a) and

(i <> m) and

(i <> o) and

(i <> t) and

(i <> z) and

(i <> d) and

(i <> y) and

(n <> l) and

(n <> a) and

(n <> m) and

(n <> o) and

(n <> t) and

(n <> z) and

(n <> d) and

(n <> y) and

(l <> a) and

(l <> m) and

(l <> o) and

(l <> t) and

(l <> z) and

(l <> d) and

(l <> y) and

(a <> m) and

(a <> o) and

(a <> t) and

(a <> z) and

(a <> d) and

(a <> y) and

(m <> o) and

(m <> t) and

(m <> z) and

(m <> d) and

(m <> y) and

(o <> t) and

(o <> z) and

(o <> d) and

(o <> y) and

(t <> z) and

(t <> d) and

(t <> y) and

(z <> d) and

(z <> y) and

(d <> y) then

begin

z1[1]:= i * lintpower(10,0);

z1[2]:= a * lintpower(10,1) + m * lintpower(10,0);

z1[3]:= n * lintpower(10,2) + o * lintpower(10,1) + t * lintpower(10,0);

z1[4]:= a * lintpower(10,0);

z1[5]:= l * lintpower(10,3) + a * lintpower(10,2) + z * lintpower(10,1) + y * lintpower(10,0);

sum[j1]:= l * lintpower(10,3) + a * lintpower(10,2) + d * lintpower(10,1) + y * lintpower(10,0);

if trunc(z1[1]*z1[2]-z1[3]/z1[4]+z1[5]) = sum[j1] then begin

bool:= true;

j1:= j1 + 1;

end;

end;

end;

end;

end;

end;

end;

end;

end;

end;

end;

end;

if bool then

begin

a3:= j1 - 1;

a2:= maxnum(sum,a3);

a1:= minnum(sum,a3);

writeln('max = ', a2);

writeln('min = ', a1);

writeln('n = ', a3);

answer:= a2 - a1 + a3;

writeln('answer = ', answer);

end;

end;

begin

getsum;

readln;

end.

Running cryptogram several operators2.pas we obtain:

a 2 = 9867 , b 2 = 1203 , n 2 = 3052 m 2 = 11716 . a_{2} = 9867, \: b_{2} = 1203, \: n_{2} = 3052 \implies m_{2} = \boxed{11716}.

m 1 + m 2 = 18828 . \implies m_{1} + m_{2} = \boxed{18828}.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...