0

user defined function - appendArrays

Hi there,

I would like to learn more about "user defined functions".

Couldn't use Sean's functions on Arrays.

I am trying to solve a Sudoku grid with Ninox...

There are three arrays : square e.g. [3,6,7,8] - row [3,7] - and column [3,7,9]

an array showing [3,6,7,8,3,7,3,7,9] giving after unique and sort [3,6,7,8,9] (forbidden numbers) is what I am trying.  to get - then subtracting [3,6,7,8,9] from [1,2,3,4,5,6,7,8,9] would give [1,2,4,5] (possible numbers).

Do I need user defined functions ?

 

Thank you

3 replies

null
    • Sean
    • 4 yrs ago
    • Reported - view

    Chris,

     

    Pretty much any unique formula is a user defined function. I guess what separates a formula from a function is that you are wrapping the formula in the function format then you can call the "function" which executes your formula. Clear as mud right!

     

    I assume those numbers will change so how do you get the numbers that you want to exclude? I won't be able to respond for a while after this post btw.

     

    Sean

    • Sean
    • 4 yrs ago
    • Reported - view

    Hopefully, this better explains the difference between a plain ole formula and a user defined function...

     

    Screen Shot 2019-06-16 at 12.54.06 PM

     

    Screen Shot 2019-06-16 at 12.54.26 PM

     

    Screen Shot 2019-06-16 at 12.54.50 PM

    • Sean
    • 4 yrs ago
    • Reported - view

    The following code works...

     

    let mySquare := [3, 6, 7, 8];
    let myRow := [3, 7];
    let myCol := [3, 7, 9];
    let subNumbers := unique(mySquare, myRow, myCol);
    let posNumbers := [0];
    let allNumbers := [1, 2, 3, 4, 5, 6, 7, 8, 9];
    for i in range(0, count(allNumbers)) do
    let lpCount := 0;
    let numFound := false;
    while lpCount < count(subNumbers) and not numFound do 
    if item(subNumbers, lpCount) = item(allNumbers, i) then
    numFound := true
    else
    lpCount := lpCount + 1
    end
    end
    ;
    if not numFound then
    posNumbers := unique(posNumbers, item(allNumbers, i))
    end
    end;
    posNumbers := slice(posNumbers, 1, count(posNumbers));
    posNumbers

     

    I don't know if you really need to store the values in the arrays as numbers. If you can store the numbers as text it would be easy to pass the stringified arrays to a user defined function. 

Content aside

  • 4 yrs agoLast active
  • 3Replies
  • 1598Views