Posted: . At: 11:00 AM. This was 11 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.

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

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 2@14 1n16 11@9 2@10 1n13 3@13 3@8 1@7 1n10 2@21 2@7 1@5 1n7 2@27 1@6 1@4 "
"1n6 1@10 10@10 2@5 2@2 1n4 2@7 4@9 4@9 1@5 1@2 1n3 2@6 3@15 3@8 1@5 1@1 1n3 "
"1@6 2@18 3@7 2@5 1@1n2 1@6 2@20 3@7 1@5 1@1n2 1@5 2@21 3@7 1@5 1@1n1 2@5 2@2"
"1 3@7 1@5 1@1n1 2@5 2@11 3@6 3@8 1@5 1@1n2 1@5 2@11 11@8 2@5 1@1n2 1@6 2@11 "
"8@9 2@5 1@1 1n3 1@6 2@26 2@5 2@1 1n3 2@6 2@24 2@5 2@2 1n4 2@6 3@20 2@6 2@3 1"
"n6 1@8 3@14 3@7 1@5 1n7 2@9 13@9 2@6 1n9 2@27 1@9 1n12 3@19 3@11 1n16 5@7 4@"
"16 1n22 5@21 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');
		}
}

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.