48On the ground of values of these sums, it can be determined unambiguously, whetherthe mistake was made, and if so, the bad (altered) bit can be found.Task. A) Analyze the codes of Hamming, sums S 1, S 2, S 3and fill in the table above;B) Determine, if the encoded message 1100011 was transmitted correctly, and ifnot, restore the original coded message.232. Interest. A man went to borrow some money from a moneylender. The moneylenderagreed to lend and asked to repay money next month in the following way:on the first day of the month – 1 litas, on the second – two litas, on the third – fourlitas, i.e. every day to repay twice as much as the day before. On the day when the debtcould be paid off, the debtor would have to repay all rate of that day too. The overpaidsum would be the moneylender’s interest.A moneylender can lend not more than 30000 (thirty thousands) litas.Task. A moneylender reconsidered the situation and agreed to lend only if the loansum would be repaid in d days sharply, i.e. if in the way presented above it is notpossible to repay in other number of days.Write a program to calculate:a) how many litas it would be the most profitably to borrow for the man, i.e. whenthe interest in litas would be the least;b) how many litas it would be the most profitably to lend for the moneylender, i.e.when the interest in litas would be the biggest.Example. If number of days is 2, the most profitably for the man would be toborrow 3 litas, and the most profitably for the trader would be to lend 2 litas.233. Theorem 6174. Sequence 6174 is formed in the following way. The firstmember of the sequence is any tetra-signed number n 1. The only restriction: all fourdigits of this number can’t be equal (i.e. at least one must differ from the remainingthree). Two new numbers will be formed from the first member of the sequence. Thefirst number is obtained by sorting digits of n 1in descending order and the secondnumber will be obtained by sorting digits in ascending order. We subtract the secondnumber from the first one and obtain the second member n 2of the sequence. Againtwo new numbers are formed from n 2, the smaller is subtracted from the larger, thethird member of the sequence n 3is obtained, etc. Sequence is finished when its membersstart repeating (i.e. it can’t have two identical members). If the member of sequencehas less than four digits, then, sorting its digits (i.e. searching for further member),extra zero (or zeroes) is attached.Theorem 6174 states that the last member of the sequence formed in this way willalways be equal to 6174.Note: further members of the sequence will repeat, because 7641–1467==6174.Example: let us take the number 7815. It will be the first member n 1of the sequence:8751 – 1578 == 7173; n 2;7731 – 1377 == 6354; n 3;6543 – 3456 == 3087; n 4;
8730 – 0378 == 8352; n 5;8532 – 2358 == 6174; n 6;Task: The first member n 1of the sequence is given. Write a program to find thenumber of the last member (it is equal to 6174) of sequence.For example, if the input is 7815, the result should be equal to 6.49STAGE IIJUNIOR DIVISIONy 1X 3234. Parallel Sorting (theoretical task). Sequences of1 5 3 2 9 8numbers often have to be sorted in ascending or descendingorder. During the process of sorting, elements of sequencesPicture 234.1are compared andswapped. Sometimes theseX 1 y 1= min(x 1, x 2)actions can be performed inparallel. Consider the sequenceX 2 y 2= max(x 1, x 2)at picture 234.1.Two pairs of elementsPicture 234.2Picture 234.3can be compared andswapped at the same moment:x 1the second elementwith the fourth one and thefifth with the sixth one – thesorted sequence is obtained.Comparator is used inX 2y 2y 3algorithms of parallel sorting.It is a circuit having twoX 4y 4Picture 234.4inputs and two outputs (picture234.2: inputs are on theleft, outputs – on the right).X 1For example, whenx 1=3, x 2=1, we obtain situationin pict. 234.3.Comparators are joinedX 3with each other and so sortingnetworks are obtained.They sort members of sequencein ascending order. X 5Undoubtedly, not everysuch network sort sequence X 6completely Consider the exampleon pict. 234.4.Picture 234.53 11 3X 2 y 2y 3X 4 y 4y 1y 5y 6