A nice sample of code that will render a spiral on your terminal screen. This could be useful indeed.

Posted: September 4, 2013. At: 11:00 AM. This was 4 years ago. Post ID: 6197
Page permalink.
WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters. These cookies expire two weeks after they are set.

This code sample will render a spiral on your terminal when you compile and execute it. Very interesting indeed.

#include <sstream>
#include <iostream>
#include <string>
 
std::string rle =
"32 [email protected] 1n16 [email protected] [email protected] 1n13 [email protected] [email protected] [email protected] 1n10 [email protected] [email protected] [email protected] 1n7 [email protected] [email protected] [email protected] "
"1n6 [email protected] [email protected] [email protected] [email protected] 1n4 [email protected] [email protected] [email protected] [email protected] [email protected] 1n3 [email protected] [email protected] [email protected] [email protected] [email protected] 1n3 "
"[email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]"
"1 [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] "
"[email protected] [email protected] [email protected] 1n3 [email protected] [email protected] [email protected] [email protected] 1n3 [email protected] [email protected] [email protected] [email protected] 1n4 [email protected] [email protected] [email protected] [email protected] 1"
"n6 [email protected] [email protected] [email protected] [email protected] 1n7 [email protected] [email protected] [email protected] 1n9 [email protected] [email protected] 1n12 [email protected] [email protected] 1n16 [email protected] [email protected]"
"16 1n22 [email protected] 1n";
 
int main()
{
	std::stringstream ss(rle);
	while (!ss.eof())
	{
		int n = 0;
		while (ss.peek() >= '0' && ss.peek() <= '9')
		n = n * 10 + ss.get() - '0';
		char c = ss.get();
		while (0 < n--)
			std::cout << (c != 'n' ? c : 'n');
		}
}

No comments have been made. Use this form to start the conversation :)

Leave a Reply