Let and be operations of addition and multiplication of integers respectively.
In the cryptogram shown above each letter represents a digit. Let be the maximum value for , be the minimum value for and be all possible values of and .
In the second cryptogram shown above each letter represents a digit. Let be the maximum value for , be the minimum value for and be all possible values of and .
In the third cryptogram shown above each letter represents a digit. Let be the maximum value for , be the minimum value for and be all possible values of and .
Find: .
Note: You can create a program (in any language) to find , and , but the program should not contain any predefined functions or procedures. That is you must create all functions and procedures and they should appear in the program, and not called from a library you created. For example, you could create your own maximum and minimum function for an array of integers and your own power function.
I wrote a program that when executed gets the input and writes a program to solve cryptograms to a text file, then I saved the text file using a different extension, complied it and ran program .
So, for the first cryptogram you would just need to run program and save the text file (using a different extension) containing program and execute it, then run program again and save the text file(using a different extension) containing program and execute it, then run program again and save the text file(using a different extension) containing program and execute it.
I chose three cryptograms so that program can generate all three cryptograms as stated above. Writing three separate programs for each cryptogram would be tedious and that was not my intention. Essential, you just need to write program .
Assume I chose cryptograms. Write program to generate all cryptograms as stated above.
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.
I used Free Pascal to construct the program:
Program A :
program for_brillant; uses mathunit;
type arraytype = array[1 .. 1000] of longint;
var myfile:text;
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;
var j,k:longint;
begin
count:= 0;
for j:= 1 to n do
begin
if (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] <> '=') 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] = '*') 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, 'myfile5.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,'for n:= 1 to exponent do');
writeln(myfile,'begin');
writeln(myfile,'end;');
writeln(myfile,'end;');
writeln(myfile);
writeln(myfile);
writeln(myfile, 'function minnum(a:arraytype; last:longint):longint;');
writeln(myfile,'var j,n:longint;');
writeln(myfile);
writeln(myfile,'begin');
writeln(myfile,'end;');
writeln(myfile,'function maxnum(a:arraytype; last:longint):longint;');
writeln(myfile,'var j,n:longint;');
writeln(myfile,'begin');
writeln(myfile,'end;');
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] <> '=') 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, 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 and enter the data for the first cryptogram. Program A has now written program B 1 to the textfile "myfile5.txt".
For program B 1 :
Go to text file "myfile5.txt" and save it with a different extension( I saved it using cryptogram_several operators.pas).
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 y,a,p,o,u,r,e,s,t:longint;
bool:boolean;
j1:longint;
a1,a2,a3,answer:longint; sum:arraytype;
begin
bool:= false;
j1:= 1;
for y:= 1 to 9 do
begin
for a:= 1 to 9 do
begin
for p:= 1 to 9 do
begin
for o:= 0 to 9 do
begin
for u:= 0 to 9 do
begin
for r:= 0 to 9 do
begin
for e:= 0 to 9 do
begin
for s:= 0 to 9 do
begin
for t:= 0 to 9 do
begin
if
(y <> a) and
(y <> p) and
(y <> o) and
(y <> u) and
(y <> r) and
(y <> e) and
(y <> s) and
(y <> t) and
(a <> p) and
(a <> o) and
(a <> u) and
(a <> r) and
(a <> e) and
(a <> s) and
(a <> t) and
(p <> o) and
(p <> u) and
(p <> r) and
(p <> e) and
(p <> s) and
(p <> t) and
(o <> u) and
(o <> r) and
(o <> e) and
(o <> s) and
(o <> t) and
(u <> r) and
(u <> e) and
(u <> s) and
(u <> t) and
(r <> e) and
(r <> s) and
(r <> t) and
(e <> s) and
(e <> t) and
(s <> t) then
begin
z1[1]:= y * lintpower(10,2) + o * lintpower(10,1) + u * lintpower(10,0);
z1[2]:= a * lintpower(10,2) + r * lintpower(10,1) + e * lintpower(10,0);
z1[3]:= a * lintpower(10,0);
sum[j1]:= p * lintpower(10,3) + e * lintpower(10,2) + s * lintpower(10,1) + t * lintpower(10,0);
if z1[1]+z1[2]*z1[3] = sum[j1] then begin
bool:= true;
j1:= j1 + 1;
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 operatators.pas we obtain:
a 1 = 8 7 5 6 , b 1 = 1 3 0 4 , n 1 = 1 9 1 ⟹ m 1 = 7 6 4 3 .
Now run program A and enter the data for the second cryptogram. Program A has now written program B 2 to the textfile "myfile5.txt".
For program B 2 :
Go to text file "myfile5.txt" and save it with a different extension( I saved it 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 y,l,a,o,u,e,i,r:longint;
bool:boolean;
j1:longint;
a1,a2,a3,answer:longint; sum:arraytype;
begin
bool:= false;
j1:= 1;
for y:= 1 to 9 do
begin
for l:= 1 to 9 do
begin
for a:= 1 to 9 do
begin
for o:= 0 to 9 do
begin
for u:= 0 to 9 do
begin
for e:= 0 to 9 do
begin
for i:= 0 to 9 do
begin
for r:= 0 to 9 do
begin
if
(y <> l) and
(y <> a) and
(y <> o) and
(y <> u) and
(y <> e) and
(y <> i) and
(y <> r) and
(l <> a) and
(l <> o) and
(l <> u) and
(l <> e) and
(l <> i) and
(l <> r) and
(a <> o) and
(a <> u) and
(a <> e) and
(a <> i) and
(a <> r) and
(o <> u) and
(o <> e) and
(o <> i) and
(o <> r) and
(u <> e) and
(u <> i) and
(u <> r) and
(e <> i) and
(e <> r) and
(i <> r) then
begin
z1[1]:= y * lintpower(10,2) + o * lintpower(10,1) + u * lintpower(10,0);
z1[2]:= a * lintpower(10,2) + r * lintpower(10,1) + e * lintpower(10,0);
z1[3]:= a * lintpower(10,0);
sum[j1]:= l * lintpower(10,3) + i * lintpower(10,2) + a * lintpower(10,1) + r * lintpower(10,0);
if z1[1]+z1[2]*z1[3] = sum[j1] then begin
bool:= true;
j1:= j1 + 1;
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 operatators2.pas we obtain:
a 2 = 8 7 9 6 , b 2 = 1 0 2 3 , n 2 = 1 1 3 ⟹ m 2 = 7 8 8 6 .
Now run program A and enter the data for the second cryptogram. Program A has now written program B 3 to the textfile "myfile5.txt".
For program B 3 :
Go to text file "myfile5.txt" and save it with a different extension( I saved it using cryptogram_several operators3.pas).
Program cryptogram_several operators3.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 l,m,p,i,o,v,e,y,z,a:longint;
bool:boolean;
j1:longint;
a1,a2,a3,answer:longint; sum:arraytype;
begin
bool:= false;
j1:= 1;
for l:= 1 to 9 do
begin
for m:= 1 to 9 do
begin
for p:= 1 to 9 do
begin
for i:= 1 to 9 do
begin
for o:= 0 to 9 do
begin
for v:= 0 to 9 do
begin
for e:= 0 to 9 do
begin
for y:= 0 to 9 do
begin
for z:= 0 to 9 do
begin
for a:= 0 to 9 do
begin
if
(l <> m) and
(l <> p) and
(l <> i) and
(l <> o) and
(l <> v) and
(l <> e) and
(l <> y) and
(l <> z) and
(l <> a) and
(m <> p) and
(m <> i) and
(m <> o) and
(m <> v) and
(m <> e) and
(m <> y) and
(m <> z) and
(m <> a) and
(p <> i) and
(p <> o) and
(p <> v) and
(p <> e) and
(p <> y) and
(p <> z) and
(p <> a) and
(i <> o) and
(i <> v) and
(i <> e) and
(i <> y) and
(i <> z) and
(i <> a) and
(o <> v) and
(o <> e) and
(o <> y) and
(o <> z) and
(o <> a) and
(v <> e) and
(v <> y) and
(v <> z) and
(v <> a) and
(e <> y) and
(e <> z) and
(e <> a) and
(y <> z) and
(y <> a) and
(z <> a) then
begin
z1[1]:= i * lintpower(10,0);
z1[2]:= l * lintpower(10,3) + o * lintpower(10,2) + v * lintpower(10,1) + e * lintpower(10,0);
z1[3]:= m * lintpower(10,1) + y * lintpower(10,0);
sum[j1]:= p * lintpower(10,4) + i * lintpower(10,3) + z * lintpower(10,2) + z * lintpower(10,1) + a * lintpower(10,0);
if z1[1]*z1[2]+z1[3] = 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 operatators3.pas we obtain:
a 3 = 5 7 4 4 6 , b 3 = 1 2 0 0 4 , n 3 = 1 9 ⟹ m 3 = 4 5 4 6 1 .
⟹ m 1 + m 2 + m 3 = 6 0 9 9 0 .