+ 1

What's the string here in the given program, although I asked in the comments there, no one's seems to have the answer

I kind of understood what this program is doing but have no clue how it's doing, not to mention the string characters totally clueless what those are and besides that the whole program seems complex I'd really appreciate if someone could explain what's inside the string character and what's after that- in shorts whole program Also if someone could make a python version of this, it would be really helpful Thank you guys in advance https://code.sololearn.com/coDQm0rfCej5/?ref=app

9th Nov 2021, 3:57 AM
A Mohammed Alhaan
A Mohammed Alhaan - avatar
4 odpowiedzi
+ 1
The string is a representation of a compression technique called Run-Length Encoding. Here the ASCII value of the first character encodes a number of spaces to print. (The number is shifted upward from the letter 'A'). The second character tells a number of exclamations to print. The scheme continues like that - spaces and exclamations - for every pair of characters. After every 80 characters of output an automatic newline is inserted. Here is my Python translation: # MAP OF INDIA rle = "TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq "\ + "TNn*RPn/QPbEWS_JSWQAIJO^NBELPeHBFHT}TnALVlBL"\ + "OFAkHFOuFETpHCStHAUFAgcEAelclcn^r^r\\tZvYxXyT|S~Pn SPm "\ + "SOn TNn ULo0ULo#ULo-WHq!WFs XDt!" b = 0 line = "" for a in rle: b ^= 1 line += ('!', ' ')[b]*(ord(a) - 64) if len(line)>=80: print(line[:80]) line = line[80:] That is it. I hope it helps!
9th Nov 2021, 7:00 AM
Brian
Brian - avatar
+ 1
Thanks a ton dude, rle is quite confusing but you made it pretty clear What's the fourth line In the code ? B ^=1 what does this do And another question is, is there any specific way to convert an image in rle like some software or something
10th Nov 2021, 3:58 AM
A Mohammed Alhaan
A Mohammed Alhaan - avatar
+ 1
Torg regarding your question whether there is a convenient way to play with RLE, my answer is: I do not know. It might be a good learning project to make your own. Some form of RLE is supported in several compressed image formats (.BMP, .TIFF, .PCX). It works efficiently with 2-tone images (black and white), but not so well with color.
10th Nov 2021, 6:04 AM
Brian
Brian - avatar
0
b ^= 1 uses bitwise exclusive or to make b switch from 0 to 1, then 1 to 0, and so on... which synchronizes with selecting ' ' or '!' every other RLE character. When b is 0: 0 ^ 1 = 1 When b is 1: 1 ^ 1 = 0
10th Nov 2021, 5:44 AM
Brian
Brian - avatar