0% found this document useful (0 votes)
38 views6 pages

Logic Building

The document outlines a series of programming tasks that involve string manipulation, number processing, and array handling. Tasks include adding large numbers represented as strings, decoding an encoded array, calculating string codes based on letter positions, analyzing sequences in arrays, and encoding three strings into specific formats. Each task is accompanied by examples and specific requirements for implementation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views6 pages

Logic Building

The document outlines a series of programming tasks that involve string manipulation, number processing, and array handling. Tasks include adding large numbers represented as strings, decoding an encoded array, calculating string codes based on letter positions, analyzing sequences in arrays, and encoding three strings into specific formats. Each task is accompanied by examples and specific requirements for implementation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1 ) Addition using Strings

Write a function that takes two numbers in string format and forms a string containing the sum (addition) of
these two numbers
Assumption(s):

The input strings will contain only numeric digits

• The input strings can be of any large lengths

The lengths of the two input string need not be the same

The input strings will represent only positive numbers

For example -

If input strings are "1234" and "56" the output string should be "1290-

If input strings are '56" and "1234" the output string should be "1290

If input strings are 123456732128989543219" and "987612673489652" the output string should be
"123457719741663032871

NOTE: in Java & C#, this logic can be easily implemented using Biginteger However for the sake of
enhancing your programming skills, you are recommended to solve this question without using BigInteger

2 ) Simple Encoded Array


Maya has stored few confidential numbers in an array (array of int). To ensure that others do not find the
numbers easily, she has applied a simple encoding. Encoding used: Each array element has been substituted
with a value that is the sum of its original value and its succeeding element's value.

i.e. arr[i] = original value of arr[i] + original value of arr[i+1] e.g. value in arr[0] = original value of arr[0] +
original value of arr[1] Also note that value of last elemint i.e. arr[last index] remains unchanged.

For example,

If the encoded array is (7,6,8,16,12,3) The original array should have been (2,5,1,7,9,3)

Provided the encoded array, you are expected to find the - a. First number (value in index 0) in the original
array

b. Sum of all numbers in the original array


3 ) FindStringCode
Crazy Zak has designed the below steps which can be applied on any given string (sentence) to produce a
number.

STEP1. In each word, find the Sum of the Difference between the first letter and the last letter, second letter
and the penultimate letter, and so on fill the center of the word.

STEP2. Concatenate the sums of each word to form the result,

For example

If the given string is "WORLD WIDE WEBT

STEP1. In each word, find the Sum of the Difference between the first letter and the

last letter, second letter and the penultimate letter, and so on till the center of the word. WORLD [W-
DJ+JOL+R) [23-4-15-12)+[18][199+3)+(18)[40] WIDE [W-E]+[1-DJ-123-5-19-41-118)-(5)-(21

WEB [W-B]+[E][23-2)+(5)-121]+5)+(26)

STEP2. Concatenate the sums of each word to form the Sult

[40] [23] [26]

The answer (output) should be the number 402326.

[402326]

NOTE1: The value of each letter is its position in the English alphabet system Le a=A=1, b=B=2, c=C-3,
and so on till 2-2-26 So, the result will be the same for "WORLD WIDE WEB" or "World Wide Web" or
"world wide web or any other combination of uppercase and lowercase letters
IMPORTANT Note: In Step1, after subtracting the alphabets, we should use the absolute values for
calculating the sum. For instance, in the below example, both [H-O] and [E-L] result in negative number -7,
but the positive number 7 (absolute value of -7) is used for calculating the sum of the differences

Hello

[H-O]+[E-L]+[L]=[8-15]+[5-12]+[12][7]+[7]+[12] = [26]

Assumptions: The given string (sentence) will contain only alphabet characters and there will be only one
space character between any two consecutive words.

You are expected to help Zak, by writing a function that takes a string (sentence) as input, performs the
above mentioned processing on the sentence and returns the result (number),

Example1: input1= "World Wide Web output1402326

Example2: input1 "Hello World"

output1 2640 Explanation:


Hello [H-O]+[E-L]+[L][8-151-15-12-127-17 [12]=[26] World = [W-D]+[O-L]+[R) [23-4]+[15-12]+[18]
[19]+[3]+[16](40) Result Number formed by concatenating (26) and (40) = 2640

4 ) Decreasing sequence:
Given an integer array, find the number of decreasing sequences in the array and the length of its longest
decreasing sequence.

You are expected to complete the logic within the given function, where,

input1 represents the integer array and, input2 represents the number of elements in the integer array

The function should set the output1 variable to the number of decreasing sequences in the array, and set the
output2 variable to the length of the longest decreasing sequence in the array.

5 ) Sum of Powers of Digits


Alex has been asked by his teacher to do an assignment on powers of numbers. The assignment requires
Alex to find the sum of powers of each digit of a given number, as per the method mentioned below.

If the given number is 582109, the Sum of Powers of Digits will be calculated as = = (5 raised to the power
of 8) + (8 raised to the power of 2) + (2 raised to the power of 1) (1 raised to the power of 0) + (0 raised to
the power of 9) + (9 raised to the power of 0)

Let each digit of the number is raised to the power of the next digit on its right-side Note that the right-most
digit has to be raised to the power of 0. The sum of all of these powers is the expected result to be calculated.

Example If the given number is 582109, the Sum of Powers of Digits = = (5 raised to the power of 8) + (8
raised to the power of 2) + (2 raised to the power of 1)+ (1 raised to the power of 0) (0 raised to the power of
9) + (9 raised to the power of 0)

