Create the REV function from Swap

We have a function REV(“string”,m,n).This function is capable of reversing the caharacters in the string from mth location to nth location. e.g. REV(“abcd”,2,3); the output will be acbd We need to swap a string from a position,e.g. SWAP(“abcdefg”,4)  output needs to be efgabcd.
How can the REV function used do this.

Solution
 ANS : L = string length,N= position given in SWAP function.
SWAP(“abcdefg”,4) = REV(REV(REV(“abcdefg”,N+1,L),1,N),1,L).

Is there multiply function in 8085 microprocessor

There is no multiplication instruction in the 8085 - I believe that was added in the 8086 & 8088 version of the series. This has the entire instruction set for the 8085: These operations are equivilent to multiplying by 2: Shift left by 1 (shifting left by n is multiplying by 2^n) Add the value to itself once. Other than that you can write a loop to add the number to itself ‘n’ times. [Read More]

Stone thrown from the boat

Problem Will there be any change in water level/height of floating part of the boat if stones are dropped into the pond from a floating boat? Follow up - What if you are given empty 2L bottle and chained under the boat? Solution There is maybe a little physics needed here… When an object is floating be it because it is something less dense than water, say polystyrene, or because it is in a boat, say a brick and the whole boat is less dense than water, then it displaces in the water it’s own mass. [Read More]

Number of rectangles in MxN matrix.

Problems Count number of squares in chessboard? Count number of rectangles in MXN rectangle Squares in rectangle Lets answer them 1 by 1. Solution Number of squares in chessboard having 8X8 grid. There are four 7x7 squares, one aligned with each corner. There are nine 6x6 squares, etc. So the sum of the first 8 squares 1+4+9+16+25+36+47+64=204 is the answer. In general, the sum of the first n squares is given by the formula [Read More]

Three children

Problem :

Tom’s mother has three children. One is named April, one is named May. What is the third one named?

Solution :

Tom

Black Dog, Black-out and Driver Problem

Problem : A completely black dog was strolling down Main Street during a total blackout affecting the entire town. Not a single streetlight had been on for hours. Just as the dog was crossing the middle line a Buick Skylark with 2 broken headlights speedily approaches his position, but manages to swerve out of the way just in time. How could the driver have possibly seen the dog to swerve in time? [Read More]

Inhereting wealth from wise Sheikh

Problem : An Arab sheikh tells his two sons to race their camels to a distant city to see who will inherit his fortune. The one whose camel is slower will win. The brothers, after wandering aimlessly for days, ask a wise man for advise. After hearing the advice they jump on the camels and race as fast as they can to the city. What does the wise man say? [Read More]

Book worm

Problem : A bookworm eats from the first page of an encyclopedia to the last page. The bookworm eats in a straight line. The encyclopedia consists of ten 1000-page volumes and is sitting on a bookshelf in the usual order. Not counting covers, title pages, etc., how many pages does the bookworm eat through? Solution :  On a book shelf the first page of the first volume is on the “inside” [Read More]

Alarm clock with snooze interval of 9

Problem : Why is it very common to have a 9 minute snooze interval on alarm clocks, why not 10 instead? **** Solution :  By setting the snooze time to 9 minutes, the alarm clock only needs to watch the last digit of the time. So, if you hit snooze at 6.45, the alarm goes off again when the last digit equals 4. They couldn’t make it 10 minutes, otherwise the alarm would go off right away, or it would take more circuitry. [Read More]

The U2 riddle

Problem : U2 has a concert that starts in 17 minutes and they must all cross a bridge to get there. All four men begin on the same side of the bridge. You must help them across to the other side. It is night. There is one flashlight. A maximum of two people can cross at one time. Any party who crosses, either 1 or 2 people, must have the flashlight with them. [Read More]