Code detection problem

For security reasons, messages are transmitted as a secret code over a transmission channel. It is usually sent as a sequence of bits, that is, 0s and 1s. Due to noise in the transmission channel, the transmitted message may become corrupted. That is, the message received at the destination may not be the same as the message transmitted. There are several techniques to check the validity of the transmitted message at the destination. One such technique is to transmit the same message twice. At the destination, both copies of the message are compared. Given a file "data.txt" with the messages that is transmitted, write a pseudocode and the subsequent Python program to check whether the message received at the destination is error-free. For simplicity, assume that the secret code representing the message is a sequence of digits(0 to 9) and the maximum length of the message is 250 digits. Each original message is followed by a copy of the message and the first number in both the messages indicate the length of the message. Each character in the message is separated by a space. For example, 7 9 2 7 8 3 5 6 7 9 2 7 8 3 5 6 means that the original message is of length 7 and it is 9 2 7 8 3 5 6 and copy of the  message is also of length 7 and it is 9 2 7 8 3 5 6. If the original and the copy of the message is same then print ‘message transmitted’ is ok’. Print ‘Message transmitted is not OK’ when the length of the original or the copy of the message is greater than 250 or when the original message is not same as copy of the message.
Input Format:
Name of the file
Input file contains a number of secret codes immediately followed by their copy
Output Format:
Print either ‘Message transmitted is ok’ or ‘Message transmitted is not ok’

Input:
name of the file

the secret code followed by the copy

Processing Involved:
file_check = open(name)
line = list(map(int,file_check.readline().rstrip().split()))
i = 0
j = line[i]+1
temp1 = []
temp2 = []
while True:
    temp1 = line[i+1:j]
    temp2 = line[j+1:j+1+line[i]]

    i = j+1 + line[i]
    if i < len(line):
        j = i + line[i] + 1
    else:

        break

Output:
Display whether the message transmitted is ok or not ok

Program:
name = input().rstrip()
file_check = open(name)
line = list(map(int,file_check.readline().rstrip().split()))
i = 0
j = line[i]+1
temp1 = []
temp2 = []
while True:
    temp1 = line[i+1:j]
    temp2 = line[j+1:j+1+line[i]]
    if temp1 == temp2:
        print('Message transmitted ok')
    else:
        print('Message transmitted is not ok')
    i = j+1 + line[i]
    if i < len(line):
        j = i + line[i] + 1
    else:
        break
Pseudocode:
Step1. Open the file whose name is taken as the input
Step2. assign line as the data stored in the file data.txt as a list
Step3. assign i as 0 and j as the sum of the value of the number at the zeroeth index position of line and 1
Step4. repeat  till the loop is not broken
Step4.1. check the messages contained in temp1 and temp2 using the lengths of the messages and do it till you reach the last message
Step4.2. display whether the message display is ok or not

Step5.End
        

    

4 comments:

  1. i got a error like Your program has exceeded the time limit allocated. Please check for infinite loops or other similar scenario in your code

    ReplyDelete
    Replies
    1. That is not possible..bcoz this is the exact code that i used to run the program and haven't changed it a bit...so there should be no issues

      Delete
  2. bro when we copy and paste the code ,i m running the code the code was gone and not saving the code

    ReplyDelete
    Replies
    1. This happened with me too...i dont know why...i just logged out and then logged in again

      Delete

Bonus Practice Problems(GMT To IST)

IST (Indian Standard Time) is 5 hours 30 minutes ahead of GMT(Greenwich Mean Time). Develop an algorithm and write the Python code to find...