Recently, I found a way to generate specific blame for SmokeDetector. That was cool, so I decided to make a C++ program for it. I also have it on GitHub. This program is called Blame Bot.
Blame Bot does not need any flags to compile, so you can use make blame
to compile it.
How it works:
Blame Bot takes an input of a number. This input is your chat id. This number is taken from your chat link. Mine would be: https://chat.stackexchange.com/users/301688/grant-garrison, and my number would be 301688. Then, the number is converted to base 7. A switch statement then outputs the characters. (Note: the characters must be in double quotes.)
#include <iostream>
int main(){
int digit;
std::string stringDigit, answer, instring;
std::cin>>instring;
int in = std::stoi(instring,nullptr);
while (in != 0){
digit = in % 7;
if (digit < 10){
stringDigit = '0' + digit;
}else{
stringDigit = digit - 10 + 'A';
}
answer = stringDigit + answer;
in /= 7;
}
std::cout<<"!!/blame\u180E ";
int i = 0;
while(answer.length()>=i){
switch (answer[i]-'0'){
case 0: std::cout<<"\u180E";
break;
case 1: std::cout<<"\u200B";
break;
case 2: std::cout<<"\u200C";
break;
case 3: std::cout<<"\u200D";
break;
case 4: std::cout<<"\u2060";
break;
case 5: std::cout<<"\u2063";
break;
case 6: std::cout<<"\uFEFF";
break;
}
i++;
}
std::cout<<"a\n";
}
What I'm looking for:
I'm looking for efficiency and syntax improvements. I know the program is fast already, but any extra computation cut out is a bonus. I do want to leave the {
and }
on the if
statements though, as I think it improves readability for me. I also do not want to use any libraries.
What I think can be improved:
I think that switching back and forth from std::string
and int
is inefficient, and I'm sure there is a better way that doesn't need that. I also think that the base conversion algorithm might have a better replacement.
make blame
without a makefile (assuming GNU make). – Did you change your profile in response to this question? \$\endgroup\$