Copy / past diagrams

Everything about Sudoku that doesn't fit in one of the other sections

Re: Copy / past diagrams

Postby Pupp » Sat Aug 29, 2020 3:26 am

SpAce wrote:
Pupp wrote:I wanted to mention that the large triple diagram comes from Hodoku using the "copy for simplesudoku format"

Thanks! Looks like I never tried that option. Too bad the givens/values diagrams are so narrow. Better than nothing anyway.


I can't say I'm a fan of using Hodoku's "Copy for SimpleSudoko".

For a clean puzzle, using SudoCue's "Copy Filled" gives the best clean diagram without pencilmarks.
Code: Select all
9 . .|1 . .|. . 4
. . 8|. 9 .|. . .
. . .|. . 6|. 2 .
-----+-----+-----
. . 6|4 3 7|. . 1
. 9 .|6 . 8|. 3 .
3 . .|2 5 9|7 . .
-----+-----+-----
. 5 .|3 . .|. . .
. . .|. 2 .|3 . .
7 . .|. . 5|. . 9
Pupp
 
Posts: 246
Joined: 18 October 2019

Re: Copy / past diagrams

Postby 1to9only » Sat Aug 29, 2020 6:36 am

SpAce wrote:
Pupp wrote:I wanted to mention that the large triple diagram comes from Hodoku using the "copy for simplesudoku format"

Thanks! Looks like I never tried that option. Too bad the givens/values diagrams are so narrow. Better than nothing anyway.

If you are able to compile your own version of Hodoku.jar, in SudokuUtil.java change the followding code from:
Code: Select all
    /**
     * Reformat a sudoku given by a 81 character string to SimpleSudoku format.
     *
     * @param values
     * @return
     */
    public static String getSSFormatted(String values) {
        StringBuilder tmp = new StringBuilder();
        values = values.replace('0', '.');
        tmp.append(" *-----------*");
        tmp.append(NEW_LINE);
        writeSSLine(tmp, values, 0);
        writeSSLine(tmp, values, 9);
        writeSSLine(tmp, values, 18);
        tmp.append(" |---+---+---|");
        tmp.append(NEW_LINE);
        writeSSLine(tmp, values, 27);
        writeSSLine(tmp, values, 36);
        writeSSLine(tmp, values, 45);
        tmp.append(" |---+---+---|");
        tmp.append(NEW_LINE);
        writeSSLine(tmp, values, 54);
        writeSSLine(tmp, values, 63);
        writeSSLine(tmp, values, 72);
        tmp.append(" *-----------*");
        tmp.append(NEW_LINE);
        return tmp.toString();
    }

    /**
     * Build one line of a sudoku defined by <code>clues</code> in SimpleSudoku
     * format.
     *
     * @param tmp
     * @param clues
     * @param startIndex
     */
    private static void writeSSLine(StringBuilder tmp, String clues, int startIndex) {
        tmp.append(" |");
        tmp.append(clues.substring(startIndex + 0, startIndex + 3));
        tmp.append("|");
        tmp.append(clues.substring(startIndex + 3, startIndex + 6));
        tmp.append("|");
        tmp.append(clues.substring(startIndex + 6, startIndex + 9));
        tmp.append("|");
        tmp.append(NEW_LINE);
    }


To:
Code: Select all
    /**
     * Reformat a sudoku given by a 81 character string to SimpleSudoku format.
     *
     * @param values
     * @return
     */
    public static String getSSFormatted(String values) {
        StringBuilder tmp = new StringBuilder();
        values = values.replace('0', '.');
        tmp.append(" *-----------------------*");
        tmp.append(NEW_LINE);
        writeSSLine(tmp, values, 0);
        writeSSLine(tmp, values, 9);
        writeSSLine(tmp, values, 18);
        tmp.append(" |-------+-------+-------|");
        tmp.append(NEW_LINE);
        writeSSLine(tmp, values, 27);
        writeSSLine(tmp, values, 36);
        writeSSLine(tmp, values, 45);
        tmp.append(" |-------+-------+-------|");
        tmp.append(NEW_LINE);
        writeSSLine(tmp, values, 54);
        writeSSLine(tmp, values, 63);
        writeSSLine(tmp, values, 72);
        tmp.append(" *-----------------------*");
        tmp.append(NEW_LINE);
        return tmp.toString();
    }

    /**
     * Build one line of a sudoku defined by <code>clues</code> in SimpleSudoku
     * format.
     *
     * @param tmp
     * @param clues
     * @param startIndex
     */
    private static void writeSSLine(StringBuilder tmp, String clues, int startIndex) {
        tmp.append(" |");
        tmp.append(" "+clues.substring(startIndex + 0, startIndex + 1));
        tmp.append(" "+clues.substring(startIndex + 1, startIndex + 2));
        tmp.append(" "+clues.substring(startIndex + 2, startIndex + 3));
        tmp.append(" |");
        tmp.append(" "+clues.substring(startIndex + 3, startIndex + 4));
        tmp.append(" "+clues.substring(startIndex + 4, startIndex + 5));
        tmp.append(" "+clues.substring(startIndex + 5, startIndex + 6));
        tmp.append(" |");
        tmp.append(" "+clues.substring(startIndex + 6, startIndex + 7));
        tmp.append(" "+clues.substring(startIndex + 7, startIndex + 8));
        tmp.append(" "+clues.substring(startIndex + 8, startIndex + 9));
        tmp.append(" |");
        tmp.append(NEW_LINE);
    }


To get:
Code: Select all
 *-----------------------*
 | . . 1 | 6 . 3 | . . 4 |
 | 4 . . | . . . | . . . |
 | . 7 3 | . 8 2 | . . 1 |
 |-------+-------+-------|
 | 6 4 . | . . . | . . . |
 | . . 8 | . 9 . | 1 . . |
 | . . . | . . . | . 7 6 |
 |-------+-------+-------|
 | 1 . . | 2 4 . | 3 5 . |
 | . . . | . . . | . . 7 |
 | 5 . . | 8 . 7 | 6 . . |
 *-----------------------*
User avatar
1to9only
 
Posts: 4177
Joined: 04 April 2018

Re: Copy / past diagrams

Postby SpAce » Sat Aug 29, 2020 11:00 am

1to9only wrote:If you are able to compile your own version of Hodoku.jar, in SudokuUtil.java change the followding code from:

Thanks for that tip, too! Yeah, I could do it. There are many other things I'd like to tweak in Hodoku, but so far I've avoided touching the code. I'm afraid I wouldn't be able to stop :D

(I've mostly avoided even looking at the code, especially the solving logic. One day I might like to code my own helper/solver, and I'd like to do it with my own ideas -- at least first. Afterwards I could then check how others have coded the same parts to see what could be improved.)
User avatar
SpAce
 
Posts: 2671
Joined: 22 May 2017

Re: Copy / past diagrams

Postby Pupp » Sat Aug 29, 2020 2:37 pm

how do you change the code in Hodoku?
Pupp
 
Posts: 246
Joined: 18 October 2019

Re: Copy / past diagrams

Postby SpAce » Sat Aug 29, 2020 3:03 pm

Pupp wrote:how do you change the code in Hodoku?

Get the source code from here. It's in the hodoku-2-2-0-src.zip. Then you just need to know how to code and compile Java.

There's also a newer version under this fork. I haven't tried it.
User avatar
SpAce
 
Posts: 2671
Joined: 22 May 2017

Previous

Return to General