A computer science problem by Rocco Dalto

Computer Science Level pending

Let + + , * , and - be operations of addition, multiplication, and subtraction of integers, respectively.

I N E E D M Y + M A I L = S O O N I * NEED - MY + MAIL = SOON

In the cryptogram shown above each letter represents a digit. Let a 1 a_{1} be the maximum value for S O O N \overline{SOON} , b 1 b_{1} be the minimum value for S O O N \overline{SOON} and n 1 n_{1} be all possible values of I N E E D M Y + M A I L = S O O N \: \overline{I} * \overline{NEED} - \overline{MY} + \overline{MAIL} = \overline{SOON} and m 1 = a 1 b 1 + n 1 m_{1} = a_{1} - b_{1} + n_{1} .

I W A N T M Y + M A I L = S O O N I * WANT - MY + MAIL = SOON

In the second cryptogram shown above each letter represents a digit. Let a 2 a_{2} be the maximum value for S O O N \overline{SOON} , b 2 b_{2} be the minimum value for S O O N \overline{SOON} and n 2 n_{2} be all possible values of I W A N T M Y + M A I L = S O O N \: \overline{I} * \overline{WANT} - \overline{MY} + \overline{MAIL} = \overline{SOON} and m 2 = a 2 b 2 + n 2 m_{2} = a_{2} - b_{2} + n_{2} .

S O O N + I W A N T M Y = M A I L SOON + I * WANT - MY = MAIL

In the third cryptogram shown above each letter represents a digit. Let a 3 a_{3} be the maximum value for M A I L \overline{MAIL} , b 3 b_{3} be the minimum value for M A I L \overline{MAIL} and n 3 n_{3} be all possible values of S O O N + I W A N T M Y = M A I L \: \overline{SOON} + \overline{I} * \overline{WANT} - \overline{MY} = \overline{MAIL} and m 3 = a 3 b 3 + n 3 m_{3} = a_{3} - b_{3} + n_{3} .

T H I S I S F U N + T O = D O THIS - IS * FUN + TO = DO

In the fourth cryptogram shown above each letter represents a digit. Let a 4 a_{4} be the maximum value for D O \overline{DO} , b 4 b_{4} be the minimum value for D O \overline{DO} and n 4 n_{4} be all possible values of T H I S I S F U N + T O = D O \: \overline{THIS} - \overline{IS} * \overline{FUN} + \overline{TO} = \overline{DO} and m 4 = a 4 b 4 + n 4 m_{4} = a_{4} - b_{4} + n_{4} .

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

Note: You can create a program (in any language) to find m 1 m_{1} , m 2 m_{2} , m 3 m_{3} , and m 4 m_{4} , 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 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 run program A A again and save the text file(using a different extension) containing program B 2 B_{2} and execute it, then run program A A again and save the text file(using a different extension) containing program B 3 B_{3} and execute it, then run program A A again and save the text file(using a different extension) containing program B 4 B_{4} and execute it. .

I chose four cryptograms so that program A A can generate all four cryptograms as stated above. Writing four 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 11087.

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 3, 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] = '-') 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] <> '-') 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] = '-') 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, 'myfile6.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] <> '-') 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 A and enter the data for the first cryptogram. Program A A has now written program B 1 B_{1} to the textfile "myfile6.txt".

For program B 1 : B_{1}:

Go to text file "myfile6.txt" and save it with a different extension( I saved it using cryptogram_several operators11.pas).

Program cryptogram_several operators11.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 m,i,s,n,e,d,y,a,l,o:longint;

bool:boolean;

j1:longint;

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

begin

bool:= false;

j1:= 1;

for m:= 1 to 9 do

begin

for i:= 1 to 9 do

begin

for s:= 1 to 9 do

begin

for n:= 1 to 9 do

begin

for e:= 0 to 9 do

begin

for d:= 0 to 9 do

begin

for y:= 0 to 9 do

begin

for a:= 0 to 9 do

begin

for l:= 0 to 9 do

