Graphical representation of a puzzle - graphics

Just for fun, I have written a solver for str8ts puzzles. While dealing with the REPL representation of a puzzle is okay for me, e.g.
STR8TS> (solve-puzzle #p"puzzles/2019-02-04-hard")
Initial puzzle:
-----------------------------------------------------
| -7 | -9 | 0 | 0 | 10 | 0 | 0 | 0 | 10 |
| 3 | 0 | 6 | 0 | 0 | 0 | 0 | 0 | 10 |
| 0 | 0 | 10 | 0 | 0 | 10 | 10 | 0 | 0 |
| 0 | 1 | 0 | 10 | 10 | 0 | 0 | 5 | 0 |
| 10 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 10 |
| 0 | 0 | 0 | 0 | -6 | 10 | 0 | 9 | 0 |
| 0 | 0 | 10 | 10 | 0 | 0 | -2 | 0 | 0 |
| 10 | 0 | 9 | 0 | 0 | 5 | 0 | 0 | 0 |
| -4 | 0 | 0 | 0 | 10 | 0 | 0 | -1 | -3 |
-----------------------------------------------------
Final state:
-----------------------------------------------------
| -7 | -9 | 5 | 6 | 10 | 2 | 3 | 4 | 10 |
| 3 | 8 | 6 | 5 | 7 | 1 | 4 | 2 | 10 |
| 1 | 2 | 10 | 7 | 8 | 10 | 10 | 6 | 5 |
| 2 | 1 | 3 | 10 | 10 | 7 | 8 | 5 | 6 |
| 10 | 6 | 4 | 3 | 5 | 8 | 9 | 7 | 10 |
| 5 | 3 | 2 | 4 | -6 | 10 | 7 | 9 | 8 |
| 6 | 5 | 10 | 10 | 3 | 4 | -2 | 8 | 9 |
| 10 | 4 | 9 | 8 | 2 | 5 | 6 | 3 | 7 |
| -4 | 7 | 8 | 9 | 10 | 6 | 5 | -1 | -3 |
-----------------------------------------------------
Puzzle solved in 4.168 seconds.
I was wondering what could be a more elegant way to /draw/ the puzzle. The puzzle is stored in a two-dimensional array and 10 and negative number should be black fields.
Is there a library which allows for the generation of a simple png or svg file of the puzzle grid in b/w and the numbers as text?

I use Vecto for things like that. It's fairly low-level (kind of like writing PostScript code), but lets you draw stuff like the Movie Charts, so it's a matter of planning and practice to make what you like.

Related

Change x:y to x ↵ y

I have the following problem: In my very large excel spreadsheet, I have a few rows that look like this:
Memo: IBRD
0
0
0
0
0
0
0
0
0
0
IDA
0
0
0
0
0
0
0
0
0
0
and a few others that look like this:
Memo:
IBRD
0
0
0
0
0
0
0
0
0
0
IDA
0
0
0
0
0
0
0
0
0
0
I want them to be uniform and change all those that exhibit the first format to the SECOND one (where Memo: empty; and the next row is IBRD with the data entries).
I have found the following VBA code that might do the trick but I am not 100% how to apply this to my problem here.
Sub splitOneCellIntoMore()
Dim R As Range
Dim I As Range
Dim O As Range
wTitle = "splitOneCellIntoMoreCells"
Set I = Application.Selection.Range("B")
Set I = Application.InputBox("Select the Cell B1 that contains the text you want to split:", wTitle, I.Address, Type:=8)
Set O = Application.InputBox("Select destination cell you want to paste your split data:", wTitle, Type:=8)
A = VBA.Split(I.Value, ":")
O.Resize(UBound(A) - LBound(A) + 1).Value = Application.Transpose(A)
End Sub
(I took the code from: https://www.excelhow.net/split-one-cell-into-two-or-more-cells.html)
This is the table I am using.
| DEBT OUTSTANDING(LDOD) | | | | 36 | 330 | 405 | 412 | 527 |
| ------------------------------------------------------------------- |--|---|---|---|---|---|---|---|
| Public and publicly e;uaranteed | | | | 36 | 330 | 405 | 412 | 506 |
| Official creditors | | | | 2 | 305 | 376 | 385 | 480 |
| Multilateral | | | | 0 | 115 | 151 | 164 | 242 |
| Concessional                                                      I | | | | 0 | 110 | 142 | 155 | 232 |
| Bilateral | | | | 2 | 190 | 225 | 221 | 238 |
| Concessional | | | | 2 | 151 | 189 | 190 | 212 |
| Private creditors | | | | 34 | 25 | 29 | 27 | 26 |
| Bonds | | | | 0 | 0 | 0 | 0 | 0 |
| Commercial banks | | | | 0 | 0 | 0 | 0 | 0 |
| Other private | | | | 34 | 25 | 29 | 27 | 26 |
| Privatenone;uaranteed | | | | 0 | 0 | 0 | 0 | 21 |
| Bonds | | | | 0 | 0 | 0 | 0 | 0 |
| Commercial banks and other | | | | 0 | 0 | 0 | 0 | 21 |
| Memo: IBRD | | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| | | | | | | | | |
| IDA | | 0 | 0 | 0 | 109 | 137 | 148 | 220 |
| DISBURSEMENTS | | | | 33 | 70 | 90 | 52 | 89 |
| Public and publicly e;uaranteed | | | | 33 | 70 | 90 | 52 | 89 |
Screenshot/link refer:
Use FilterXML to split cells as follows:
=IFERROR(TRANSPOSE(FILTERXML("<x><y>"&SUBSTITUTE(A2,"|","</y><y>")&"</y></x>","//y")),"")

Pandas finding intervals (of n-Days) and capturing start/end dates

This started its life as a list of activities. I first built a matrix similar to the one below to represent all activities, which I inverted to show all inactivity, before building the following matrix, where zero indicates an activity, and anything greater than zero indicates the number of days before the next activity.
+------+------------+------------+------------+------------+------------+------------+------------+------------+------------+
| Item | 01/08/2020 | 02/08/2020 | 03/08/2020 | 04/08/2020 | 05/08/2020 | 06/08/2020 | 07/08/2020 | 08/08/2020 | 09/08/2020 |
+------+------------+------------+------------+------------+------------+------------+------------+------------+------------+
| A | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| B | 3 | 2 | 1 | 0 | 0 | 3 | 2 | 1 | 0 |
| C | 0 | 2 | 1 | 0 | 1 | 0 | 0 | 0 | 0 |
| D | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 0 |
| E | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
+------+------------+------------+------------+------------+------------+------------+------------+------------+------------+
Now I need to find suitable intervals for each Item. For instance, in this case I want to find all intervals with a minimum duration of 3-days.
+------+------------+------------+------------+------------+
| Item | 1_START | 1_END | 2_START | 2_END |
+------+------------+------------+------------+------------+
| A | NaN | NaN | NaN | NaN |
| B | 01/08/2020 | 03/08/2020 | 06/08/2020 | 08/08/2020 |
| C | NaN | NaN | NaN | NaN |
| D | 01/08/2020 | 07/08/2020 | NaN | NaN |
| E | 01/08/2020 | NaN | NaN | NaN |
+------+------------+------------+------------+------------+
In reality the data is 700+ columns wide and 1,000+ rows. How can I do this efficiently?

Auto Incrementing Number Values in Excel

I have to re-number over 30,000 rows in excel and am looking for a way to do this through an embedded excel function.
I have two columns, the original BuildingCount and the Test column. In the BuildingCount column, I have inconsistent count that needs to be consecutive 1,2,3 numbers in order to run a macros. However, the numbers are not always consecutive. I have been writing different variations of excel functions. The below is the output for =IF(A2>1),A2+1,1)
+----+---------------+------------+
| | A | B |
+----+---------------+------------+
| 1 | BuildingCount | TestColumn |
| 2 | 1 | #VALUE! |
| 3 | 2 | 1 |
| 4 | 3 | 3 |
| 5 | 5 | 4 |
| 6 | 6 | 6 |
| 7 | 9 | 7 |
| 8 | 1 | 10 |
| 9 | 2 | 1 |
| 10 | 3 | 3 |
| 11 | 4 | 4 |
| 12 | 5 | 5 |
+----+---------------+------------+
Ideally, the output would be the following:
+----+---------------+------------+
| | A | B |
+----+---------------+------------+
| 1 | BuildingCount | TestColumn |
| 2 | 1 | 1 |
| 3 | 2 | 2 |
| 4 | 3 | 3 |
| 5 | 5 | 4 |
| 6 | 6 | 5 |
| 7 | 7 | 6 |
| 8 | 1 | 1 |
| 9 | 2 | 2 |
| 10 | 3 | 3 |
| 11 | 4 | 4 |
| 12 | 5 | 5 |
+----+---------------+------------+
Any ideas would be very welcomed.
Formula in B2:
=IF(ROW()=2,1,IF(A2>A1,B1+1,1))
And dragged down

Multiple Lookup Criteria

I have this data below in Excel. What I want is to return the No.of Inactive months and the Inactive months themselves.
ACTIVITY MONTH
Jan17 Feb17 Mar17 Apr17 Reg Month No.Inactive months Months Inactive
User ID
1 5 38 0 60 Jan17
2 0 242 203 20 Feb17
3 30 0 0 30 Jan17
4 0 0 0 40 Apr17
5 0 0 16 0 Mar17
To count the inactive months you can use the following.
+---+------+--------+--------+--------+--------+--+-----------------+
| | A | B | C | D | E | F| G |
+---+------+--------+--------+--------+--------+--+-----------------+
| 1 | User | Jan 17 | feb-17 | mar-17 | apr-17 | | Inactive months |
| 2 | 1 | 5 | 38 | 0 | 60 | | 1 |
| 3 | 2 | 0 | 242 | 203 | 20 | | 1 |
| 4 | 3 | 30 | 0 | 0 | 30 | | 2 |
| 5 | 4 | 0 | 0 | 0 | 40 | | 3 |
| 6 | 5 | 0 | 0 | 16 | 0 | | 3 |
+---+------+--------+--------+--------+--------+--+-----------------+
where in cell G2 the is this formula =COUNTIF(B2:E2,0)
To show the list of inactive months it's a little bit harder.
The point is that you have to explain how you want to see these results.
The easier way is to use the conditional formatting anc color the cell with zero (but this is not so useful). Others way could be to traspose the table and filter the column with zero. Another one could be to use a VBA macro....

How to get the cell with the highest number, work with it, get the next highest and so on in excel?

I'm trying to get a cell with value BBBBBBBGGGGGJJJJCCCCDDDDAA from these cells:
-----------------------------------------
| 2 | 7 | 4 | 4 | 0 | 0 | 5 | 0 | 0 | 4 |
-----------------------------------------
So it gets the highest value and writes the cell's horizontal address (that might have an offset) that many times. Then gets the next highest and does the same thing until it reaches the zeroes. Is that possible in excel?
additional samples:
------------------------------------------------------------------------------------
| 2 | 0 | 0 | 3 | 0 | 0 | 5 | 0 | 0 | 0 | GGGGGDDDAA |
------------------------------------------------------------------------------------
| 0 | 0 | 2 | 0 | 0 | 0 | 5 | 0 | 0 | 0 | GGGGGCC |
------------------------------------------------------------------------------------
| 0 | 7 | 2 | 2 | 4 | 3 | 3 | 0 | 0 | 0 | BBBBBBBEEEEFFFGGGCCDD |
------------------------------------------------------------------------------------
| 4 | 7 | 0 | 7 | 7 | 0 | 0 | 0 | 8 | 7 | IIIIIIIIBBBBBBBDDDDDDDEEEEEEEJJJJJJJAAAA |
------------------------------------------------------------------------------------
| 0 | 2 | 0 | 2 | 8 | 0 | 8 | 0 | 7 | 10| JJJJJJJJJJEEEEEEEEGGGGGGGGIIIIIIIBBDD |
------------------------------------------------------------------------------------

Resources