This commit is contained in:
InsanusMokrassar 2018-09-06 13:15:16 +08:00
parent 4e70f449e4
commit 4e7580bb57
2 changed files with 83 additions and 16 deletions

View File

@ -10,33 +10,67 @@ private fun Int.toDigits(): List<Byte> {
return "$this".map { "$it".toByte() }
}
val UPPER_DIAG_MATRIX_INDEX = 0 to 3
val DOWN_DIAG_MATRIX_INDEX = 4 to 3
val UPPER_DIAG_MATRIX_INDEX = 3 to 0
val DOWN_DIAG_MATRIX_INDEX = 3 to 4
val FIRST_ROW_SUM_MATRIX_INDEX = 1 to 3
val SECOND_ROW_SUM_MATRIX_INDEX = 2 to 3
val FIRST_ROW_SUM_MATRIX_INDEX = 3 to 1
val SECOND_ROW_SUM_MATRIX_INDEX = 3 to 2
val THIRD_ROW_SUM_MATRIX_INDEX = 3 to 3
val FIRST_COLUMN_SUM_MATRIX_INDEX = 3 to 1
val SECOND_COLUMN_SUM_MATRIX_INDEX = 3 to 2
val THIRD_COLUMN_SUM_MATRIX_INDEX = 3 to 3
val FIRST_COLUMN_SUM_MATRIX_INDEX = 0 to 4
val SECOND_COLUMN_SUM_MATRIX_INDEX = 1 to 4
val THIRD_COLUMN_SUM_MATRIX_INDEX = 2 to 4
val EMPTY_CEILS_OF_MATRIX = (0 until 3).map { 0 to it }
val EMPTY_CEILS_OF_MATRIX = (0 until 3).map { it to 0 }
open class Psychomatrix(val date: DateTime) {
protected open val numbers: ByteArray = ByteArray(10)
/**
* Always array 4*5 of values. In rows was put columns (
* Always array 4*5 of values. In rows was put columns
*
*/
val asMatrix: Array<Array<Byte>>
val asMatrix: Array<Array<PsychomatrixCeilInfo>>
get() = arrayOf(
arrayOf(-1, -1, -1, getUpperDiagSum()),
arrayOf(numbers[1], numbers[4], numbers[7], getRowSum(0)),
arrayOf(numbers[2], numbers[5], numbers[8], getRowSum(1)),
arrayOf(numbers[3], numbers[6], numbers[9], getRowSum(2)),
arrayOf(getColumnSum(0), getColumnSum(1), getColumnSum(2), getDownDiagSum())
)
arrayOf(
null,
numbers[0],
numbers[1],
numbers[2],
getColumnSum(0)
),
arrayOf(
null,
numbers[3],
numbers[4],
numbers[5],
getColumnSum(1)
),
arrayOf(
null,
numbers[6],
numbers[7],
numbers[8],
getColumnSum(2)
),
arrayOf(
getUpperDiagSum(),
getRowSum(0),
getRowSum(1),
getRowSum(2),
getDownDiagSum()
)
).mapIndexed {
x, yArray ->
yArray.mapIndexed {
y, value ->
PsychomatrixCeilInfo(
x,
y,
value ?.toInt()
)
}.toTypedArray()
}.toTypedArray()
init {
val dateDigits = dateFormat.print(date).map { "$it".toByte() }.toMutableList()

View File

@ -0,0 +1,33 @@
package com.github.insanusmokrassar.PsychomatrixBase.domain.entities
data class PsychomatrixCeilInfo(
val x: Int,
val y: Int,
val count: Int?
) {
val ceilCoordsAsPair = x to y
val isUpperDiag = ceilCoordsAsPair == UPPER_DIAG_MATRIX_INDEX
val isDownDiag = ceilCoordsAsPair == DOWN_DIAG_MATRIX_INDEX
val isFirstRowSum = ceilCoordsAsPair == FIRST_ROW_SUM_MATRIX_INDEX
val isSecondRowSum = ceilCoordsAsPair == SECOND_ROW_SUM_MATRIX_INDEX
val isThirdRowSum = ceilCoordsAsPair == THIRD_ROW_SUM_MATRIX_INDEX
val isFirstColumnSum = ceilCoordsAsPair == FIRST_COLUMN_SUM_MATRIX_INDEX
val isSecondColumnSum = ceilCoordsAsPair == SECOND_COLUMN_SUM_MATRIX_INDEX
val isThirdColumnSum = ceilCoordsAsPair == THIRD_COLUMN_SUM_MATRIX_INDEX
val isCalculated =
ceilCoordsAsPair in EMPTY_CEILS_OF_MATRIX
|| isUpperDiag || isDownDiag
|| isFirstRowSum || isSecondRowSum || isThirdRowSum
|| isFirstColumnSum || isSecondColumnSum || isThirdColumnSum
val numberOfCharacteristic: Byte? = if (
isCalculated
) {
null
} else {
(x * 3 + y).toByte()
}
}