begin

for o:= 0 to 9 do

begin

if

(m <> i) and

(m <> s) and

(m <> n) and

(m <> e) and

(m <> d) and

(m <> y) and

(m <> a) and

(m <> l) and

(m <> o) and

(i <> s) and

(i <> n) and

(i <> e) and

(i <> d) and

(i <> y) and

(i <> a) and

(i <> l) and

(i <> o) and

(s <> n) and

(s <> e) and

(s <> d) and

(s <> y) and

(s <> a) and

(s <> l) and

(s <> o) and

(n <> e) and

(n <> d) and

(n <> y) and

(n <> a) and

(n <> l) and

(n <> o) and

(e <> d) and

(e <> y) and

(e <> a) and

(e <> l) and

(e <> o) and

(d <> y) and

(d <> a) and

(d <> l) and

(d <> o) and

(y <> a) and

(y <> l) and

(y <> o) and

(a <> l) and

(a <> o) and

(l <> o) then

begin

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

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

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

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

sum[j1]:= s * lintpower(10,3) + o * lintpower(10,2) + o * lintpower(10,1) + n * lintpower(10,0);

if z1[1]*z1[2]-z1[3]+z1[4] = 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 operators11.pas we obtain:

a 1 = 9881 , b 1 = 5881 , n 1 = 24 m 1 = 4024 . a_{1} = 9881, \: b_{1} = 5881, \: n_{1} = 24 \implies m_{1} = \boxed{4024}.

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 "myfile6.txt".

For program B 2 : B_{2}:

Go to text file "myfile6.txt" and save it with a different extension( I saved it using using cryptogram_several operators21.pas).

Program cryptogram_several operators21.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 w,m,i,s,t,y,a,l,o,n:longint;

bool:boolean;

j1:longint;

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

begin

bool:= false;

j1:= 1;

for w:= 1 to 9 do

begin

for m:= 1 to 9 do

begin

for i:= 1 to 9 do

begin

for s:= 1 to 9 do

begin

for t:= 0 to 9 do

begin

for y:= 0 to 9 do

begin

for a:= 0 to 9 do

begin

for l:= 0 to 9 do

begin

for o:= 0 to 9 do

begin

for n:= 0 to 9 do

begin

if

(w <> m) and

(w <> i) and

(w <> s) and

(w <> t) and

(w <> y) and

(w <> a) and

(w <> l) and

(w <> o) and

(w <> n) and

(m <> i) and

(m <> s) and

(m <> t) and

(m <> y) and

(m <> a) and

(m <> l) and

(m <> o) and

(m <> n) and

(i <> s) and

(i <> t) and

(i <> y) and

(i <> a) and

(i <> l) and

(i <> o) and

(i <> n) and

(s <> t) and

(s <> y) and

(s <> a) and

(s <> l) and

(s <> o) and

(s <> n) and

(t <> y) and

(t <> a) and

(t <> l) and

(t <> o) and

(t <> n) and

(y <> a) and

(y <> l) and

(y <> o) and

(y <> n) and

(a <> l) and

(a <> o) and

(a <> n) and

(l <> o) and

(l <> n) and

(o <> n) then

begin

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

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

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

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

sum[j1]:= s * lintpower(10,3) + o * lintpower(10,2) + o * lintpower(10,1) + n * lintpower(10,0);

if z1[1]*z1[2]-z1[3]+z1[4] = 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 operators21.pas we obtain:

a 2 = 9550 , b 2 = 6775 , n 2 = 45 m 2 = 2820 . a_{2} = 9550, \: b_{2} = 6775, \: n_{2} = 45 \implies m_{2} = \boxed{2820}.

Now run program A A and enter the data for the third cryptogram. Program A A has now written program B 3 B_{3} to the textfile "myfile6.txt".

For program B 3 : B_{3}:

Go to text file "myfile6.txt" and save it with a different extension( I saved it using using cryptogram_several operators31.pas).

