• Random Cube Algorithm


    本来我就是魔方爱好者,所有是魔友当然少不了pc端的计时器,以下是魔方打乱公式算法代码,语言:c#;

    public static string rndCube( int max ); 是获取随机打算字符串的入口函数;

    max就是打乱长度了。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    ////
    ////code by:chouhom
    ////
    namespace ConsoleApplication1
    {
        class Program
        {
            static string[] rndMove = new string[] { "R", "L", "F", "B", "U", "D" };
            static List<string> arr = new List<string>();
            static string[] Arr;
            static Random r = new Random();
            /// <summary>
            /// slice
            /// </summary>
            /// <param name="move1"></param>
            /// <param name="move2"></param>
            /// <returns></returns>
            public static bool slice(string move1, string move2)
            {
                int i = Convert.ToInt32(move1);
                int k = Convert.ToInt32(move2);
                if (i / 2 == k / 2)
                    return true;
                else return false;
            }
            /// <summary>
            /// random filter
            /// </summary>
            /// <param name="tmpRnd">int.tostring</param>
            /// <returns>false is yes</returns>
            public static bool checkmove(string tmpRnd)
            {
                Arr = arr.ToArray();
                if (Arr.Length > 0 && tmpRnd == Arr[Arr.Length - 1])
                    return true;
                else
                {
                    if (Arr.Length > 1 && tmpRnd == Arr[Arr.Length - 2] && slice(tmpRnd, Arr[Arr.Length - 1]))
                        return true;
                    else return false;
                }
            }
            /// <summary>
            /// create random cube string
            /// </summary>
            /// <param name="max">length</param>
            /// <returns>randomCube string</returns>
            public static string rndCube(int max)
            {
                string move = "";
                string tmpRnd;
                max++;
                for (int i = 0; i < max; i++)
                {
                    do { 
                        tmpRnd = r.Next(6).ToString(); 
                    }
                    while (checkmove(tmpRnd));
                    arr.Add(tmpRnd);
                }
                for (int i = 0; i < Arr.Length; i++)
                {
                    int tmp = r.Next(5);
                    if (tmp == 4) { move += rndMove[Convert.ToInt32(Arr[i])] + "2 "; }
                    else if (tmp == 2 || tmp == 3)
                    { move += rndMove[Convert.ToInt32(Arr[i])] + "' "; }
                    else
                    { move += rndMove[Convert.ToInt32(Arr[i])] + " "; }
                }
                return move;
            }
            static void Main(string[] args)
            {
                Console.Write(rndCube(15));
                Console.ReadKey();
            }
        }
    }
  • 相关阅读:
    Android内核sys_setresuid() Patch提权(CVE-2012-6422)
    Android驱动中的remap_pfn_range()校验漏洞(CVE-2013-2596)
    Android内核栈溢出与ROP(CVE-2013-2597)
    从android设备中提取内核
    Android: protecting the kernel
    Linux Kernel Stack
    Android 1.5-7.0(持续更新)安全机制一览
    stack-protector-strong
    ANDROID init进程
    mysql中相关,无关子查询,表与表之间的关系以及编码和乱码的解决
  • 原文地址:https://www.cnblogs.com/homchou/p/2861784.html
Copyright © 2020-2023  润新知