How to divide a grid (an 2D array) into subgrids? [Suduko]

Hey guys
I've been struggling with a problem with my Suduko program for a few days now and thought I could get some help here.
The problem is that I have no idea how to divide a Suduko grid and stuff them into subgrids.
My current plan is to go through the Suduko array r * c times (where r and c is the dimensions of a subgrid) and stuff the cells into my quad array (somehow). I've gone through the sourcecode of 4 suduko programs on sourceforge, but still can't find a solution (mainly because I can't read other prog. lannguages yet).
My code:
* easyIO is a packadge that enables read/write to files
* and enables communication between the user and the program via the command-line
* You can find this packadge here: http://www.universitetsforlaget.no/java/easyIO.zip
import easyIO.*;
/** Initialises the board */
class Oblig2
     public static void main(String[] args)
          /** If there is a argument in the command line (the filename to be used in this case),
           *  then send that argument with a new Board
          if(args.length >= 0)
               Board suduko = new Board(args[0]);
class Board
     /** Constant (yeah, no final int) that defines the board dimensisions, if dimension is 6, then the board is 6 x 6 */
     int dimension;
     /** The quad dimensions */
     int quadRow;
     int quadCol;
    Cell[][] cells;
    Row[] row;
    Col[] col;
    Quad[] quad;
     * Board contructor defines the boards properties
     * @param filename comes from Oblig2.main()
    Board(String filename)
          /** In is a class of easyIO, inFile will contain the contents of the file */
          In inFile = new In(filename);
          dimension = inFile.inInt("\n"); System.out.print(dimension + "\n");
          quadRow = inFile.inInt("\n"); System.out.print(quadRow + "\n");
          quadCol = inFile.inInt("\n"); System.out.print(quadCol + "\n");
          inFile.readLine();
          /** Creates all the neccessary cell, row, cols and quad arrays */
          cells = new Cell[dimension][dimension];
          row = new Row[dimension];
          col = new Col[dimension];
          quad = new Quad[quadRow * quadCol];
          /** Initializes all the rows */
          for(int i = 0; i < row.length; i++)
               row[i] = new Row(dimension);
          /** Initializes all cols */
          for(int i = 0; i < col.length; i++)
               col[i] = new Col(dimension);
          /** Initializes all quads */
          for(int i = 0; i < quad.length; i++)
               quad[i] = new Quad(quadRow, quadCol);
          /** Initializes all cells and puts them in rows and cols */
          for(int i = 0; i < cells.length; i++)
               for(int j = 0; j < cells.length; j++)
                    cells[i][j] = new Cell();
                    row[i].addCell(cells[i][j]);
                    col[j].addCell(cells[i][j]);
                    cells[i][j].addRCpointer(row[i], col[j]);
          for(int i = 0; i < (quadRow * quadCol)
               for(int j = 0; i < cells.length; j++)
                    for(int k = 0; k < cells[k].length; k++
          /** Reads the file until it reaches the end of the file */
          while(!inFile.endOfFile())
          /** Closes the filecontainer */
          inFile.close();
class Row
     /** Single col. array to contain cells in row */
     Cell[] row;
     * Assigns an array with length=rowVal
     * @param is the same as dimension in Board-class
     Row(int rowVal)
          row = new Cell[rowVal];
     /** Add cell to row
     * If the cell is null, or empty, then it will set the cell[i] = cell,
     * and return control back to the caller
     void addCell(Cell cell)
          for(int i = 0; i < row.length; i++)
               if(row[i]==null)
                    row[i] = cell;
                    return;
     * Checks if it's possible to stuff a number into the row,
     * returns true if it's possible and false else
     boolean tryNumeral(int cellVal)
          for(int i = 0; i < row.length; i++)
               if(row[i].getContains() == cellVal)
               { return false; }
          return true;
class Col
     /** Single col. array to contain cells in col.*/
Cell[] col;
* Assigns an array with length=colVal
* @param is the same as dimension in Board-class
Col(int colVal)
          col = new Cell[colVal];
     /** Add cell to col.
     * If the cell is null, or empty, then it will set the cell[i] = cell,
     * and return control back to the caller
     void addCell(Cell cell)
          for(int i = 0; i < col.length; i++)
               if(col[i]==null)
                    col[i] = cell;
                    return;
     * Checks if it's possible to stuff a number into the col,
     * returns true if it's possible and false else
     boolean tryNumeral(int cellVal)
          for(int i = 0; i < col.length; i++)
               if(col[i].getContains() == cellVal)
               { return false; }
          return true;
class Quad
     /** Single col. array to contain cells in quad*/
Cell[] quad;
     /** Assigns an array with length=row*col to quad */
Quad(int row, int col)
          quad = new Cell[row * col];
     /** Add cell to quad
     * If the cell is null, or empty, then it will set the cell[i] = cell,
     * and return control back to the caller
     void addCell(Cell cell)
          for(int i = 0; i < quad.length; i++)
               if(quad[i]==null)
                    quad[i] = cell;
                    return;
     * Checks if it'possible to stuff a number into the quad.
     * returns true if it's possible and false else.
     boolean tryNumeral(int cellVal)
          for(int i = 0; i < quad.length; i++)
               if(quad[i].getContains() == cellVal)
               { return false; }
          return true;
/** The lowest unit on a Suduko board */
class Cell
     /** The number the box contains */
int contains;
     /** Pointers to the row/col/quad it's located in */
Row cellRow;
Col cellCol;
Quad cellQuad;
     /** Add pointers from Board-contructor R = Row, C = Col. */
     void addRCpointer(Row row, Col col)
          cellRow = row;
          cellCol = col;
     /** Checks if it's okay to place a number there */
void tryNumeral()
/** Get-method for the cells value */
int getContains()
          return this.contains;

nitinkajay wrote:
I want to know how to store the output of a analog to digital converter into an 2D labview array.
How exactly are you performing 'Analog to Digital'???
Grabbing image using camera OR performing data acquisition using DAQ card OR some other way????
I am not allergic to Kudos, in fact I love Kudos.
 Make your LabVIEW experience more CONVENIENT.

Similar Messages

  • How do i change 2 row of array into waveform with delta time and time

    Hello,
    How do i change 2 row of array into waveform with delta time and time
    so the waveform graph will display two waveform,
    waveform, not cluster =]
    and how to extract 1d array from waveform?

    Hi AxE,
    Here is an example VI, that do what You asked for.
    Both requests.
    Hope it Helps...
    Attachments:
    2D_to_Waveform.vi ‏75 KB

  • How can i pass a value in array into .setText()?

    i want to display a value in an array into a JTextField. May i know how to do it?
    eg:
    JTextField UserName;
    UserName.setText(s);
    but it doesn't display the value into the JTextfield.

    ok... is s an array?
    String[] s = {"s1", "s2"};Either you expect 1 value...
    username.setText(s[0]);
    // or
    username.setText(s[1]);Or you expect both:
    StringBuffer sb = new StringBuffer("");
    for(int x = 0; x < s.length; x++) {
       if(x != 0) sb.append(", ");
       sb.append(s[x])
    username.setText(sb.toString());

  • How can I save 3 of 1D arrays into excel file neatly? VI file is attached. Thanks...

    I have 3 of the 1D arrays. When I combine them, I get 1 very long column in excel. Instead I want to have three columns of shorter arrays. I attached the vi. Besides, is there any way I can write on the 1st row of the same excel file.
    Attachments:
    Ali_PID_Control_Loop_10_formula_frontpanel.vi ‏132 KB

    There's more than one way to "combine" arrays.
    Look at the BUILD ARRAY function.
    If you wire three arrays to three inputs, you have a choice of outputs:
    You can CONCATENATE the inputs, in which case the output is a longer 1-D array.
    If you DON'T concatenate them, the output is a 2-D array, which sounds like what you want.
    You will probably want to TRANSPOSE the 2-D ARRAY, as this will give you three columns of N rows. Without transposing, you get three rows of N columns.
    If the original arrays are not equal length, they will be padded with zeroes.
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks

  • How can you covert a 2-d array into a 1-d array by taking the average of all the values in each row?

    Hi
    My application is generating a 2-dimensional array of data as it performs multiple sweeps.  I would like to take the mean of all the data in each row and thereby reduce to a 1-dimensional array.  Does anybody have a quick solution.
    (Sorry - I am posting many messages at present, I promise to share my acquired knowledge!!!).
    Thanks
    Ashley. 

    Try this.
    Attachments:
    Mean.JPG ‏5 KB

  • How  to divide distinct records in a table into batches

    Hi all,
    I need a small help . I have some 3 to 4 lakhs of records in table . I want to divide these records into batches by assigning some batchno to some set of records. i.e i'll query some distinct records those distinct records should be assigned to one batchno . i.e when i query there may be some 100 records of one unique value in a column and 1000 next and so on . I want to make these records to one one batchno . Can any one help in this regard.
    Regards,
    rakesh

    May below given SQL help you...
    WITH T AS
    SELECT 'A' COL1 FROM DUAL UNION ALL
    SELECT 'B' COL1 FROM DUAL UNION ALL
    SELECT 'D' COL1 FROM DUAL UNION ALL
    SELECT 'A' COL1 FROM DUAL UNION ALL
    SELECT 'X' COL1 FROM DUAL UNION ALL
    SELECT 'P' COL1 FROM DUAL UNION ALL
    SELECT 'B' COL1 FROM DUAL
    SELECT COL1 , 'BTCH_'||DENSE_RANK() OVER (ORDER BY COL1) BATCH_NO
    FROM   T;
    COL1     BATCH_NO
    A     BTCH_1
    A     BTCH_1
    B     BTCH_2
    B     BTCH_2
    D     BTCH_3
    P     BTCH_4
    X     BTCH_5
    7 rows returned in 0.00 seconds     *009*

  • Divide an array into components

    Hello:
    I am developing a LV application that has, in some way, "two parts": One of them is the user interface and its associated block diagram, that receives values from controls and files. Then, this values are used for feeding the inputs of a "Call Library Function" node.
    Well, some of the values I use are components of an array. I thought that I could use a "Split array" block, but I cant connect the "1 component array" with the numerical input of the library node.
    How could I "convert" a "1 component array" into a "numerical value". I actually use a very improper method, I connect the "1 component" array to a "array max & min" block, and I use "max value" output (I could use min too, obviously).
    Another question that is related to this is the follwing: Is there any method in order to split an array into its numerical components? Because I have, for example, a 4 elements array, I wished to divide it (in an easy way, instead of having a "serial association" of 4 "split array" blocks) into 4 numerical values that are used for feeding a function node.
    Well, if you need any aditional info, please dont hesitate in ask for it. Thank you very much for your attention and please sorry for my bad english.
    Yours sincerely.
    Juan Crespo

    Juan,
    Apologies if I misunderstood, but is the 'Index Array' function the answer to both your questions?
    =====================================================
    Fading out. " ... J. Arthur Rank on gong."
    Attachments:
    Index Array Elements.jpg ‏12 KB

  • Insert columns of one array into another

    how can one insert columns of an array into another array at every odd place of that array in which insertions are to be made? In short, columns of one array to be inserted into another array bt possibly in between the already initialised array. 
    Solved!
    Go to Solution.

    here's an example, feel free to ask question if it's not clear for you.
    hope it helps
    When my feet touch the ground each morning the devil thinks "bloody hell... He's up again!"
    Attachments:
    insert.vi ‏20 KB

  • How to divide all textFrames in one-character-per-textFrame?

    Hello:
    How to divide all textFrames in one-character-per-textFrame?
    Example: the textFrame "Letters" will be divided in 7 textFrames: "L", "e", "t", "t", "e", "r", "s".
    Help, please.

    Hi Paul, try this one
    #target Illustrator
    //  script.name = splitSelectedFramesIntoWords2.0.jsx;
    //  script.description = splits selected texFrames into separate words;
    //  script.required = select point text textFrames before running;
    //  script.parent = CarlosCanto;  // 10/14/11
    //  script.elegant = false;
    var idoc = app.activeDocument;
    var sel = idoc.selection; // get selection
    var selCount = sel.length; // count items
    var tFrames = []; // to hold the textFrames
    for (j=selCount ; j>0 ; j--) // loop thru selection & get textFrames backwards
                        tFrames[j-1] = sel[j-1];
    for (k = 0 ; k<tFrames.length ; k++) // loop thru textFrames
                        var xpos = tFrames[k].position[0]; // get x
                        var ypos = tFrames[k].position[1]; // get y
                        var words = tFrames[k].contents.split(/\s/g); // get all words into an array
                        //$.writeln(words);
                        var space = tFrames[k].duplicate(); // dup to get width of a space
                        space.contents = " ";
                        var sw = space.width;
                        space.contents = words[0]; // replace space with first word
                        var w = space.width;
                        var wordCount = words.length; // count words
                        for (i=1; i<wordCount ; i++) // loop thru words
                                            xpos2 = xpos+w+sw; // next words position = previous word pos+width+space
                                            var iword = space.duplicate(); // duplicate previous word
                                            iword.contents = words[i]; // add next word
                                            iword.position = [xpos2,ypos]; // position the character = original position + new width
                                            w = iword.width; // get words width
                                            xpos = iword.position[0]; // get words position
                        tFrames[k].remove(); // remove textFrame

  • How to set the value of an array element (not the complete array) by using a reference?

    My situation is that I have an array of clusters on the front panel. Each element is used for a particular test setup, so if the array size is three, it means we have three identical test setups that can be used. The cluster contains two string controls and a button: 'device ID' string, 'start' button and 'status' string.
    In order to keep the diagrams simple, I would like to use a reference to the array as input into a subvi. This subvi will then modify a particular element in the array (i.e. set the 'status' string).
    The first problem I encounter is that I can not select an array element to write to by using the reference. I have tried setting the 'Selection s
    tart[]' and 'Selection size[]' properties and then querying the 'Array element' to get the proper element.
    If I do this, the VI always seems to write to the element which the user has selected (i.e. the element that contains the cursor) instead of the one I am trying to select. I also have not found any other possible use for the 'Selection' properties, so I wonder if I am doing something wrong.
    Of course I can use the 'value' property to get all elements, and then use the replace array element with an index value, but this defeats the purpose of leaving all other elements untouched.
    I had hoped to use this method specifically to avoid overwriting other array elements (such as happens with the replace array element) because the user might be modifying the second array element while I want to modify the first.
    My current solution is to split the array into two arrays: one control and one indicator (I guess that's really how it should be done ;-) but I'd still like to know ho
    w to change a single element in an array without affecting the others by using a reference in case I can use it elsewhere.

    > My situation is that I have an array of clusters on the front panel.
    > Each element is used for a particular test setup, so if the array size
    > is three, it means we have three identical test setups that can be
    > used. The cluster contains two string controls and a button: 'device
    > ID' string, 'start' button and 'status' string.
    >
    > In order to keep the diagrams simple, I would like to use a reference
    > to the array as input into a subvi. This subvi will then modify a
    > particular element in the array (i.e. set the 'status' string).
    >
    It isn't possible to get a reference to a particular element within an
    array. There is only one reference to the one control that represents
    all elements in the array.
    While it may seem better to use references to update
    an element within
    an array, it shouldn't really be necessary, and it can also lead to
    race conditions. If you write to an element that has the
    possibility of the user changing, whether you write with a local, a
    reference, or any other means, there is a race condition between the
    diagram and the user. LV will help with this to a certain extent,
    especially for controls that take awhile to edit like ones that use
    the keyboard. In these cases, if the user has already started entering
    text, it will not be overwritten by the new value unless the key focus
    is taken away from the control first. It is similar when moving a slider
    or other value changes using the mouse. LV will write to the other values,
    but will not rip the slider out of the user's hand.
    To completely avoid race conditions, you can split the array into user
    fields and indicators that are located underneath them. Or, if some
    controls act as both, you can do like Excel. You don't directly type
    into the cell. You choose w
    hich cell to edit, but you modify another
    location. When the edit is completed, it is incorporated into the
    display so that it is never lost.
    Greg McKaskle

  • Using the value "Image/*" for the accept attribute of the HTML input Element, how can I add .pdf to the array of preconfigured file types (.jpe, .jpg, .jpeg, .?

    On a form, using the value "image/*" for the accept attribute of the HTML input Element, how can I add .pdf to the array of pre-configured file types (.jpe, .jpg, .jpeg, .gif, .png, .bmp, .ico, .svg, .svgz, .tif, .tiff, .ai, .drw, .pct, .psp, .xcf, .psd, .raw)?
    Say I wanted to add .gif, .jfif or .ico. I find this array limited, how can I add types to image?
    <input type="file" name="file" accept="image/*" id="file" />
    mimeTypes.rdf does not seem to allow this.

    ''mimeTypes.rdf'' has nothing to do with web development. It's a file that stores your file handling preferences (e.g. if you want ZIP files automatically saved or opened).
    You can't change the file types of the pre-defined content specifiers (audio/*, video/*, image/*), but you can specify additional MIME types. To add PDF to your above example,
    <pre><nowiki><input type="file" name="file" accept="image/*,application/pdf" id="file" /></nowiki></pre>
    For details, see
    * [https://developer.mozilla.org/En/HTML/Element/Input developer.mozilla.org/En/HTML/Element/Input]

  • How to print a grid from windows phone 8.1 application

    Hello ,
    I want to print a grid from a windows phone application.
    For tablet I can print using this namespace:
    using Windows.Graphics.Printing;
    using Windows.UI.Xaml.Printing;
    But they are only for Tablet.
    Please suggest a solution of printing from windows 8.1 phone application.
    Thanks

    Hi waqar.haider.confiz,
    >>How to print a grid from windows phone 8.1 application                                 
    As far as I known, in Windows Phone 8.1 app it does not have such API for us to print a grid. I will recommand you submit this feature request on this
    UserVoice forum.
    Best Regards,
    Amy Peng
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How do I convert a 1-D array of cluster of 5 elements into a 2-D array of numbers? (history data from a chart)

    Hello,
    in my vi I have a chart with 5 Plots displaying measurement data.
    The user should be able to save all the history data from the chart at anytime. (e.g. the user watches the chart and some event happens, then he presses a "save"-button)
    I know, that I can read out the history data with a property node. That is not the problem. The problem is, how do I handle the data? The type of the history data is a 1-D array of cluster of 5 elements.
    I have to convert that data somehow into a 2 D-array of numbers or strings, so that I can easily save it in a text-file.
    How do I convert a 1-D array of cluster of 5 elements into a 2-D array of numbers?
    I use LabVIEW 7.1
    Johannes
    Greetings Johannes
    Using LabVIEW 7.1 and 2009 recently
    Solved!
    Go to Solution.

    Gerd,
    thank you for the quick response and the easy solution.
    Look what I did in the meantime. I solved the problem too, but muuuch more complicate :-)
    And I have converted the numbers to strings, so that I can easily write them into a spreasheet file.
    Johannes
    Message Edited by johanneshoer on 04-28-2009 10:39 AM
    Greetings Johannes
    Using LabVIEW 7.1 and 2009 recently
    Attachments:
    SaveChartHistory.JPG ‏57 KB
    SaveChartHistory.JPG ‏57 KB

  • How to extract every component in an array?

    Hello everyone!
    Do you know how to extract every component from an array field?
    For example:
    The following is the defination of a table:
    CREATE TABLE test (
    id NUMBER PRIMARY KEY,
    name VARCHAR2(32),
    shape MDSYS.SDO_GEOMETRY
    And then I insert a new record:
    INSERT INTO test VALUES(
    1,'first',
    MDSYS.SDO_GEOMETRY(
    2003,
    NULL,
    NULL,
    MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,3),
    MDSYS.SDO_ORDINATE_ARRAY(1,1, 5,7)
    The Question is I want to read the every component (for example 1,1,5,7) in the sdo_ordinate_array one by one. Who knows how to write the SQL?
    I have tried "select a.shape.sdo_ordinates(1) from test a". But it can't work.
    Thank you very much!

    One solution is to read each ordinate from a cursor ina SQL block. Here is an example:
    set serveroutput on
    SET serveroutput on SIZE 1000000
    set concat on
    DEFINE layername = 'LAYER';
    DEFINE geomcolname = 'GEOM';
    DECLARE
    id varchar2(10);
    longitude number;
    latitude number;
    logmile number;
    i number;
    theLayer varchar2(32);
    theGeomCol varchar2(32);
    BEGIN
    FOR rec IN (SELECT ROWID, id, &geomcolname FROM &layername ) LOOP
    id := rec.id;
    i := 1;
    while i < rec.geom.sdo_ordinates.count loop
    longitude:=rec.geom.sdo_ordinates(i);
    latitude:=rec.geom.sdo_ordinates(i+1);
    logmile:=rec.geom.sdo_ordinates(i+2);
    dbms_output.put_line(id || ',' || longitude || ',' || latitude || ',' || logmile);
    i := i + 3;
    end loop;
    END LOOP;
    commit;
    END;
    Maybe that will help.
    Dave
    David R. Miller
    Michael Baker Jr., Inc.
    3601 Eisenhower Avenue
    Alexandria, VA 22314
    [email protected]
    www.mbakercorp.com

  • How to store logical operator in an array in java

    how to store logical operator in an array in java.
    Array should not be String type if i pass an element of that array it should be considered as logical operator

    my exact requirment is like this, i need some logic
    to convert string like this "2 Equals 3 AND 4 greater
    than 7" to condition like this
    2 == 3 && 4 >7 which i can pass to if
    condition.So you want to create an expression parser?
    No need for something as ugly as what you think you need, a simple nested conditional will do it for just the few logical operations.

Maybe you are looking for

  • Batch management issue.

    hello all, i have batch management active in mm,automatic batch is created during GR. now i want to implement fifo goods issue,but it needs material master view to be extended to classificatio tab under which i will assign the class.we have almost 20

  • Blue Box with Question Mark - Just started happening

    I read other posts about this but it didn't seem they were similar to my issue. I've been getting emails from many sources and have always been able to view the images within the email. However, it seems in the past 2 weeks or so, I no longer see the

  • Can I change the default 'File Type' for PL/SQL Source File to '*.prc' ?

    Want to change the 'default' extension for PL/SQL source to '*.prc' When navigating 'File' / 'Save As', and selecting the 'File Type' list box, The default 'File Type' for PL/SQL Source File is '*.pls'. Can I change the default 'File Type' for PL/SQL

  • Outlook Authentication Prompts

    Having a lot of problems with Outlook 2010/2013 authentication prompts. Client is migrating from EX 2010 and going to onsite EX 2013. Both Outlook 2010 & 2013 get the prompts. At this point in the migration, all internal DNS records point to the load

  • About standard text

    1.How do u transport STANDARD TEXT from development client to quality client or to development?