Program cryptogram_several operators31.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 s,w,m,i,o,n,t,y,a,l:longint;

bool:boolean;

j1:longint;

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

begin

bool:= false;

j1:= 1;

for s:= 1 to 9 do

begin

for w:= 1 to 9 do

begin

for m:= 1 to 9 do

begin

for i:= 1 to 9 do

begin

for o:= 0 to 9 do

begin

for n:= 0 to 9 do

begin

for t:= 0 to 9 do

begin

for y:= 0 to 9 do

begin

for a:= 0 to 9 do

begin

for l:= 0 to 9 do

begin

if

(s <> w) and

(s <> m) and

(s <> i) and

(s <> o) and

(s <> n) and

(s <> t) and

(s <> y) and

(s <> a) and

(s <> l) and

(w <> m) and

(w <> i) and

(w <> o) and

(w <> n) and

(w <> t) and

(w <> y) and

(w <> a) and

(w <> l) and

(m <> i) and

(m <> o) and

(m <> n) and

(m <> t) and

(m <> y) and

(m <> a) and

(m <> l) and

(i <> o) and

(i <> n) and

(i <> t) and

(i <> y) and

(i <> a) and

(i <> l) and

(o <> n) and

(o <> t) and

(o <> y) and

(o <> a) and

(o <> l) and

(n <> t) and

(n <> y) and

(n <> a) and

(n <> l) and

(t <> y) and

(t <> a) and

(t <> l) and

(y <> a) and

(y <> l) and

(a <> l) then

begin

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

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

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

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

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

if z1[1]+z1[2]*z1[3]-z1[4] = 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 operators31.pas we obtain:

a 3 = 9423 , b 3 = 5417 , n 3 = 52 m 3 = 4058 . a_{3} = 9423, \: b_{3} = 5417, \: n_{3} = 52 \implies m_{3} = \boxed{4058}.

Now run program A A and enter the data for the forth cryptogram. Program A A has now written program B 4 B_{4} to the textfile "myfile6.txt".

For program B 4 : B_{4}:

Go to text file "myfile6.txt" and save it with a different extension( I saved it using using cryptogram_several operators41.pas).

Program cryptogram_several operators41.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,f,t,d,h,s,u,n,o: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 f:= 1 to 9 do

begin

for t:= 1 to 9 do

begin

for d:= 1 to 9 do

begin

for h:= 0 to 9 do

begin

for s:= 0 to 9 do

begin

for u:= 0 to 9 do

begin

for n:= 0 to 9 do

begin

for o:= 0 to 9 do

begin

if

(i <> f) and

(i <> t) and

(i <> d) and

(i <> h) and

(i <> s) and

(i <> u) and

(i <> n) and

(i <> o) and

(f <> t) and

(f <> d) and

(f <> h) and

(f <> s) and

(f <> u) and

(f <> n) and

(f <> o) and

(t <> d) and

(t <> h) and

(t <> s) and

(t <> u) and

(t <> n) and

(t <> o) and

(d <> h) and

(d <> s) and

(d <> u) and

(d <> n) and

(d <> o) and

(h <> s) and

(h <> u) and

(h <> n) and

(h <> o) and

(s <> u) and

(s <> n) and

(s <> o) and

(u <> n) and

(u <> o) and

(n <> o) then

begin

z1[1]:= t * lintpower(10,3) + h * lintpower(10,2) + i * lintpower(10,1) + s * lintpower(10,0);

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

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

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

sum[j1]:= d * lintpower(10,1) + o * lintpower(10,0);

if z1[1]-z1[2]*z1[3]+z1[4] = 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 operators41.pas we obtain:

a 4 = 98 , b 4 = 13 , n 4 = 82 m 4 = 167 . a_{4} = 98, \: b_{4} = 13, \: n_{4} = 82 \implies m_{4} = \boxed{167}.

m 1 + m 2 + m 3 + m 4 = 11087 . \implies m_{1} + m_{2} + m_{3} + m_{4} = \boxed{11087}.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...