Exemple #1
0
        /// <summary>
        /// Fibonacci Search
        /// </summary>
        /// <param name="elem"></param>
        /// <param name="lo"></param>
        /// <param name="hi"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        private static int FibSearch(T[] elem, int lo, int hi, T e)
        {
            Fib fib = new Fib(hi - lo);

            while (lo < hi)
            {
                while (hi - lo < fib.Get())
                {
                    fib.Prev();
                }
                int mi = lo + fib.Get() - 1;
                if (Lt(e, elem[mi]))
                {
                    hi = mi;
                }
                else
                {
                    if (Lt(elem[mi], e))
                    {
                        lo = mi + 1;
                    }
                    else
                    {
                        return(mi);
                    }
                }
            }
            return(-1);
        }
        //
        // Some simple TPL scenario tests.
        //

        internal static bool RunTaskScenarioTests()
        {
            bool passed = true;

            // Matrix multiply:
            passed &= MatrixMultiplySample.Test(2);
            passed &= MatrixMultiplySample.Test(8);
            passed &= MatrixMultiplySample.Test(32);
            passed &= MatrixMultiplySample.Test(64);
            passed &= MatrixMultiplySample.Test(128);
            passed &= MatrixMultiplySample.Test(256);
            passed &= MatrixMultiplySample.Test(400);

            //// N-queens:
            NQueensTest.NQueens();

            //// Sorting:
            passed &= SortSample.Test(1024);
            passed &= SortSample.Test(16 * 1024);
#if !PFX_LEGACY_3_5
            passed &= SortSample.Test(16 * 1024 * 1024);
#endif
            // Some other random scenarios:
            passed &= Tree.Test();
            passed &= Fib.Test(8);
            passed &= Fib.Test(16);
#if !PFX_LEGACY_3_5
            passed &= Fib.Test(32);
#endif

            return(passed);
        }
        public void Given_5_Steps_BuildFib_Returns_Correct_Fib_List()
        {
            List <int> expected = new List <int> {
                1, 1, 2, 3, 5
            };
            List <int> actual = Fib.BuildFib(5);

            Assert.True(Equals(expected, actual));
        }
Exemple #4
0
    public static void Run()
    {
        Fib fib = new Fib();

        Console.WriteLine(fib.normalRecursive(5));
        Console.WriteLine(fib.memoCalendarFib(5));
        Console.WriteLine(fib.memoCalendarFibLoop(5));
        Console.WriteLine(fib.bestFib(5));
    }
Exemple #5
0
    public void t()
    {
        var fib = new[] { 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233 };

        for (int i = 0; i < fib.Length; ++i)
        {
            Assert.AreEqual(fib[i], Fib.Get(i));
        }
    }
Exemple #6
0
        //禁用 SetNetworkAdapter(False)
        //启用 SetNetworkAdapter(True)
        //添加引用system32\shell32.dll

/// <summary>
/// 通过网络连接名,修改网络启用,停用状态
/// </summary>
/// <param name="status">启用true,停用false</param>
/// <param name="pNetworkConnection">网络连接名</param>
/// <returns></returns>
        public static bool SetNetworkAdapterByShell(bool status, string pNetworkConnection)
        {
            const string discVerb = "停用(&B)"; // "停用(&B)";
            const string connVerb = "启用(&A)"; // "启用(&A)";
            const string network  = "网络连接";   //"网络连接";
            //const string networkConnection = this._netCardName; // "本地连接"

            string sVerb = null;

            if (status)
            {
                sVerb = connVerb;
            }
            else
            {
                sVerb = discVerb;
            }

            Shell32.Shell  sh     = new Shell32.Shell();
            Shell32.Folder folder = sh.NameSpace(Shell32.ShellSpecialFolderConstants.ssfCONTROLS);

            try
            {
                //进入控制面板的所有选项
                foreach (Shell32.FolderItem myItem in folder.Items())
                {
                    //进入网络连接
                    if (myItem.Name == network)
                    {
                        Shell32.Folder fd = (Shell32.Folder)myItem.GetFolder;
                        foreach (Shell32.FolderItem fi in fd.Items())
                        {
                            //找到本地连接
                            if ((fi.Name == pNetworkConnection))
                            {
                                //找本地连接的所有右键功能菜单
                                foreach (Shell32.FolderItemVerb Fib in fi.Verbs())
                                {
                                    if (Fib.Name == sVerb)
                                    {
                                        Fib.DoIt();
                                        return(true);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }
            return(true);
        }
Exemple #7
0
    public void TestPrivateFibViaRelfection(Fib fibData)
    {
        FibonacciGenerator fibonacciGenerator = new FibonacciGenerator();
        MethodInfo         methodInfo         = typeof(FibonacciGenerator).GetMethod("Fib", BindingFlags.NonPublic | BindingFlags.Instance);

        object[] parameters = { fibData.InitialValue };
        int      retVal     = (int)methodInfo.Invoke(fibonacciGenerator, parameters);

        Assert.Equal(fibData.ExpectedValue, retVal);
    }
Exemple #8
0
    public int value()
    {
        if(_value <= 2)
            return 1;

        Fib f1 = new Fib(_value - 1);
        Fib f2 = new Fib(_value - 2);

        return f1.value() + f2.value();
    }
Exemple #9
0
        public List <BigInteger> NumbersWithTwoSqrt()
        {
            List <BigInteger> sqrts = new List <BigInteger>();

            foreach (BigInteger element in Fib.Where(x => x.IsContainsTwo()).ToList())
            {
                sqrts.Add((BigInteger)Math.Exp(BigInteger.Log(element) / 2));
            }
            return(sqrts);
        }
Exemple #10
0
        // GET: Main
        public ActionResult Index()
        {
            List <int> fifteenFibs = new List <int>();
            Fib        fibInstance = new Fib();

            fifteenFibs             = fibInstance.returnListOfFib(15);
            ViewData["fifteenFibs"] = fifteenFibs;

            return(View());
        }
Exemple #11
0
        static void Main(string[] args)
        {
            Console.WriteLine(Factorial(5));
            Console.WriteLine(Fibonachi(6));

            Fib fib = null;

            fib = n => n > 1 ? fib(n - 1) + fib(n - 2) : 1;
            Console.WriteLine(fib(5));
            Console.Read();
        }
        public static void Main(string[] args)
        {
            int res;

            System.Console.WriteLine("Digite um valor: ");
            int num = int.Parse(System.Console.ReadLine());
            Fib fb  = new Fib();

            res = fb.cFib(num);
            System.Console.WriteLine(res);
            System.Console.ReadKey();
        }
Exemple #13
0
    public int value()
    {
        if (_value <= 2)
        {
            return(1);
        }

        Fib f1 = new Fib(_value - 1);
        Fib f2 = new Fib(_value - 2);

        return(f1.value() + f2.value());
    }
Exemple #14
0
        public BigInteger GetNumberWithMaxSumOfFiguresSquares()
        {
            BigInteger max    = 0;
            int        maxSum = 0;

            foreach (BigInteger element in Fib.Where(x => x.GetSquareOfFiguresSum() >= maxSum))
            {
                maxSum = element.GetSquareOfFiguresSum();
                max    = element;
            }
            return(max);
        }
Exemple #15
0
        public void Fib_Should_Generate_Iterative_N_6()
        {
            Fib fib  = new Fib();
            var fibs = fib.GenerateFibs(6, false);

            fibs.Length.Should().Be(7, "Incorrect length of fib(6).");
            fibs[1].Should().Be(1, "Incorrect value of fib_1");
            fibs[2].Should().Be(1, "Incorrect value of fib_2");
            fibs[3].Should().Be(2, "Incorrect value of fib_3");
            fibs[4].Should().Be(3, "Incorrect value of fib_4");
            fibs[5].Should().Be(5, "Incorrect value of fib_5");
            fibs[6].Should().Be(8, "Incorrect value of fib_6");
        }
Exemple #16
0
    static void Main()
    {
        View view = new View();
        Fib  fib  = new Fib(true);

        fib.Main();

        DateTime start = DateTime.Now;

        System.Threading.Thread.Sleep(20);// делаем паузу

        DateTime finish = DateTime.Now;

        Console.WriteLine(finish - start);

        view.Pause();
    }
Exemple #17
0
 public ActionResult <string> Get(int n)
 {
     _logger.LogInformation("Beginning a fibonnacci search!");
     try
     {
         //create new fib object and return the result
         var f   = new Fib();
         var res = f.FindFib(n);
         return(Ok(res.ToString()));
     }
     catch (OverflowException e) //catch any result overflow issues if it becomes too large
     {
         _logger.LogError(e.ToString());
     }
     //return generic error for security reasons
     return(BadRequest("Error has occurred"));
 }
Exemple #18
0
        /// <summary>
        /// 本地浏览器右键菜单“属性”条目事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LocalPopupMenuProperty_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            const string discVerb   = "属性(&R)";
            Point        p          = this.ListViewLocal.PointToClient(new Point(menutrippoint.X, menutrippoint.Y));
            string       sourceFile = LocalPath + ListViewLocal.GetItemAt(p.X, p.Y).Text;
            FileInfo     file       = new FileInfo(sourceFile);

            Shell32.Shell      shell      = new Shell32.Shell();
            Shell32.Folder     folder     = shell.NameSpace(file.DirectoryName);
            Shell32.FolderItem folderItem = folder.ParseName(file.Name);
            foreach (Shell32.FolderItemVerb Fib in folderItem.Verbs())
            {
                if (Fib.Name == discVerb)
                {
                    Fib.DoIt();
                    break;
                }
            }
        }
Exemple #19
0
        //锁定到任务栏
        public static void LockToTaskbar(bool isLock)
        {
            Shell shell = new Shell();

            Shell32.Folder folder = shell.NameSpace(Path.GetDirectoryName(Application.StartupPath + "\\Aurora Player.exe"));
            FolderItem     app    = folder.ParseName(Path.GetFileName(Application.StartupPath + "\\Aurora Player.exe"));
            string         sVerb  = isLock ? "锁定到任务栏(&K)" : "从任务栏脱离(&K)";

            foreach (FolderItemVerb Fib in app.Verbs())
            {
                if (Fib.Name == sVerb)
                {
                    Fib.DoIt();
                    return;
                }
            }

            return;
        }
Exemple #20
0
 public void CountFibonacci()
 {
     for (int i = 1; i < this.Amount + 1; i++)
     {
         BigInteger a = BigInteger.Zero;
         BigInteger b = BigInteger.One;
         for (int j = 31; j >= 0; j--)
         {
             BigInteger d = a * (b * 2 - a);
             BigInteger e = a * a + b * b;
             a = d;
             b = e;
             if (((i >> j) & 1) != 0)
             {
                 BigInteger c = a + b;
                 a = b;
                 b = c;
             }
         }
         Fib.Add(a);
     }
 }
Exemple #21
0
    public static void Main()
    {
        Fib x = new Fib(40);

        Console.WriteLine(x.value());
    }
Exemple #22
0
 public static void Main()
 {
     Fib x = new Fib(40);
     Console.WriteLine(x.value());
 }
Exemple #23
0
        public List <BigInteger> SortBySecondFigure()
        {
            List <BigInteger> SortedList = Fib.OrderByDescending(number => number.GetSecondFigure()).ToList();

            return(SortedList);
        }
Exemple #24
0
 public int CountPrime()
 {
     return(Fib.Where(x => x.isPrime()).ToList().Count);
 }
Exemple #25
0
 public void GivenDataFibonacciReturnsResultsOk(int number, Int64 result)
 {
     var fib = new Fib();
     var actual = fib.Fibonacci(number);
     Assert.AreEqual(result, actual);
 }
Exemple #26
0
 public void CreateTheFibonacciNumbers()
 {
     Assert.That(Fib.CreateNumbers().Take(6), Is.EqualTo(new [] { 1, 1, 2, 3, 5, 8 }));
 }
Exemple #27
0
 public int CountDivideByFiveNumbers()
 {
     return(Fib.Where(x => x % 5 == 0).ToList().Count);
 }
Exemple #28
0
 public int CountDivideByItFiguresNumbers()
 {
     return(Fib.Where(x => x.FiguresSum() != 0 && x % x.FiguresSum() == 0).ToList().Count);
 }
        public static void Main(string[] args)
        {
            CreateHeader();
            while (true)
            {
                Console.WriteLine("Input problem #:");
                string userInput     = "lis";
                int    problemNumber = 0;

                if (userInput == "sort")
                {
                    SortingAlgorithms SortingAlgorithms = new SortingAlgorithms();
                    SortingAlgorithms.Main();
                }
                else if (userInput == "LinkedList")
                {
                    LinkedListTest linkedList = new LinkedListTest();
                    linkedList.Main();
                }
                else if (userInput == "Fib")
                {
                    Fib fib = new Fib();
                    fib.Main();
                }
                else if (userInput == "lis")
                {
                    LISS lis = new LISS();
                    lis.Main();
                }
                else if (userInput == "search")
                {
                    SearchingAlgorithms search = new SearchingAlgorithms();
                    search.Main();
                }
                else
                {
                    bool validInput = Int32.TryParse(userInput, out problemNumber);
                    if (validInput)
                    {
                        switch (problemNumber)
                        {
                        case 1:
                            Problem1 problem1 = new Problem1();
                            problem1.Main();
                            break;

                        case 21:
                            Problem21 problem21 = new Problem21();
                            problem21.Main();
                            break;

                        case 29:
                            Problem29 problem29 = new Problem29();
                            problem29.Main();
                            break;

                        case 37:
                            Problem37 problem37 = new Problem37();
                            problem37.Main();
                            break;

                        case 44:
                            Problem44 problem44 = new Problem44();
                            problem44.Main();
                            break;

                        case 57:
                            Problem57 problem57 = new Problem57();
                            problem57.Main();
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }
Exemple #30
0
 /// <summary>
 /// Przygotowywanie odpowiedzi dla klienta
 /// </summary>
 /// <param name="ans">Numer przesłany przez klienta.</param>
 /// <returns>Wartość ciągu Fibonacciego dla numeru od klienta.</returns>
 public static int Start(int ans)
 {
     return(Fib.Fibonacci(ans));
 }
Exemple #31
0
 static void Test1()
 {
     Console.WriteLine("----Test1");
     Fib.Print();
 }