Results 1 to 5 of 5

Thread: Programming challenge - fun stuff

  1. Registered TeamPlayer rush2049's Avatar
    Join Date
    03-26-11
    Location
    Lancaster, PA
    Posts
    1,213
    Post Thanks / Like
    Stat Links

    Programming challenge - fun stuff Programming challenge - fun stuff Programming challenge - fun stuff Programming challenge - fun stuff Programming challenge - fun stuff
    Gamer IDs

    Gamertag: Benjamin Rush PSN ID: Benjamin_Rush Steam ID: rush2049 rush2049's Originid: rush20492002
    #1

    Programming challenge - fun stuff

    Programming challenge suggestion:


    I saw this puzzle today and thought it would be a good idea to use as a challenge for programming a solver.


    Programming challenge - fun stuff-hme5htwcsllnowski5nr-png




    These puzzles are called 'nongrams'




    I started working on my own solver for it. But in the meantime I used an online solver to come up with this correct solution:


    Programming challenge - fun stuff-capture-jpg




    This is the first in a long string of puzzles.


    See here for where I first saw it: Can You Solve a UK Intelligence Agency's Christmas Puzzle?




    Where I am so far in my code:


    Code:
    package ukintpuzzle1;
    
    /**
     *
     * @author benra
     */
    public class UKintPuzzle1 {
        
        public UKintPuzzle1() {
            int grid[][] = new int[25][25];
            grid[3][3] = 1;
            grid[4][3] = 1;
            grid[12][3] = 1;
            grid[13][3] = 1;
            grid[21][3] = 1;
            
            grid[6][8] = 1;
            grid[7][8] = 1;
            grid[10][8] = 1;
            grid[14][8] = 1;
            grid[15][8] = 1;
            grid[18][8] = 1;
            
            grid[6][16] = 1;
            grid[11][16] = 1;
            grid[16][16] = 1;
            grid[20][16] = 1;
            
            grid[3][21] = 1;
            grid[4][21] = 1;
            grid[9][21] = 1;
            grid[10][21] = 1;
            grid[15][21] = 1;
            grid[20][21] = 1;
            grid[21][21] = 1;
            
            
            
            int colClues[][] = new int[grid.length][];
            int[][] rowClues = new int[grid[0].length][];
            
            colClues[0] = new int[]{7, 2, 1, 1, 7};
            colClues[1] = new int[]{1, 1, 2, 2, 1, 1};
            colClues[2] = new int[]{1, 3, 1, 3, 1, 3, 1, 3, 1};
            colClues[3] = new int[]{1, 3, 1, 1, 5, 1, 3, 1};
            colClues[4] = new int[]{1, 3, 1, 1, 4, 1, 3, 1};
            colClues[5] = new int[]{1, 1, 1, 2, 1, 1};
            colClues[6] = new int[]{7, 1, 1, 1, 1, 1, 7};
            colClues[7] = new int[]{1, 1, 3};
            colClues[8] = new int[]{2, 1, 2, 1, 8, 2, 1};
            colClues[9] = new int[]{2, 2, 1, 2, 1, 1, 1, 2};
            colClues[10] = new int[]{1, 7, 3, 2, 1};
            colClues[11] = new int[]{1, 2, 3, 1, 1, 1, 1, 1};
            colClues[12] = new int[]{4, 1, 1, 2, 6};
            colClues[13] = new int[]{3, 3, 1, 1, 1, 3, 1};
            colClues[14] = new int[]{1, 2, 5, 2, 2};
            colClues[15] = new int[]{2, 2, 1, 1, 1, 1, 1, 2, 1};
            colClues[16] = new int[]{1, 3, 3, 2, 1, 8, 1};
            colClues[17] = new int[]{6, 2, 1};
            colClues[18] = new int[]{7, 1, 4, 1, 1, 3};
            colClues[19] = new int[]{1, 1, 1, 1, 4};
            colClues[20] = new int[]{1, 3, 1, 3, 7, 1};
            colClues[21] = new int[]{1, 3, 1, 1, 1, 2, 1, 1, 4};
            colClues[22] = new int[]{1, 3, 1, 4, 3, 3};
            colClues[23] = new int[]{1, 1, 2, 2, 2, 6, 1};
            colClues[24] = new int[]{7, 1, 3, 2, 1, 1};
            
            for(int i=0;i<colClues.length;i++){
                for(int o=0;o<colClues[i].length;o++){
                    System.out.print(colClues[i][o]);
                }
                System.out.println("");
            }
            
            rowClues[0] = new int[]{7, 3, 1, 1, 7};
            rowClues[1] = new int[]{1, 1, 2, 2, 1, 1};
            rowClues[2] = new int[]{1, 3, 1, 3, 1, 1, 3, 1};
            rowClues[3] = new int[]{1, 3, 1, 1, 6, 1, 3, 1};
            rowClues[4] = new int[]{1, 3, 1, 5, 2, 1, 3, 1};
            rowClues[5] = new int[]{1, 1, 2, 1, 1};
            rowClues[6] = new int[]{7, 1, 1, 1, 1, 1, 7};
            rowClues[7] = new int[]{3, 3};
            rowClues[8] = new int[]{1, 2, 3, 1, 1, 3, 1, 1, 2};
            rowClues[9] = new int[]{1, 1, 3, 2, 1, 1};
            rowClues[10] = new int[]{4, 1, 4, 2, 1, 2};
            rowClues[11] = new int[]{1, 1, 1, 1, 1, 4, 1, 3};
            rowClues[12] = new int[]{2, 1, 1, 1, 2, 5};
            rowClues[13] = new int[]{3, 2, 2, 6, 3, 1};
            rowClues[14] = new int[]{1, 9, 1, 1, 2, 1};
            rowClues[15] = new int[]{2, 1, 2, 2, 3, 1};
            rowClues[16] = new int[]{3, 1, 1, 1, 1, 5, 1};
            rowClues[17] = new int[]{1, 2, 2, 5};
            rowClues[18] = new int[]{7, 1, 2, 1, 1, 1, 3};
            rowClues[19] = new int[]{1, 1, 2, 1, 2, 2, 1};
            rowClues[20] = new int[]{1, 3, 1, 4, 5, 1};
            rowClues[21] = new int[]{1, 3, 1, 3, 10, 2};
            rowClues[22] = new int[]{1, 3, 1, 1, 6, 6};
            rowClues[23] = new int[]{1, 1, 2, 1, 1, 2};
            rowClues[24] = new int[]{7, 2, 1, 2, 5};
            
            printgridbig(grid);
            printgridsmall(grid, colClues, rowClues);
            
        }
    
    
        /**
         * - a blank space # - a filled square r - a guess for a row clue c - a
         * guess for a col clue b - a guess for both a row and col clue
         */
        public final void printgridbig(int[][] pgrid) {
            for (int o = 0; o < pgrid.length; o++) {
                for (int b = 0; b < pgrid.length; b++) {
                    System.out.print("----");
                }
                System.out.println("-");
                for (int i = 0; i < pgrid.length; i++) {
                    if (pgrid[i][o] == 0) {
                        System.out.print("|   ");
                    } else if (pgrid[i][o] == 1) {
                        System.out.print("| # ");
                    } else if (pgrid[i][o] == 2) {
                        System.out.print("| r ");
                    } else if (pgrid[i][o] == 3) {
                        System.out.print("| c ");
                    } else if (pgrid[i][o] == 4) {
                        System.out.print("| b ");
                    }
                }
                System.out.println("|");
            }
            for (int b = 0; b < pgrid.length; b++) {
                System.out.print("----");
            }
            System.out.println("-");
        }
    
    
        /**
         * - - a blank space # - a filled square r - a guess for a row clue c - a
         * guess for a col clue b - a guess for both a row and col clue
         */
        public final void printgridsmall(int[][] pgrid, int[][] pcolclues, int[][] prowclues) {
            int maxRowCluesize = 0;
            for (int i = 0; i < pcolclues.length; i++) {
                if (maxRowCluesize < pcolclues[i].length) {
                    maxRowCluesize = pcolclues[i].length;
                }
            }
            printgridsmallcolclue(pcolclues,maxRowCluesize);
            
            
            for (int o = 0; o < pgrid.length; o++) {
                printgridsmallrowclue(prowclues, o, maxRowCluesize);
                for (int i = 0; i < pgrid.length; i++) {
                    if (pgrid[i][o] == 0) {
                        System.out.print(" - ");
                    } else if (pgrid[i][o] == 1) {
                        System.out.print(" # ");
                    } else if (pgrid[i][o] == 2) {
                        System.out.print(" r ");
                    } else if (pgrid[i][o] == 3) {
                        System.out.print(" c ");
                    } else if (pgrid[i][o] == 4) {
                        System.out.print(" b ");
                    }
                }
                System.out.println("");
            }
            
        }
        
        private final void printgridsmallcolclue(int[][] pcolclues, int maxRowClueSize) {
            int maxCluesize = 0;
            for (int i = 0; i < pcolclues.length; i++) {
                if (maxCluesize < pcolclues[i].length) {
                    maxCluesize = pcolclues[i].length;
                }
            }
            
            for (int i = 0; i < maxCluesize; i++) {
                for(int f=0;f<maxRowClueSize;f++){
                    System.out.print("   ");
                }
                
                for (int o = 0; o < pcolclues.length; o++) {
                    if (pcolclues[o].length >= maxCluesize - i) {
                        System.out.print(" " + pcolclues[o][i - (maxCluesize - pcolclues[o].length)] + " ");
                    } else {
                        System.out.print("   ");
                    }
                }
                System.out.println("");
            }
        }
        
        private final void printgridsmallrowclue(int[][] prowclues, int row, int maxRowCluesize) {
            for (int o = 0; o < maxRowCluesize; o++) {
                    if (prowclues[row].length >= maxRowCluesize - o) {
                        System.out.print(" " + prowclues[row][o - (maxRowCluesize - prowclues[row].length)]);
                        if(prowclues[row][o - (maxRowCluesize - prowclues[row].length)] <10){//for numbers that have two digits, remove extra padding space
                            System.out.print(" ");
                        }
                    } else {
                        System.out.print("   ");
                    }
                }
            
        }
    
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            UKintPuzzle1 p = new UKintPuzzle1();
        }
        
    }
    -- Intentionally Left Blank --

  2. Registered TeamPlayer DJ Ms. White's Avatar
    Join Date
    11-13-07
    Location
    Plano, TX and Ruston, LA
    Posts
    32,364
    Post Thanks / Like
    Blog Entries
    43
    Stat Links

    Programming challenge - fun stuff Programming challenge - fun stuff Programming challenge - fun stuff Programming challenge - fun stuff
    Gamer IDs

    Steam ID: DJMrWhite
    #2

    Re: Programming challenge - fun stuff

    This is also a fun subreddit for varying levels of skill.
    https://www.reddit.com/r/dailyprogrammer/
    enf-Jesus its been like 12 minutes and you're already worried about stats?! :-P
    Bigdog-
    Sweet home Alabama you are an idiot.

  3. Registered TeamPlayer salty99's Avatar
    Join Date
    05-13-09
    Location
    Arizona
    Posts
    6,117
    Post Thanks / Like
    Blog Entries
    3
    Stat Links

    Programming challenge - fun stuff Programming challenge - fun stuff Programming challenge - fun stuff Programming challenge - fun stuff Programming challenge - fun stuff
    Gamer IDs

    Gamertag: salty99 PSN ID: mynameisfatmike salty99's Originid: mynameisfatmike
    #3

    Re: Programming challenge - fun stuff

    Learn python the hard way has some decent challenges.

    Been a while since I have done one of these. I'll check it out


  4. Administrator Kanati's Avatar
    Join Date
    05-15-08
    Location
    Pekin, Illinois, United States
    Posts
    17,724
    Post Thanks / Like
    Stat Links

    Programming challenge - fun stuff Programming challenge - fun stuff Programming challenge - fun stuff Programming challenge - fun stuff Programming challenge - fun stuff Programming challenge - fun stuff
    #4

    Re: Programming challenge - fun stuff

    Fuck I don't know how to solve that by hand let alone by program.
    Likes salty99, Gunny liked this post

    Krakkens and shit. stop tempting them.
    -- Bigdog

  5. Registered TeamPlayer rush2049's Avatar
    Join Date
    03-26-11
    Location
    Lancaster, PA
    Posts
    1,213
    Post Thanks / Like
    Stat Links

    Programming challenge - fun stuff Programming challenge - fun stuff Programming challenge - fun stuff Programming challenge - fun stuff Programming challenge - fun stuff
    Gamer IDs

    Gamertag: Benjamin Rush PSN ID: Benjamin_Rush Steam ID: rush2049 rush2049's Originid: rush20492002
    #5

    Re: Programming challenge - fun stuff

    -- Intentionally Left Blank --

Thread Information

Users Browsing this Thread

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

Tags for this Thread

Bookmarks

Posting Permissions

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