示例#1
0
        public static int Problem1(string input)
        {
            var mem = new mem();

            var lines = input.Replace("\n", "\r").Split('\r').Where(e => !string.IsNullOrWhiteSpace(e)).ToArray();

            long pos = 0;

            var mulcount     = 0;
            var timesincemul = 0;
            var l            = 0;

            while (timesincemul < 1_000_000 && pos >= 0 && pos < lines.Count())
            {
                var op   = pos;
                var line = lines[pos];

                var p = line.Split(' ');

                timesincemul++;

                switch (p[0])
                {
                case "set":
                    mem.Set(p[1], mem.Get(p[2]));
                    break;

                case "sub":
                    mem.Set(p[1], mem.Get(p[1]) - mem.Get(p[2]));
                    break;

                case "mul":
                    mem.Set(p[1], mem.Get(p[1]) * mem.Get(p[2]));
                    mulcount++;
                    timesincemul = 0;
                    break;

                case "jnz":
                    if (mem.Get(p[1]) != 0)
                    {
                        pos += mem.Get(p[2]);
                        pos--;
                    }
                    break;
                }

                pos++;

                //Trace.WriteLine($"{op}: {line} ({pos})");
                //Trace.WriteLine(mem.ToString());

                l++;
                if (l % 1000 == 0)
                {
                    Trace.WriteLine($"{l}: {timesincemul}");
                }
            }

            return(mulcount);
        }
示例#2
0
 static mem[] m_mem;            //初始化 有500个可被分配的结构体
 static MyStringBuilder()
 {
     memCapcity = 500;
     m_mem      = new mem[500];
     for (int i = 0; i < memCapcity; i++)
     {
         m_mem[i] = new mem();
     }
 }
示例#3
0
        public static long Problem1(string input)
        {
            //input = "set a 1\nadd a 2\nmul a a\nmod a 5\nsnd a\nset a 0\nrcv a\njgz a -1\nset a 1\njgz a -2";

            var mem = new mem();

            var lines = input.Replace("\n", "\r").Split('\r').Where(e => !string.IsNullOrWhiteSpace(e)).ToArray();

            long pos = 0;

            long lastSound = 0;

            while (true)
            {
                var op   = pos;
                var line = lines[pos];

                var p = line.Split(' ');

                switch (p[0])
                {
                case "snd":
                    lastSound = mem.Get(p[1]);
                    break;

                case "set":
                    mem.Set(p[1], mem.Get(p[2]));
                    break;

                case "add":
                    mem.Set(p[1], mem.Get(p[1]) + mem.Get(p[2]));
                    break;

                case "mul":
                    mem.Set(p[1], mem.Get(p[1]) * mem.Get(p[2]));
                    break;

                case "mod":
                    mem.Set(p[1], mem.Get(p[1]) % mem.Get(p[2]));
                    break;

                case "rcv":
                    if (mem.Get(p[1]) != 0)
                    {
                        return(lastSound);
                    }
                    break;

                case "jgz":
                    if (mem.Get(p[1]) > 0)
                    {
                        pos += mem.Get(p[2]);
                        pos--;
                    }
                    break;
                }

                pos++;

                Trace.WriteLine($"{op}: {line} ({pos})");
                Trace.WriteLine(mem.ToString());
            }
        }
示例#4
0
 2 => new GZipStream(mem, CompressionMode.Decompress, true),