Advertisement
Guest User

Untitled

a guest
May 26th, 2015
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #ifndef TURMITE_H_
  2. #define TURMITE_H_
  3.  
  4. #include <iostream>
  5.  
  6. const char *rand_file() {
  7. char *filename = new char[1024];
  8. sprintf(filename, "turmite_%zd.rule", time(NULL));
  9. return filename;
  10. }
  11.  
  12. void dump_transistions(const char *filename, unsigned int states, unsigned int symbols, uint32_t *transistions) {
  13. FILE *f = fopen(filename, "w");
  14. const char *actions = "LRFU";
  15. fprintf(f, "%d %d\n", states, symbols);
  16. printf("%d %d\n", states, symbols);
  17. for(unsigned int s = 0; s < states; s++) {
  18. for(unsigned int c = 0; c < symbols; c++) {
  19. int idx = (s * symbols + c) * 3;
  20. uint32_t next_action = transistions[idx + 0];
  21. uint32_t next_symbol = transistions[idx + 1];
  22. uint32_t next_state = transistions[idx + 2];
  23. printf("%u %u -> %u %u %u\n", s, c, next_action, next_symbol, next_state);
  24. fprintf(f, "%c %u %u\n", actions[next_action], next_symbol, next_state);
  25. }
  26. }
  27. fclose(f);
  28. }
  29.  
  30.  
  31. #endif /* !TURMITE_H_ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement