Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio.h"
- #define SUCCESS 1;
- #define WRONG_SPACE 101;
- #define WRONG_AUTOMAT 102;
- void printBinary(int number, int bitsCount);
- int main(int argc, char* argv) {
- const int dimension = 1; // assignment
- const int colorsCount = 2; // assignment
- int space;
- unsigned long long rule;
- scanf_s("%d%llu", &space, &rule);
- if(space < 0 || space > 2) {
- printf_s("Chybna velikost okoli!\n");
- return WRONG_SPACE;
- }
- int exponent = 2*space + 1;
- int bitsCount = 1 << exponent;
- unsigned long long automataCount = ((unsigned long long) 1) << bitsCount;
- if(rule < 0 || rule > automataCount) {
- printf_s("Chybne cislo pravidla!\n");
- return WRONG_AUTOMAT;
- }
- // print the input
- printf_s("Velikost okoli: %d\n", space);
- printf_s("Pocet automatu: %llu\n", automataCount);
- printf_s("Cislo automatu: %d\n\n", rule);
- // print the rules
- for(int i = 0; i < bitsCount; i++) {
- printBinary(i, exponent); // the i in binary - bitsCount places, "." is zero, "*" is one
- char next = (rule & (1 << i)) > 0 ? '*' : '.';
- printf_s("\n%*c\n\n", exponent/2 + 1, next);
- }
- return SUCCESS;
- }
- void printBinary(int number, int bitsCount) {
- for(int i = 1 << bitsCount - 1; i > 0; i >>= 1) {
- printf_s("%c", (number & i) == i ? '*' : '.');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement