Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Discussion Basic Fractal Numbers

Discussion in 'Scripting' started by fournicknet, Jan 20, 2023.

  1. fournicknet

    fournicknet

    Joined:
    Jan 8, 2013
    Posts:
    13
    The following is code that I created to create my fractal nubmers, sharing it with the community if it will help. I can get it to go up to 91 iterations with out breaking because of the 64 bit limitation. I'm sure there is another way to get above 91 iterations and if you do I would encourage you to respond to this post if you feel inclined to do so.

    Code (CSharp):
    1. internal class Program
    2.     {
    3.         static private long firstNumber, secondNumber, result;
    4.         static void Main(string[] args)
    5.         {
    6.             firstNumber = 0;
    7.             secondNumber = 1;
    8.             result = 0;
    9.  
    10.             for (int i = 0; i < 100; i++)
    11.             {
    12.                 result = firstNumber + secondNumber;
    13.                 Console.WriteLine("Level " + i + " is " + result);
    14.                 secondNumber = firstNumber;
    15.                 firstNumber = result;
    16.             }
    17.             Console.ReadLine();
    18.         }
    19. }
     
    Colonel_Campbell likes this.
  2. Deleted User

    Deleted User

    Guest

    This is a variant of the Fibonacci sequence. Except it's slightly different because you set the
    secondNumber = firstNumber
    instead of
    secondNumber = result
    , which just delays the sequence by 1 (the first iteration swaps
    firstNumber
    and
    secondNumber
    .

    ...yeah...
     
    fournicknet and Colonel_Campbell like this.
  3. fournicknet

    fournicknet

    Joined:
    Jan 8, 2013
    Posts:
    13
    I took it for granted that it worked after line 20, good catch.
     
    Colonel_Campbell likes this.
  4. fournicknet

    fournicknet

    Joined:
    Jan 8, 2013
    Posts:
    13
    It is if you are using it for GameDevelopment, like a leveling system