Input format explanation for TOH - facebook

Today i came across this Tower of Hanoi problem from Facebook and here is the question and solution for this - Facebook sample puzzle: Towers of Hanoi
But the problem i am facing is i am not able to understand the inputs given here . i know the basics of tower of Hanoi. i am not able to understand this part
Constraints:
1<= N<=8
3<= K<=5
Input Format:
N K
2nd line contains N integers.
Each integer in the second line is in the range 1 to K where the i-th integer denotes the peg to which disc of radius i is present in the initial configuration.
3rd line denotes the final configuration in a format similar to the initial configuration.
N and K are inputs where N is the number of disks and K is the number of pegs. But what is the initial configuration and final configuration here is an example.
Sample Input #00:
2 3
1 1
2 2
where 2 is the Number of disks and 3 is the number of pegs what the next line 1 1 and 2 2. can anyone please help me in understanding this problem and correct me if my understanding is wrong.

This sample input denotes: Both disks are on the first peg, and you should move them to the second peg.
Another sample input:
6 4
4 2 4 3 1 1
1 1 1 1 1 1
describes this placement:
5 1
6 2 4 3
_ _ _ _

Related

Extending Rabin-Karp algorithm to hash a 2D matrix

I'm trying to solve a problem here, it asks to find the size of the biggest common subsquare between two matrices.
e.g.
Matrix #1
3 3
1 2 0
1 2 1
1 2 3
Matrix #2
3 3
0 1 2
1 1 2
3 1 2
Answer: 2
Biggest common subsquare is:
1 2
1 2
I know that Rabin-Karp algorithm can be extended to work on a 2D matrix, but I can't understand how exactly can we do that, I tried to understand the author's code in the editorial, but its too complicated, I also did some search for a good explanation, but I couldn't find a clear one.
Can anyone simply explain how can I use Rabin-Karp algorithm to hash a matrix, I know I will hash rows and columns, but I can't see how to mix their hashes together to come up with a hashed matrix, and how the rolling hash function will be handled in this case ?

How to find out if numbers are different in pascal?

i can't solve one pascal problem, first i have to enter N which is the number or mesurments, next i enter those mesurments (if N is 5 i enter 5 mesurments for exmaple 3 4 5 6 7). After that i enter Q which is the number of times i check the number of different numbers in a specific part of the row. For example you have input
5 (number of mesurments)
1 2 3 3 4 (mesurments)
3 (number of checkings)
1 3
3 4
1 5 (left number is the starting number from the row, if it's 1 you start from 1, if it's 4 you start from 3 because 3 is the fourth mesurment and the right number is the last number if it's 5 it would be 4 because 4 is the fifth in the row)
And for output you would get
3
1
4 (for the first checking you have number from 1 to 3 (1 2 3) and you have 3 different numbers, second mesurment from 3 to 4 (3 3) and it's 1 different number and last from 1 to 5 there are 4 different numbers)
Hope you understod me, and thanks if you can solve it, i am in highschool now and i am preparing my self for something more complicating :) thanks in advance
The inequality operator of Pascal is <>

MATLAB: Conditionally matrix elements into two separate cell arrays

A matrix has 2 rows and several columns, and the first contains alternating strings of 1's and 0's. I want to use this binary as a decision to copy the information below it into one of two cell arrays. I understand that this can be done through iteration with the use of the IF conditional, or with while loops, but I'm having trouble cleaning it up.
For example, for
mat = [ 1 1 1 0 0 1 1 0 0 0 0 1 1 1 ;...
1 2 3 4 5 6 7 1 2 3 4 5 6 7 ]
I would like to output two cell arrays, one for the '1s', and one for the '0s':
1 2 3
6 7
5 6 7
and:
4 5
1 2 3 4
There are a couple of ways of doing this, I am sure. One might be using a loop; however, you can also make good use with the built-in find function. Below is a sample solution based on your example.
For '1s',
Here, we would like to get the indices with '1' from the first row.
on_array= mat(2, find(mat(1,:)));
or as suggested by #H.Muster
on_array= mat(2, mat(1,:)==1);
For '0s',
Here, we would like to get the indices with '0' from the first row.
off_array = mat(2, find(mat(1,:)==0));
or as suggested by #H.Muster
off_array= mat(2, mat(1,:)==0);
For the output format(the one that you want), i am sure you know what to do. Good luck.

Matlab - find a missing time from a matrix and insert the missing time with a value

I have a series of times and returns in various matrices lets call them a b c. They are all x by 2 with column 1 being times in seconds and column 2 returns. While all the returns are over a set series of time intervals like 15s 30s 45s etc the problem is not all the matrices have all the time buckets so while a might be a 30 by 2 , b might only be a 28 by 2. Because it is missing say time 45 seconds and a return. I want to go through each matrix and where I am missing a time bucket I want to insert the bucket with a zero return - I am happy to create a control 30 by 1 matrix with all the times that need to be cross referenced
You can use ismember to locate these missing positions, so if a is the control vector and b is the missing data vector ind=find(ismember(a,b)==0); will give you the indices of a that are missing in b.
For example:
a=1:10;
b=[1:2 4:5 7:10];
ind=find(ismember(a,b)==0);
ind =
3 6
In order to to add zeros in the right places for b just
for n=1:numel(ind)
b=[b(1:ind(n)-1) , 0 , b(ind(n):end)];
end
b =
1 2 0 4 5 0 7 8 9 10

how to make one layer perceptrons learn to show seven segments?

I was asked to write an algorithm to make seven one layer perceptrons learn to show seven segments number according to 4 0-1 inputs, for example
-1 -1 -1 -1 ==> 1 1 1 1 1 1 -1 % 0
-1 -1 -1 1 ==> -1 -1 -1 -1 1 1 -1 % 1
...
can any one help me, please
So, if I'm interpreting this correctly, you give your net a binary representation of a digit and you want it to tell you what line segments are needed to display that digit seven-segments style.
Luckily, since there are only 10 digits, you can just hand write a training set where each digit is correctly matched to the segments needed, and then use the standard perceptron training algorithm: the delta rule.
This algorithm will change the weights of the network until every input pattern is associated with the correct output pattern.
Implementation note: make sure all 4 input units are connected to all 7 output units, and that all of the connection weights start out at some small random value.