(setqxinput" [D]
[N] [C]
[Z] [M] [P]
1 2 3
move 1 from 2 to 1
move 3 from 1 to 3
move 2 from 2 to 1
move 1 from 1 to 2")
;; first, split the input into 2 parts
(setqxinputParts (split-stringxinput"\n\n"))
(setqxBoxesText (nth 0 xinputParts))
(setqxProcedure (nth 1 xinputParts))
;; split the boxes input, per line, into a list of 4 chars
(setqxBoxesLineList (split-stringxBoxesText"\n"))
(setqxNumOfColumns
(string-to-number
(car (last
(split-string
(car (lastxBoxesLineList)) " +")))))
;; drop the last time
(setqxBoxesLineList (reverse (rest (reversexBoxesLineList))))
(require 'subr-x)
;; a list of list. each sublist is a row of boxes
(setqxBoxMatrixnil)
;; built the xBoxMatrix
(mapc
(lambda (x)
(let ((xx (string-pad x (* 4 xNumOfColumns) 32))
(xlistnil))
(message"%s"xx)
;; split each line, into 4 chars
(while (not (equal (lengthxx) 0))
(push (string-trim (substringxx 0 4)) xlist)
(setqxx (substringxx 4)))
(setqxlist (reversexlist))
(message"%s"xlist)
(pushxlistxBoxMatrix)))
xBoxesLineList)
(setqxBoxMatrix (reversexBoxMatrix))
;; convert xBoxMatrix into a netsed vector
(setqxBoxMatrix
(vconcat
(mapcar
(lambda (x) (vconcatx))
xBoxMatrix)))
;; [["" "[D]" ""] ["[N]" "[C]" ""] ["[Z]" "[M]" "[P]"]]
(defunxah-transpose (Matrix)
"transpose a matrix.
the matrix is assumed to be 2D.
and assumed to be nested vector, not list.
before
a b c
d e f
after transpose
a d
b e
c f
Version 2022-12-29"
(interactive)
(let (($flatList '())
($rowCount (lengthMatrix))
($colCount (length (arefMatrix 0))))
(message"row count %s"$rowCount)
(message"col count %s"$colCount)
(dotimes (i COUNT [RESULT])
(dotimes (j COUNT [RESULT])
;; # python
;; # transpose, body of
;; temp = arr[i][j]
;; arr[i][j] = arr[j][i]
;; arr[j][i] = temp
))
(mapc
(lambda (x)
(mapc
(lambda (y) (push y $flatList))
x))
Matrix)
(seq-partition (reverse$flatList) $rowCount)
;; (vconcat (seq-partition $flatList $rowCount))
;; ))
(xah-transpose
[
[1 2 3]
[4 5 6]
]
)