IF YOU LIKE THIS BLOG AND WANT MORE POSTS TELL ME IN THE COMMENTS! I HAVE A LOT OF PUZZLES AND TECH CONCEPTS TO SHARE. ESPECIALLY CONCEPTS CONCERNING C/ C++. IF YOU WANT ANSWERS TO ANY QUESTIONS, PLEASE E-MAIL ME info.edu.programming@gmail.com

I'LL CREATE POSTS THAT SPECIFICALLY CLARIFIES YOUR DOUBTS AND HELPS YOU IF YOU ASK FOR IT.

Pages

Tuesday, 31 May 2016

Programming puzzle 1 ( keep up with logic )


Let there be two arrays of sizes $m$ and $n$ respectively. The array $M$ of size $m$ contains a combination of these symbols: $S = {'p', 'q', 'r', 's', 't'}$ and the other array $N$ of size $n$ contains an array of numbers. These two arrays are read linearly. So to keep a track of the number of elements read and interpreted in both the arrays, there are two index variables $p_1$ and $p_2$ used. Each time an element in $M$ is read, $p_1$ increments. Each time an element in $N$ is read or manipulated, $p_2$ increments.

The below describes the pattern to be found in the array $M$, and also defines the rules of what must be done for each of the patterns found. Write a program to implement these rules and ensure that cases that can't be handled return with a proper error message.

Pattern
Rule
Pqrst
Swap the first with the second, the second with the third, the third with the fourth and the fourth with the fifth.
pqrs
This time, swap with the fifth number
pqr
This time, swap with the fourth number
pq
Swap the first number (at $p_2$ in $N$)with the third number.
q
Increment the number by one
r
Decrement the number by one
s
Square of the number is returned.
t
Cube of the number is returned.
P
Swap the first number (at the position $p_2$) with the second number
Note that, the pattern in the above table is arranged in the descending order of priority. That is, if pattern 'pqrst' is found, the corresponding rule is applied and not the other rules because it is of the highest priority.

Solve this by writing a program in C++ or any other language you prefer.

(the solution will be added shortly. In the meanwhile, be the first one to post the answer in the comments)

Sunday, 29 May 2016


THIS BLOG'S FIRST PUZZLE




There are 5 people. A, B, C, D and E. All five of them are to be seated in a linearly placed chairs. Each of them have specific preferences with sitting near each other. A wishes to sit next to C and B wishes to sit next to D. E prefers to sit on the right corner and D does not wish to sit besides A. How many arrangements are possible? list out the solution(s).


Solution: