Some sultan had two wise men: Ali-ibn-Vali and Vali-ibn-Ali. Wanting to be convinced of their wisdom, the Sultan called the wise men to him and said: “I planned two numbers. Both are whole, each is greater than one, but less than a hundred. I multiplied these numbers and the result will tell Ali and at the same time Vali I will say the sum of these numbers. If you really are as wise as they say about you, you can find out the original numbers. ”
Sultan said Ali the work, and Vali - the amount. Wise men thought. The first to break the silence of Ali.
“I don’t know these numbers,” he said, lowering his head.
“I knew that,” said Vali.
“Then I know these numbers,” rejoiced Ali.
- Then I know! Exclaimed Vali.
And the wise men informed the amazed Sultan of the numbers that he had intended.
Call these numbers.
Albert and Bernard just met Cheryl. They want to know when her birthday is. Cheryl offered them ten possible dates: May 15, May 16, May 19, June 17, June 18, July 14, July 16, August 14, August 15 and August 17. Then Cheryl told Albert the month of her birth, and Bernard - the day. After this dialogue took place.
Albert: I don't know when Cheryl has a birthday, but I know that Bernard doesn't know either.
Bernard: At first I did not know when Cheryl had a birthday, but I know now.
Albert: Now I also know when Cheryl has a birthday.
When is Cheryl's birthday?
days = [14; 15; 16; 17; 18; 19]; months = [5; 6; 7; 8]; matrix = [ 0 0 1 1; 1 0 0 1; 1 0 1 0; 0 1 0 1; 0 1 0 0; 1 0 0 0 ];
I don't know when Cheryl has a birthday, but I know that Bernard doesn't know either.From it we can conclude that any days valid for this month may correspond to more than one month.
unique_days = find(sum(matrix,2)==1); [~, months_with_unique_days] = find (matrix(unique_days,:)==1); months_with_unique_days = unique(months_with_unique_days); matrix(:,months_with_unique_days) = []; months(months_with_unique_days) = [];
At first, I did not know when Cheryl had a birthday, but I know now.
non_unique_days = find(sum(matrix,2)~=1); matrix(non_unique_days,:) = []; days(non_unique_days) = [];
Now I also know when Cheryl has a birthday.This means that in the remaining part of the matrix there is a column in which there is only one option. This column corresponds to July. We throw away all the columns, where more than one option.
non_unique_months = find(sum(matrix)~=1); matrix(:,non_unique_months) = []; months(non_unique_months) = [];
days = days(matrix == 1); disp(days); disp(months);
% Birthday example matrix = [ 0 0 1 1; 1 0 0 1; 1 0 1 0; 0 1 0 1; 0 1 0 0; 1 0 0 0 ]; days = [14; 15; 16; 17; 18; 19]; months = [5; 6; 7; 8]; % Remove months with unique days unique_days = find(sum(matrix,2)==1); [~, months_with_unique_days] = find (matrix(unique_days,:)==1); months_with_unique_days = unique(months_with_unique_days); matrix(:,months_with_unique_days) = []; months(months_with_unique_days) = []; % Remove non-unique days non_unique_days = find(sum(matrix,2)~=1); matrix(non_unique_days,:) = []; days(non_unique_days) = []; % Find 1 month with unique day non_unique_months = find(sum(matrix)~=1); matrix(:,non_unique_months) = []; months(non_unique_months) = []; % Find the last day days = days(matrix == 1); % Result output disp(days); disp(months);
months = 4:198; days = unique((2:99)'*(2:99)); matrix = false(length(days),length(months)); for i1 = 2:99 for i2 = 2:99 matrix(days==(i1*i2),months==(i1+i2)) = true; end; end;
Source: https://habr.com/ru/post/256293/
All Articles