C++ code to draw an India map (and maybe other countries too)

Mohith Gupta
Geek Culture
Published in
3 min readAug 16, 2021

Hey reader, hope you are doing good despite the pandemic giving us the “sit idle at home and regret your life decisions” thoughts.

Today’s post would be small but quite interesting. I hope you are excited, so let’s get started!

Prerequisites: Copy-paste feature on your device OR you can also write the whole code again :p

NOTE: I do not own this code, just found it on the internet and thought of sharing it.

Try running the code, it looks beautiful!

The following code when executed generates the map of India:

#include <stdio.h>int main(){    int a,b,c;
int count = 1;
for ( b=c=10 ; a=”- FIGURE?, UMKC,XYZHello Folks,\TFy!QJu ROo
TNn(ROo)SLq SLq ULo+\UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^\
NBELPeHBFHT}TnALVlBLOFAkHFOuFETp\HCStHAUFAgcEAelclcn^r^r\\tZvYxXy\
T|S~Pn SPm SOn TNn ULo0ULo#ULo-W\Hq!WFs XDt!” [b+++21] ; ){
for(; a → 64 ; ){//This loop draws individual characters, and a newline whenever it reaches the end of line putchar ( ++c==’Z’ ? c = c/ 9:33^b&1);
}
}
return 0;
}

A bit complex right?

Notice [b+++21] at the end of the encoded string. As b+++21 is equivalent to (b++ + 21) which will evaluate to 31 (10 + 21), the first 31 characters of this string are ignored and do not contribute to anything. The remaining encoded string contains instructions for drawing the map. The individual characters determine how many spaces or exclamation marks to draw consecutively.

Ok, let’s see a little bit less complex code :

#include <iostream>
using namespace std;
int main(){
int a = 10, b = 0, c = 10; // The encoded string after removing first 31 characters char* str = "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!";
// string's individual characters determine how many spaces or exclamation marks to draw consecutively. while (a != 0){

a = str[b++];

while (a-- > 64){
if (++c == 90) {
c = 10;
putchar('\n');
}
else{
if (b % 2 == 0)
putchar('!');
else
putchar
(' ');
}
}
}
return 0;
}

Now, you might be able to understand the loops but not the string.

Basically, the string is a run-length encoding of the map of India. It means that the same data value may occur in the data elements and it is stored as a single data value.
Alternating characters in the string store how many times to draw a space, and how many times to draw an exclamation mark consecutively.

I don’t know how to do this for the other countries. It should be possible cause it was possible for the India map, but only with some serious thought and work put into it.

Reference: https://stackoverflow.com/questions/3533348/how-does-this-code-generate-the-map-of-india

I’m done with the better version of I Coded a Script to Download the “Download Restricted” Files from Google Drive. So, the next post will probably be on that or maybe not 😜

Please consider showing your appreciation by providing feedback and suggestions in the comment section.

If you are pleased too much, you can always buy me a coffee 😉

buy me a coffee link

And that’s it for today, see you in the next one. Au revoir!

You can read some of my other posts :

Play YouTube Videos on VLC with Just 1 Click
Convert Your ‘.py’ to a ‘.exe’ File with Just 2 Commands
All You Need to Know About the “Fetch API” in JavaScript
I Coded a Script to Download the “Download Restricted” Files from Google Drive

For further doubts and else, you can ping me on mohithguptak@gmail.com or find me on Twitter.

Sign up to discover human stories that deepen your understanding of the world.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Mohith Gupta
Mohith Gupta

Written by Mohith Gupta

A Better Person than Yesterday, I guess? In the process of Learning

Responses (1)

Write a response