Page 2 of 4 FirstFirst 1234 LastLast
Results 26 to 50 of 93

Thread: Project Sigma!

  1. #26
    Join Date
    Dec 2011
    Posts
    257
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Sytherix View Post
    What he is trying to tell you is that you must find the first occurrence of "x". A.K.A "At which point you first notice x".

    In example 1, x=6. Therefore you look at the numbers and notice that x is the third number in, henceforth the result is 3.

    [1 (first number), 3 (second number), 6(third number), 8(fifth number).

    As you can see, the result is 3. You are not trying to solve what x itself equals, rather what position x has in a list of numbers.
    Oh I get it now, thankyou Say x is 4, and the sequence is 2, 4 ,6, the answer is 2? But you need to make a script that does that. Can anyone point me to any tutorials?
    Last edited by sm321; 03-05-2012 at 11:09 AM.

  2. #27
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Quote Originally Posted by Kyle Undefined View Post
    Are you basing the index number from 1 or 0? Technically, your examples should read 1 less, since arrays start with 0.
    The conventional position Not the index.
    Last edited by Daniel; 03-05-2012 at 09:26 AM.
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  3. #28
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Quote Originally Posted by sm321 View Post
    Oh I get it now, thankyou Say x is 4, and the sequence is 2, 4 ,6, the answer is 2? But you need to make a script that does that. Can anyone point me to any tutorials?
    There is not really a tutorial for that. This is a basic tutorial on arrays. If you ignore the color finding part this might help you. I will not give more help as this is an competition. Good luck!
    Working on: Tithe Farmer

  4. #29
    Join Date
    Oct 2011
    Location
    UK
    Posts
    1,322
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    I have sent you my submission for the intermediate competition, not really sure what a signed integer is, actually I might look it up and then have a go...

    --edit:--
    ok got that sorted, not quite sure what is ment by the sorting, do we choose one method of sorting (eg ascending or descending) or do we make out script able to do all of them?

    --edit2:--
    I now have a script working for the advanced one but I am not sure if I have understood it correctly since I seemed to find it easier than the intermediate one :/
    Last edited by putonajonny; 03-06-2012 at 12:14 AM.

  5. #30
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Quote Originally Posted by putonajonny View Post
    I have sent you my submission for the intermediate competition, not really sure what a signed integer is, actually I might look it up and then have a go...

    --edit:--
    ok got that sorted, not quite sure what is ment by the sorting, do we choose one method of sorting (eg ascending or descending) or do we make out script able to do all of them?

    --edit2:--
    I now have a script working for the advanced one but I am not sure if I have understood it correctly since I seemed to find it easier than the intermediate one :/
    Hi put!

    You noticed that I was rather ambiguous on the type of sorting that I want This means that you can use any sorting method (not including intelligent design sort), as long as it is sorted in one way, shape or form. You only need to sort the array once, with one method.
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  6. #31
    Join Date
    Dec 2011
    Location
    Australia
    Posts
    174
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Submitted my intermediate
    I'm sure I made it more complex than it should be, butmeh.
    My Scripts:
    MethDwarfMiner - A Resource Dung Coal Miner

    MethLarder - Oak Larder Maker #~# Oak Door Maker - MethDoorer
    MethSudokuLITE - Small Casket Sudoku Solver (MEMBERS+ ONLY)

  7. #32
    Join Date
    Oct 2011
    Location
    UK
    Posts
    1,322
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by Daniel View Post
    Hi put!

    You noticed that I was rather ambiguous on the type of sorting that I want This means that you can use any sorting method (not including intelligent design sort), as long as it is sorted in one way, shape or form. You only need to sort the array once, with one method.
    Thanks very much for that, I have:
    Simba Code:
    //Input
    3;
    5;
    [0, 3, 5, 9, 3, 9, 5, 1];

    //Output
    [0, 1, 3, 3, 5, 5, 9, 9]
    [3, 4]
    [5, 6]

    ? Thats what I have working atm, based on the fact I already submitted my intermediate is it worth posting that too? / Have I got the right end of the stick? :P

    Quote Originally Posted by Methrend View Post
    Submitted my intermediate
    I'm sure I made it more complex than it should be, butmeh.
    it's on!


    Could you confirm you received my submission? Maybe a list of people on the OP would be good?

    Make sure that X, Y and array are defined constants at the beginning of your script
    Can you make arrays constants? if so how? :P (I know you could make each integer in it a constant, but then the array length would be limited)

  8. #33
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Simba Code:
    const
      constantArray = [3,5,6,8,3];
    Working on: Tithe Farmer

  9. #34
    Join Date
    Oct 2011
    Location
    UK
    Posts
    1,322
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    Simba Code:
    const
      constantArray = [3,5,6,8,3];
    Code:
    [Error] (5:19): Syntax error at line 4

  10. #35
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    Use lape.

  11. #36
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default


    Week #1:

    Beginner:
    Find-A-Number! -
    Write a program that finds the position of the first occurrence of X in a sorted array of whole numbers. Make sure that X is a defined constant at the beginning of your script and is more appropriately named for its purpose.

    Example:
    X = 3, Array = [1, 2, 3, 4, 5]
    Result = 3

    Since there was only one entry (disappointing!), there was only one winner: slushpuppy.
    Their code:

    Simba Code:
    program FindANumber;
    const
    X = 6;
    arr = [1, 2, 3, 4, 5,6];
    size = sizeof(arr);
    var
    //arr : array of LongInt;
    I : LongInt;
    begin
     for I := 0 to size do
     begin
     if arr[I] = X then
     begin
      writeln(inttostr(I + 1));
      break;
     end
      if arr[size - I - 1] = X then
     begin
      writeln(inttostr(I + 1));
      break;
     end
     end;
    end.

    Intermediate:
    Brute Force Madness -
    Write a program that returns all possible combinations of the characters in string, in order of the sequence of characters with no overlaps. Make sure that string is a constant and is placed at the beginning of the script.

    Example:
    string = ‘abc’
    Result = ‘aaa’, ‘aab’, ‘aac’ … ‘ccc’
    [I]There were several entries, which was quite impressive Methrend's was the fastest out of the quad entrants.

    Methrend's code:
    Simba Code:
    program MethrendBruteForceMadness;

    var
      i : Integer;
      finalString : String;
      charArray, finalArray : TStringArray;

    const
      theString = 'abc'; //String of letters to use


    function getCharArray(whatString : String) : TStringArray;
    var
      tempArray : TStringArray;
      tempString : String;
      count, i : Integer;
    begin

      tempString := whatString;
      repeat
        Delete(tempString, 1, 1);
        inc(count);
      until(tempString = '');

      Setlength(tempArray, count);

      for i := 0 to (count - 1) do
        tempArray[i] := Copy(whatString, i+1, 1);

      Result := tempArray;
    end;

    function getAllCombos(letters : TStringArray) : TStringArray;
    var
      tempArray : TStringArray;
      tempString : String;
      indiceArray : TIntegerArray;
      i, j, totalCombos : Integer;
    begin
      totalCombos := 1
      for i := 0 to high(letters) do
        totalCombos := totalCombos * (high(letters) + 1);

      setLength(tempArray, totalCombos);
      setLength(indiceArray, (high(letters) + 1));

      for i := 0 to high(tempArray) do
        begin
        tempString := '';

        for j := 0 to high(indiceArray) do
        begin
          tempString := tempString + letters[indiceArray[j]];
        end;
        tempArray[i] := tempString;

        inc(indiceArray[high(indiceArray)]);

        for j := high(indiceArray) downto 0 do
        begin
          if (indiceArray[j] > high(indiceArray)) then
          begin
            indiceArray[j] := 0;
            if (j > 0) then
              inc(indiceArray[j-1]);
          end;
        end;
      end;

      Result := tempArray;

    end;

    begin

      charArray := getCharArray(theString);
      finalArray := getAllCombos(charArray);

      for i := 0 to high(finalArray) do
      begin
        finalString := finalString + finalArray[i];
        if (i < high(finalArray)) then
          finalString := finalString + ', ';
      end;

      writeln(finalString);
    end.


    Zyt3x's code:
    Simba Code:
    const
      Chars = 'abc';

    function GetCombinations(CharacterSet : String): TStringArray;
    var
      Numeral : TIntegerArray;
      C, I, J, H, L : Integer;
    begin
      H := Length(CharacterSet)-1;
      L := H+1;
      C := Round(Pow(L, H)) * L;

      SetLength(Numeral, H+1);
      SetLength(Result, C);

      for I := 0 to C-1 do
      begin
        for J := 0 to H do
          Result[I] := Result[I] + CharacterSet[Numeral[J]+1];

        for J := H downto 1 do
          if (J = H) and (Numeral[J] = H) then
          begin
            Inc(Numeral[J-1]);
            Numeral[J] := -1;
          end else
          if Numeral[J] > H then
          begin
            Inc(Numeral[J-1]);
            Numeral[J] := 0;
          end;
        Inc(Numeral[H]);
      end;
    end;


    putonajonny's code:
    Simba Code:
    program ProjectSigma;        //entry by putonajonny

    Const
      S = 'abc';

    function StringToArray(S : String) : array of String;
    Var
      i : integer;
    begin
      SetArrayLength(Result, Length(S));
      for i := 1 to length(S) do
        Result[i - 1] := Copy(S, i, 1);
    end;

    function InStringArray(A : array of String; S : string) : Boolean;
    Var
      i : integer;
    begin
      for i := 0 to high(A) do
        if(A[i] = S) then
          begin
            Result := True;
            exit;
          end;
    end;

    function RemoveDuplicates(A : array of string) : array of string;
    Var
      i : integer;
    begin
      for i := 0 to high(A) do
        if(not InStringArray(Result, A[i]))then
          begin
            SetArrayLength(Result, GetArrayLength(Result) + 1);
            Result[high(Result)] := A[i];
          end;
    end;

    function GreaterThanN(Var AI : array of integer; Const n : integer) : Boolean;
    Var
      i : integer;
      Rep : Boolean;
    begin
      Repeat
        Rep := False;
        for i := 0 to high(AI) do
          if(AI[i] >= n)then
            if(i = 0) then
              begin
                Result := True;
                exit;
              end
            else
              begin
                AI[i] := 0;
                inc(AI[i - 1]);
                Rep := True;
              end;
      Until(not Rep);
    end;

    function Permutations(A : array of string) : array of string;
    Var
      integers : array of integer;
      i, j, n, k : integer;
    begin
      n := High(A);
      SetArrayLength(integers, n + 1);
      Repeat
        SetArrayLength(Result, GetArrayLength(Result) + 1)
        for i := 0 to n do
          begin
            k := integers[i];
            Result[j] := Result[j] + A[k];
          end;
        inc(j);
        inc(integers[high(integers)]);
      Until(GreaterThanN(integers, n + 1));
    end;

    Var
      a, b, c : array of string;


    begin

      a := StringToArray(S);
      b := RemoveDuplicates(a);
      c := Permutations(b);

      WriteLn(GetTimeRunning);

      WriteLn(c);

    end.


    masterBB's code:
    Simba Code:
    program O1;

    const
      TheString = 'Master';

    function CharInArray(c:Char;a:Array of Char):Boolean;
    var
      i,h:Integer;
    begin
      Result := True;
      h := High(a);
      for i := 0 to h do
        if c = a[i] then
          Exit;
      Result := False;
    end;

    function solveProblem1:Array of String;
    var
      i,j,k,l,highResults,amountOfChars,le,hi:Integer;
      powers:Array of Integer;
      chars:Array of Char;
    begin
      le := Length(TheString);
      hi := le-1;

      //Checks how many different chars are in the string, so aab only has 8 results
      for i := 1 to le do
        if not(CharInArray(TheString[i],chars)) then
        begin
          setLength(chars,Length(chars)+1);
          chars[High(chars)] := TheString[i];
        end;
      amountOfChars := Length(chars);

      //Setting powers to reduce function calls
      setLength(powers,le);
      powers[0] := 1;
      powers[1] := le;
      for i := 1 to hi do
        powers[i] := powers[i-1] * amountOfChars;

      //Sets the length of the results
      setLength(Result,powers[hi]* amountOfChars);
      highResults := High(Result);

      for i := 0 to highResults do
      begin
        l := i;
        for j := hi downto 0 do
        begin
          k := floor(l * 1.00 / powers[j]);
          Result[i] := Result[i] + chars[k];
          l := l - (k*powers[j]);
        end;
      end;

      writeln(Result);
    end;

    begin
      solveProblem1;
    end.

    Advanced:Sort n’ Search -
    You will be given an n-length array of random integer values with a signed 24-bit range. You are required to sort this array first following a pattern/sequence (i.e. ascending-descending, descending-ascending, odd-even, even-odd, etc - no "intelligent design sort"), not using the internal sorting methods already included Simba, or implementing a Quick Sort or Bubble Sort algorithm. You are then required to return the positions of all occurrences of X and Y in that sorted array. You should return an integer array of these positions in two separate appropriately named arrays. Make sure that X, Y and array are defined constants at the beginning of your script, and are more appropriately named given their purpose.
    Example:
    X = 6, Y = 9, Array = [4, 9, 4, 3, 9]
    ResultX = [], ResultY = [4, 5]

    [I]Only two entries: mixster and beginner5 Unfortunately beginner5 used BubbleSort, but I still allowed it anyway because of the limited number of entrants. mixster had won this week in terms of speed.

    mixster's code:
    Simba Code:
    const
      X = 42;
      Y = 69;

    procedure Merger(var output: array of Integer; input: array of Integer;
                ar1, ar2, arEnd: Integer);
    var
      ar1I, ar2I: ^Integer;
      ar1P, ar2P, arEP: ^Integer;
      oI, oE: ^Integer;
    begin
      ar1I := @input[ar1];
      ar2I := @input[ar2];
      ar1P := ar1I;
      ar2P := ar2I;
      arEP := @input[arEnd];
      oI := @output[ar1];
      oE := @output[arEnd - 1];
      while (oI <= oE) do
      begin
        if ((ar1I < ar2P) and ((ar2I >= arEP) or (ar1I^ <= ar2I^))) then
        begin
          oI^ := ar1I^;
          Inc(ar1I);
        end
        else
        begin
          oI^ := ar2I^;
          Inc(ar2I);
        end;
        Inc(oI);
      end;
    end;

    procedure SwapArray(var output: array of Integer; var input: array of Integer);
    var
      t: array of Integer;
    begin
      t := output;
      output := input;
      input := t;
    end;

    procedure MergeSort(var data: array of Integer);
    var
      output: array of Integer;
      size: Integer;
      nextSize: Integer;
      len, hi: Integer;
      st: Integer;
    begin
      size := 1;
      nextSize := 2;
      len := Length(data);
      SetLength(output, len);
      hi := len - 1;
      while (size < hi) do
      begin
        st := 0;
        while (st < hi) do
        begin
          Merger(output, data, st, Min(st + size, len), Min(st + nextSize, len));
          st := st + nextSize;
        end;
        size := nextSize;
        nextSize := nextSize shl 1;
        SwapArray(data, output);
      end;
    end;

    procedure DualBinarySearch(var xfound, yfound: array of Integer; data: array of Integer; x, y: Integer);
    var
      hi, mi, lo: Integer;
      xl, xh, yl, yh: Integer;
    begin
      SetLength(xfound, 0);
      SetLength(yfound, 0);

      hi := High(data);
      lo := 0;

      xl := lo;
      xh := hi;

      while (xl <= xh) do
      begin
        mi := (xl + xh) div 2;
        if (data[mi] < x) then
        begin
          xl := mi + 1;
          mi := (xh + xl) div 2;
        end
        else if (data[mi] <> x) then
        begin
          xh := mi - 1;
          mi := (xh + xl) div 2;
        end
        else
        begin
          xl := mi - 1;
          xh := mi + 1;
          while ((xl >= 0) and (data[xl] = x)) do
            xl := xl - 1;
          xl := xl + 1;
          while ((xh <= hi) and (data[xh] = x)) do
            xh := xh + 1;
          SetLength(xfound, xh - xl);
          xh := (xh - xl) - 1;
          for mi := 0 to xh do
            xfound[mi] := xl + mi;
          break;
        end;
      end;

      if (x = y) then
      begin
        yfound = xfound;
        exit;
      end;

      yl := lo;
      yh := hi;
      while (yl <= yh) do
      begin
        mi := (yl + yh) div 2;
        if (data[mi] < y) then
        begin
          yl := mi + 1;
          mi := (yh + yl) div 2;
        end
        else if (data[mi] <> y) then
        begin
          yh := mi - 1;
          mi := (yh + yl) div 2;
        end
        else
        begin
          yl := mi - 1;
          yh := mi + 1;
          while ((yl >= 0) and (data[yl] = y)) do
            yl := yl - 1;
          yl := yl + 1;
          while ((yh <= hi) and (data[yh] = y)) do
            yh := yh + 1;
          SetLength(yfound, yh - yl);
          yh := (yh - yl) - 1;
          for mi := 0 to yh do
            yfound[mi] := yl + mi;
          exit;
        end;
      end;
    end;


    var
      test, xF, yF: array of Integer;
      i, ts, tf, n: Integer;
    begin
      n := 16;
      SetLength(test, n);
      for i := 0 to n - 1 do
        test[i] := Random(n div 2);
      if (n < 50) then
        Writeln(test);
      ts := GetTickCount();
      MergeSort(test);
      ts := GetTickCount() - ts;
      tf := GetTickCount();
      DualBinarySearch(xF, yF, test, X, Y);
      tf := GetTickCount() - tf;
      Writeln('Sort: ' + IntToStr(ts) + 'ms');
      if (n < 50) then
        Writeln(test);
    end.
    [/i]


    beginner5's code:

    Simba Code:
    program new;
    const
    X = 3;
    Y = 9;
    procedure PrintResults ( arr : TintegerArray;X,Y :integer);
    var
    ResX ,ResY ,tempArr: TintegerArray;
    a,l ,temp ,Xcount ,Ycount: integer;
    bool :boolean;
    begin
      l := high(arr);

      repeat
        bool := FALSE;
        for a:=0 to l do
        begin
          if (a<>l)and( arr[a] > arr[a+1]) then
            begin
              temp := arr[a];
              arr[a] := arr[a+1];
              arr[a+1] := temp;
              bool := TRUE;
            end;
        end;
      until not bool;
      writeln('sorted array:')
      writeln(arr);

      for a:= 0 to l do
      begin
        if (arr[a] = x) then
        begin
          Inc(xCount);
        end;

        if (arr[a] = Y) then
        begin
          Inc(YCount);
        end;
      end;
          setlength(Resx,XCount);
          setlength(ResY,YCount);
          XCount :=0;
          Ycount :=0;

      for a:= 0 to l do
      begin
        if (arr[a] = x) then
        begin
          Resx[XCount] := a+1;
          Inc(xCount);
        end;

        if (arr[a] = Y) then
        begin
          ResY[YCount] := a+1;
          Inc(YCount);
        end;
      end;

      writeln('Results X array:');
      writeln(Resx);
      writeln('Results y array:');
      writeln(ResY);
    end;

    var
    Arr : TintegerArray;
    begin
     Arr := [4,9,4,3,9];
     Printresults ( Arr ,X,Y);


    end.
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  12. #37
    Join Date
    Dec 2011
    Location
    Australia
    Posts
    174
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Woo
    Not as complicated as I thought I'd made it then. Well done to those who won the other difficulties ^_^
    My Scripts:
    MethDwarfMiner - A Resource Dung Coal Miner

    MethLarder - Oak Larder Maker #~# Oak Door Maker - MethDoorer
    MethSudokuLITE - Small Casket Sudoku Solver (MEMBERS+ ONLY)

  13. #38
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Not a lot entries, unfortunately. What happened to Wizzup and Benland?
    Here are a few comments:

    slushpuppy:
    • SizeOf(Arr) gives you the size of the array in bytes.
    • Length(Arr) gives you the number of indices and High(Arr) gives you the last index. It would have been better to use High in this case


    Methrend:
    • You can use ToStr(finalArray) or even WriteLn(finalArray)
    • You can get the length of a string using Length(str)
    • You can get a character of a string using string[index] - the first letter is index 1


    Zyt3x:
    • Nice and clean


    putonajonny:
    • You can get a character from a string using str[index] - the first letter is index 1
    • Gradually increasing the array length can take up a lot of time. You can preset the length of the array if you know it.


    masterBB:
    • A string is basically an array of char, why not use the string type so you can use functions like Pos instead of CharInArray?
    • Nice and clean.. and comments! =D


    mixster:
    • Nice use of pointers in merger
    • You can use the builtin swap function for SwapArray
    • The nextSize loop could you also write as for st to hi - 1 with nextSize do


    beginner5:
    • You can use the built-in swap function


    A few overall comments:
    • Lape should not be faster if you cache the length of an array before a for-loop. It does this for you
    • With Brute Force Madness, why not also preset the length of the strings? Appending strings takes time
    • Use comments and meaningful variable names in your code!
    Hup Holland Hup!

  14. #39
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    And here was my solution for Brute Force Madness:

    Simba Code:
    {
      Write a program that returns all possible combinations of the characters in string,
      in order of the sequence of characters with no overlaps. Make sure that string is
      a constant and is placed at the beginning of the script.

      Example:
        string = ‘abc’
        Result = ‘aaa’, ‘aab’, ‘aac’ … ‘ccc’

      Author: nielsie95
    }

    program BruteForceMadness;

    const
      MadString = 'abc';

    var
      MadLen := Length(MadString);

    //Overload Pow() to create an integer variant
    function Pow(Base, Exp: UInt32): Integer; overload;
    begin
      Result := 1;
      for Exp downto 1 do
        Result := Result * Base;
    end;

    //Returns an array filled with combinations
    function MadFill: array of string;

      //Recursive function that fills a certain part of the array
      //It does this by spreading all the characters over len positions.
      //For example: ab is spread like aabb if Len is 4.
      //After that, it recursively fills the next string index;
      //this will give aa,ab,ba,bb.
      procedure FillArr(var a: array of string; StartInd, Len, CharInd: Integer);
      var
        i, Ind, PartLen: Integer;
      begin
        if (CharInd > MadLen) then
          Exit;

        Ind := StartInd;
        PartLen := Len div MadLen;
        for i := 0 to Len - 1 do
        begin
          a[Ind, CharInd] := MadString[i div PartLen + 1];
          Inc(Ind);
        end;

        Ind := StartInd;
        Inc(CharInd);
        for i := 0 to MadLen - 1 do
        begin
          FillArr(a, StartInd, PartLen, CharInd);
          Inc(StartInd, PartLen);
        end;
      end;

    var
      Len: Integer;
    begin
      Len := Pow(MadLen, MadLen);        //Calculate array length
      SetLength(Result, Len, MadLen);    //Allocate array
      FillArr(Result, 0, Len, 1);        //Fill the array
    end;

    begin
      WriteLn(MadFill());
    end.

    I didn't want to submit, because it was the intermediate problem. Perhaps next time I should?
    Last edited by nielsie95; 03-08-2012 at 08:35 AM.
    Hup Holland Hup!

  15. #40
    Join Date
    Jan 2010
    Posts
    1,414
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    You can have a procedure/function inside of another, Nielsie?
    Simba Code:
    (* Main *)

    repeat
      WriteLn('I am an idiot!');
    until(False);

  16. #41
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Yes, although the above script will most likely currently only work in the nightly build of Simba. You cannot access parent variables, though.
    Hup Holland Hup!

  17. #42
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Quote Originally Posted by nielsie95 View Post
    And here was my solution for Brute Force Madness:
    Aha :P

    Here was mine :P Nice and simple:
    Simba Code:
    const
      Characters = 'abc';

    var
      Results: array of String;

    procedure GenString(S: String);
    var
      I: Integer;
    begin
      if(Length(S) = Length(Characters)) then
        Writeln(S)
      else
        for I := 1 to Length(Characters) do
          GenString(S + Characters[I]);
    end;

    begin
      GenString('');
    end.



    Also, thank you for going through every submission offering suggestions and showing room for improvement
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  18. #43
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    I believe the reason my code was slower is that methernds code gives multiple of the same combos when a char is in the string more than once. So 'aab' gives multiple 'aaa' result while mine would only return one 'aaa'. Oh well, congratulations meth! You won't win that easy next time
    Working on: Tithe Farmer

  19. #44
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    I believe the reason my code was slower is that methernds code gives multiple of the same combos when a char is in the string more than once. So 'aab' gives multiple 'aaa' result while mine would only return one 'aaa'. Oh well, congratulations meth! You won't win that easy next time
    It ran fine for me? :S
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  20. #45
    Join Date
    Nov 2011
    Posts
    255
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default

    Should be studying for biology final, instead I'm tying to solve your challenge... Good news is I'm learning right?? I really like these challenges, they definitely bend the mind! Back to intracellular vesical transport for me...

  21. #46
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    I do not want to attack methrends submission as it wasn't part of the problem. But I did more work then he did, solving a second unasked question:

    input:
    Simba Code:
    S := 'aabc';

    output meth:
    aaaa, aaaa, aaab, aaac, aaaa, aaaa, aaab, aaac, aaba, aaba, aabb, aabc, aaca, aaca, aacb, aacc, aaaa, aaaa, aaab, aaac, aaaa, aaaa, aaab, aaac, aaba, aaba, aabb, aabc, aaca, aaca, aacb, aacc, abaa, abaa, abab, abac, abaa, abaa, abab, abac, abba, abba, abbb, abbc, abca, abca, abcb, abcc, acaa, acaa, acab, acac, acaa, acaa, acab, acac, acba, acba, acbb, acbc, acca, acca, accb, accc, aaaa, aaaa, aaab, aaac, aaaa, aaaa, aaab, aaac, aaba, aaba, aabb, aabc, aaca, aaca, aacb, aacc, aaaa, aaaa, aaab, aaac, aaaa, aaaa, aaab, aaac, aaba, aaba, aabb, aabc, aaca, aaca, aacb, aacc, abaa, abaa, abab, abac, abaa, abaa, abab, abac, abba, abba, abbb, abbc, abca, abca, abcb, abcc, acaa, acaa, acab, acac, acaa, acaa, acab, acac, acba, acba, acbb, acbc, acca, acca, accb, accc, baaa, baaa, baab, baac, baaa, baaa, baab, baac, baba, baba, babb, babc, baca, baca, bacb, bacc, baaa, baaa, baab, baac, baaa, baaa, baab, baac, baba, baba, babb, babc, baca, baca, bacb, bacc, bbaa, bbaa, bbab, bbac, bbaa, bbaa, bbab, bbac, bbba, bbba, bbbb, bbbc, bbca, bbca, bbcb, bbcc, bcaa, bcaa, bcab, bcac, bcaa, bcaa, bcab, bcac, bcba, bcba, bcbb, bcbc, bcca, bcca, bccb, bccc, caaa, caaa, caab, caac, caaa, caaa, caab, caac, caba, caba, cabb, cabc, caca, caca, cacb, cacc, caaa, caaa, caab, caac, caaa, caaa, caab, caac, caba, caba, cabb, cabc, caca, caca, cacb, cacc, cbaa, cbaa, cbab, cbac, cbaa, cbaa, cbab, cbac, cbba, cbba, cbbb, cbbc, cbca, cbca, cbcb, cbcc, ccaa, ccaa, ccab, ccac, ccaa, ccaa, ccab, ccac, ccba, ccba, ccbb, ccbc, ccca, ccca, cccb, cccc

    output masterBB:
    'aaaa', 'aaab', 'aaac', 'aaba', 'aabb', 'aabc', 'aaca', 'aacb', 'aacc', 'abaa', 'abab', 'abac', 'abba', 'abbb', 'abbc', 'abca', 'abcb', 'abcc', 'acaa', 'acab', 'acac', 'acba', 'acbb', 'acbc', 'acca', 'accb', 'accc', 'baaa', 'baab', 'baac', 'baba', 'babb', 'babc', 'baca', 'bacb', 'bacc', 'bbaa', 'bbab', 'bbac', 'bbba', 'bbbb', 'bbbc', 'bbca', 'bbcb', 'bbcc', 'bcaa', 'bcab', 'bcac', 'bcba', 'bcbb', 'bcbc', 'bcca', 'bccb', 'bccc', 'caaa', 'caab', 'caac', 'caba', 'cabb', 'cabc', 'caca', 'cacb', 'cacc', 'cbaa', 'cbab', 'cbac', 'cbba', 'cbbb', 'cbbc', 'cbca', 'cbcb', 'cbcc', 'ccaa', 'ccab', 'ccac', 'ccba', 'ccbb', 'ccbc', 'ccca', 'cccb', 'cccc'

    or

    input:
    Simba Code:
    S := 'aac';

    output methrend:
    'aaa', 'aaa', 'aac', 'aaa', 'aaa', 'aac', 'aca', 'aca', 'acc', 'aaa', 'aaa', 'aac', 'aaa', 'aaa', 'aac', 'aca', 'aca', 'acc', 'caa', 'caa', 'cac', 'caa', 'caa', 'cac', 'cca', 'cca', 'ccc'

    output masterBB:
    'aaa', 'aac', 'aca', 'acc', 'caa', 'cac', 'cca', 'ccc'

    edit:
    putonajonny also solved this problem.
    Last edited by masterBB; 03-08-2012 at 10:25 AM.
    Working on: Tithe Farmer

  22. #47
    Join Date
    Dec 2011
    Location
    Australia
    Posts
    174
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I have to say, the wording of the question was a bit weird.

    If Dan rules that mine no longer counts as a proper solution, I don't mind relinquishing it :P

    The way I saw it, if a letter was repeated in the given string, it was seen as a different "instance" of that letter, and as such there could be repeats. (e.g. the 'aaa's were arrange using the different instances of the a), but there couldn't be repeats using the same letter if there was only one. (so for 'abc', you couldn't output 'aaa' more than once)

    As an aside to this, It may have been a better problem had it been specified as 'no repitition' (so an input of 'abc' would output 'abc, acb, bac, bca, cab, cba'), rather than every single possible combination of the letters inclusive of repetition.


    Still, I don't mind giving up the win and the points if that's the case

    Edit: In addition, Dan will vouch that I even asked for some small amount of clarification on what he meant by "no overlaps", which I then applied to mean in the way explained above. It may be that I just didn't understand correctly ;P
    My Scripts:
    MethDwarfMiner - A Resource Dung Coal Miner

    MethLarder - Oak Larder Maker #~# Oak Door Maker - MethDoorer
    MethSudokuLITE - Small Casket Sudoku Solver (MEMBERS+ ONLY)

  23. #48
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    I've no means to change the order of who won. But, my script is faster as yours when you remove the "overlap thingie". I think you're the winner anyway.
    Working on: Tithe Farmer

  24. #49
    Join Date
    Oct 2011
    Posts
    422
    Mentioned
    15 Post(s)
    Quoted
    116 Post(s)

    Default

    >nielsie95

    However I believe High/Length wouldn't work at compile time?

  25. #50
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Quote Originally Posted by slushpuppy View Post
    >nielsie95

    However I believe High/Length wouldn't work at compile time?
    They do . Just use High(yourArray).
    Working on: Tithe Farmer

Page 2 of 4 FirstFirst 1234 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •