Advertisement
Guest User

Untitled

a guest
Aug 14th, 2014
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ConsoleApplication2 {
  6.     class Program {
  7.         static void Main(string[] args) {
  8.             int count = 0;
  9.  
  10.             for (int i = 1; i <= 0x7fff; i++) {
  11.                 var sequence = Generate6ShiftSequence(i);
  12.                 var steps = sequence.Count();
  13.  
  14.                 if (steps != 93) {
  15.                     count++;
  16.  
  17.                     Console.WriteLine("${0:x4} -> {1} steps", i, steps);
  18.                 }
  19.             }
  20.  
  21.             Console.WriteLine(count);
  22.         }
  23.  
  24.         private static IEnumerable<int> Generate1ShiftSequence(int seed) {
  25.             int value = seed;
  26.  
  27.             do {
  28.                 yield return value;
  29.  
  30.                 int bit0 = (value >> 0) & 1;
  31.                 int bit1 = (value >> 1) & 1;
  32.  
  33.                 value = (value >> 1) | ((bit0 ^ bit1) << 14);
  34.             }
  35.             while (value != seed);
  36.         }
  37.  
  38.         private static IEnumerable<int> Generate6ShiftSequence(int seed) {
  39.             int value = seed;
  40.  
  41.             do {
  42.                 yield return value;
  43.  
  44.                 int bit0 = (value >> 0) & 1;
  45.                 int bit6 = (value >> 6) & 1;
  46.  
  47.                 value = (value >> 1) | ((bit0 ^ bit6) << 14);
  48.             }
  49.             while (value != seed);
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement