Skip to main content

PROBLEM SHEET 3

This problem sheet was created by Sir Narasimhan T, Assistant Professor, IT Department LBS College of Engineering, Kasaragod.

The softcopy in .pdf is available here. There is  a bit more in the file.

1)A generalized Fibonacci sequence is a sequence of numbers such that from the third number onwards, each number is the sum of preceding two numbers. An example of generalized Fibonacci sequence is: 2, 5, 7, 12, 19, · · · · · · , but 1, 2, 3, 4, · · · · · · is not. You are to write a program that, given a sequence of numbers, decides whether the sequence is a generalized Fibonacci sequence or not.

2)There are 500 light bulbs (numbered 1 to 500) arranged in a row. Initially they are all OFF. Starting with bulb 2, all even numbered bulbs are turned ON. Next, starting with bulb 3, and visiting every third bulb, it is turned ON if it is OFF, and it is turned OFF if it is ON. This procedure is repeated for every fourth bulb, then every fifth bulb, and so on up to the 500th bulb. Write a C program to determine which bulbs are off at the end of the above exercise.

3)In the Indian currency system, the denominations available are 5, 10, 20, 50, 100, 500 and 2000. To make a sum of 2000, you can use twenty 100 notes or four 500 notes or even a singe 2000 note (and many other combinations are possible). But the last option takes the least number of currency notes. Given the available denominations and the sum (input from user), write a program to make the sum using the available denominations with the least number of currency notes. (Assume the sum is an integer and forget about coins!!!)

4)Write a program that inputs a list of integers and an integer called target, and then prints the pair of elements whose sum is target. A sample input and output is given below.
Input the list
1 6 5 4 2 3 9 12
Input the target
7
The pair of elements that add to 7 are
1     6
5     2
4     3

5)Two players start playing a game. The game board consists of N heaps arranged in a sequence, each containing certain number of coins. The figure shows such a board with 5 heaps.
HEAP 1    HEAP 2    HEAP 3    HEAP 4    HEAP 5
7 coins    2 coins      4 coins      3 coins     5 coins

The two players move alternately from each end. When a player moves, he chooses a heap from either the left end or the right end of the sequence, and removes the selected heap of coins from the sequence. The player should be consistent in the sense that if he chooses to remove heap from left end of sequence, he should continue with left end only. The game is over when the board is exhausted (no coins left). The player who has collected the maximum number of coins wins the game. Write a program to play this game. A sample input and output is shown below:
Input
Enter the number of heaps
5
Enter the number of coins in each heap
7 2 4 3 5
Enter the id (1 or 2) of the player who starts the game
2
Enter L to choose left end or R for right end
L
Output
Player 2 wins with 13 coins
[Player 2 starts with left end and takes off the heap 1. So he has 7 coins. Next player 1 chooses heap 5 from right and gets 5 coins. Next player 2 chooses heap 2 and now has a total of 9 coins. Then player 1 chooses heap 4 and gets 8 coins in total. Finally player 2 chooses heap 3 and has now 13 coins. The game ends now because player 1 has no heap to choose.]

6)Write a program to print the pattern by inputting the number of lines:
1 3 5 7 9
3 5 7 9
5 7 9
7 9
9

7)Write a program to print the pattern by inputting the number of lines:

1
2 6
3 7 10
4 8 11 13
5 9 12 14 15

8)Write a program to print the pattern by inputting the number of lines:

1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1

Comments

Popular posts from this blog

SNIFF GSM USING HACKRFX

​TOOLS  USED: •  ha ckrf_kali • brategnuradio-companion • gr-gsmgqrx • wireshark INSTALL REQUIREMENTS: First thing, you want to make sure you have all the required software installed, you can install most of them and their dependencies using your distribution package manager. Let’s start with the libraries and tools for the hackrf itself, on a Debian/Ubuntu distro you’ll install them like so: sudo  apt-get install  hackrf   libhackrf -dev libhackrf0 Once these libraries are installed, you can plug your hackrf into one of your USB ports and execute the  hackrf_info  command, at this point you should see something like the following: # hackrf_info Found  HackRF  board. Board ID Number: 2 ( HackRF  One) Firmware Version: 2014.08.1 Part ID Number: 0x00574746 0x00574746 Serial Number: 0x00000000 0x00000000 0x14d463dc 0x2f4339e1 You will now install  gnuradio  which is the software we’ll use to decode the RF signals,  gqrx  a tool to visualize signal power on certain frequencies

MORE ABOUT RANSOMWARES. PART 1

 Not long ago, a man committed suicide after an automatically generated notice from a computer virus threatened him with jail unless he paid a ransom thousands of dollars. The year was 2014. As incredible as the story seems, it marked the first known time a computer virus actually killed somebody. The next generations stole cash from users around the globe, and Cryptolocker raised the stakes – holding data of hundreds of thousands of users hostage. Despite successive short-lived take downs, the malware has made a comeback as CTB (Curve-Tor-Bitcoin) Locker. This challenging breed of malware is continuously improving, reaching new levels of complexity as smartphones and tablets are increasingly used to store crucial personal and enterprise-level documents. Bitdefender, the anti-malware solutions provider, zooms in on the subject to show how this type of virus works and to tell users how to prevent being locked out and extorted. What is ransomware? Ransomware is a type of malware th

TERMINAL ON ANDROID- TERMUX

Let Termux be our topic today. It is an Android application which is a Terminal Emulator distributed by Fredrik Fornwall. It creates exactly the same working environment of Linux Terminal on Android. Take a try. It can be installed from Google Play Store. Navigate from here . After the environment is set, go to App settings from the System Settings and give the App Storage permission.  Basic linux command like cd, ls, pwd, cat, touch and many more or almost all can be made here on this prompt. To install packages like Python or Pip type in packages install <packageName> It's that simple.  Similarly, to execute a program or a package, type <packageName> then, the corresponding help will be appear. Rest is with you. This is how an installation screen appears to be.. Now, about storage. As the initial step, type in termux-setup-storage Typing pwd gives the current working directory and it will be something like /data/data/com.termux/files/