39062564+2+1+0+1=390693

Alex contacts you to help him write a program for finding the Sum of Powers of Digits for any given
number, using the above method.

Write the logic in the given function sumOfPowerOfDigits where input1 represents the given number.

The function is expected to return the "Sum of Powers of Digits of input1.

Assumptions: For this assignment, let us assume that the given number will always contain more than 1
digit, ie the given number will always be >9

6 ) Sum of Sums of Digits in Cyclic order:


Alex has been asked by his teacher to do an assignment on sums of digits of a number. The assignment
requires Alex to and the sum of sums of digits of a given number, as per the method mentioned below.

If the given number is 582109, the Sum of Sums of Digits will be calculated as =
(5+8+2+1+0+9)+(8+2+1+0+9)+(2+1+0+9)+(1+0+ 9)+(0+9)+(9) 25+20+12+10+9+9 = 85
Alex contacts you to help him write a program for finding the Sum of Sums of Digits for any given number,
using the above method.

Help Alex by completing the logic in the given function sumOfSumsOfDigits which takes as input an
integer input1 representing the given number. The function is expected to return the "Sum of Sums of
Digits" of input1.

Assumptions: For this assignment, let us assume that the given number will always contain more than 1
digit, i.e. the given number will always be >9.

7) Identify possible words:


Detective Bakshi while solving a case stumbled upon a letter which had many words whose one character
was missing i.e. one character in the word was replaced by an underscore. For e.g. "Fi_er". He also found
thin strips of paper which had a group of words separated by colons, for e.g. "Fever:filer Filter:Fixer.fiber
fibre:tailor:offer". He could figure out that the word whose one character was missing was one of the
possible words from the thin strips of paper. Detective Bakshi has approached you (a computer programmer)
asking for help in identifying the possible words for each incomplete word.

You are expected to write a function to identify the set of possible words. The function identify Possible
Words takes two strings as input where,

input1 contains the incomplete word, and input2 is the string containing a set of words separated by colons.
The function is expected to find all the possible words from input2 that can replace the incomplete word
input1, and return the result in the format suggested below.

Example1 -

input1 = "Fi_er"

input2 = "Fever:filer:Filter:Fixer:fiber:fibre:tailor.offer

output string should be returned as "FILER:FIXER:FIBER"

Note that -

• The output string should contain the set of all possible words that can replace the incomplete word in
input1

• all words in the output string should be stored in UPPER-CASE


• all words in the output string should appear in the order in which they appeared in input2, i.e, in the above
example we have FILER followed by FIXER followed by FIBER.

• While searching for input1 in input2, the case of the letters are ignored, i.e "Fi_er" matches with "filer" as
well as "Fixer" as well as "fiber".

• IMPORTANT: If none of the words in input2 are possible candidates to replace input1, the output string
should contain the string "ERROR-009"

Assumption(s):
• Input1 will contain only a single word with only 1 character replaced by an underscore""

• Input2 will contain a series of words separated by colons and NO space character in between

• Input2 will NOT contain any other special character other than underscore and alphabetic characters.

8) Encoding Three Strings:


Anand was assigned the task of coming up with an encoding mechanism for any given three strings. He has
come up with the below plan.

STEP ONE: Given any three strings, break each string into 3 parts each. For example - If the three strings
are as below

Input1 = "John"

Input2= "Johny"

Input3= "Janardhan"

"John" should be split into "J", "oh", "n" as the FRONT, MIDDLE and END parts

respectively. "Johny" should be split into "Jo", "h", "ny" as the FRONT, MIDDLE and END parts
respectively.

"Janardhan" should be split into "Jan", "ard", "han" as the FRONT, MIDDLE and END

parts respectively. i.e. if the no. of characters in the string are in multiples of 3, then each split-part will

contain equal no. of characters, characters, as seen in the example of "Janardhan"

If the no. of characters in the string are NOT in multiples of 3, and if there is one character more than
multiple of 3, then the middle part will get the extra character, as seen in the example of "John"

If the no. of characters in the string are NOT in multiples of 3, and if there are two characters more than
multiple of 3, then the FRONT and END parts will get one extra character each, as seen in the example of
"Johny"

STEP TWO: Concatenate (join) the FRONT, MIDDLE and END parts of the strings as per the below
specified concatenation-rule to form three Output strings. Output1 = FRONT part of Input1 + FRONT part
of Input2 + FRONT part of Input3 Output2 = MIDDLE part of Input1 + MIDDLE part of Input2 +
MIDDLE part of Input3 Output3 = END part of Input1 + END part of Input2 + END part of Input3 For
example, for the above specified example input strings. Output1 = "J" + "Jo" + "Jan" = "JJojan" Output2=
"oh" + "h" + "ard" = "ohhard"

Output3 = "n" + "ny" + "han" = "nnyhan"

Step THREE: After the first two steps, we will have three output strings. Further
processing is required only for the third output string as per below rule "Toggle the case of each character in
the string", i.e. in the third output string, all lower-case characters should be made upper-case and vice versa.
For example, for the above example strings, Output3 is "nnyhan", so after applying the toggle rule, Output3
should become "NNYHAN".

Final Result - The three output strings after applying the above three steps is the final result. i.e. for the
above example,

Output1 = "Dolan"

Output2 = "ohnard

Output3NNYHAN"

Anand approaches you to help him write a program that would do the above mentioned prosessing on any
given three strings and generate the resulting three output strings

Note that the three output strings should be returned as members of a "Result" object/struct

You might also like