Skip to content

Commit

Permalink
Fix offsets computation for gcd(k, p) > 1
Browse files Browse the repository at this point in the history
  • Loading branch information
jedlimlx committed May 12, 2024
1 parent e1614b8 commit b0e2034
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 44 deletions.
21 changes: 15 additions & 6 deletions src/commonMain/kotlin/search/cfind/CFind.kt
Original file line number Diff line number Diff line change
Expand Up @@ -119,29 +119,38 @@ class CFind(
// TODO fix this for oscillators searches in other directions
val offsets = IntArray(this.period * maxOf(this.k, 1) *
(if (symmetry == ShipSymmetry.GLIDE && direction == Coordinate(1, 1)) 2 else 1)
) { 0 }

/*.apply {
) { -1 }.apply {
if (symmetry != ShipSymmetry.GLIDE || direction != Coordinate(1, 1)) {
// Compute the offsets
var initialCount = 0
for (i in 0 ..<k) {
var count = (i*period).mod(k) // TODO fix for gcd(k, p) > 1
var count = initialCount
val lst = arrayListOf(initialCount)
while (count < period * k) {
this[count] = tempOffsets[i.mod(tempOffsets.size)]
count += backOff[count.mod(period)]
lst.add(count)
}

for (j in initialCount..lst.max()) {
if (j !in lst) {
initialCount = j
break
}
}
}
} else {
var flipped = false
for (i in 0 ..<2*period) {
this[i*k] = if (flipped) 1 else 0
if (period.mod(2) == 1 || i.mod(period) == 0) flipped = !flipped

for (j in 0..<2*k) {
this[(i*k+j*period) % this.size] = (this[i*k] + j) % 2
}
}
}
}*/
}

// Compute various statistics about the neighbourhood
// TODO Get neighbourhood coordinate direction conventions right
Expand Down
58 changes: 20 additions & 38 deletions src/jvmMain/kotlin/Main.jvm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import rules.hrot.HROTGenerations
import rules.nontotalistic.rules.DeficientINT
import rules.nontotalistic.rules.INT
import rules.nontotalistic.rules.INTGenerations
import rules.nontotalistic.transitions.R2VonNeumannINT
import rules.ruleloader.builders.ruletable
import rules.ruleloader.ruletableFromFile
import rules.ruleloader.ruletree.ruletreeDirectiveFromString
Expand Down Expand Up @@ -68,51 +69,32 @@ actual fun main() {
// htmlDocument { body { findFirst { text } } }
// }
// }

// val gliderdb = GliderDB(output)
// println(gliderdb.searchByRule(HROTGenerations("/2/3")..HROTGenerations("012345678/2345678/3")).map {
// "x = 0, y = 0, rule = ${it.ruleRange!!.first}\n${it.canonPhase}"
// }.joinToString("\n\n"))

// val ruletable = ruletable {
// name = "B1S235F23K4L035"
//
// val birth = setOf(1)
// val survival = setOf(2, 3, 5)
// val forcing = setOf(2, 3)
// val killing = setOf(4)
// val living = setOf(0, 3, 5)
//
// tree(
// numStates = 3,
// neighbourhood = moore(1),
// background = intArrayOf(0)
// ) { neighbours, cellState ->
// val sum1 = neighbours.count { it == 1 }
// val sum2 = neighbours.count { it == 2 }
//
// when (cellState) {
// 1 -> {
// if (killing.contains(sum2)) 0
// else if (survival.contains(sum1)) 1
// else 2
// }
// 2 -> {
// if (living.contains(sum1)) 0 else 2
// }
// else -> {
// if (birth.contains(sum1) && forcing.contains(sum2)) 1 else 0
// }
// }
// }
// }
val transitions: MutableList<List<Int>> = arrayListOf()
val weights = arrayOf(3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2)
for (i in 0..<(1 shl 12)) {
val string = i.toString(2).padStart(12, '0')
val cells = string.map { it.digitToInt() }

// val ruletable = ruletableFromFile("SoManyShips3.rule")
//
// // B2-ei3cjkr4cektyz5-cnr6-ik78/S01e2-ae3cnqry4cqrtwyz5-ain6ekn7e
val sum = cells.mapIndexed { index, it -> weights[index] * it }.sum()
if (sum in 9 .. 11 || sum == 4)
transitions.add(cells)
}

println(R2VonNeumannINT(transitions).transitionString)

val ruletable = ruletableFromFile("SoManyShips3.rule")

// B2-ei3cjkr4cektyz5-cnr6-ik78/S01e2-ae3cnqry4cqrtwyz5-ain6ekn7e
val search = CFind(
DeficientINT("B2/S/D"), 2, 1, 6, ShipSymmetry.ODD,
verbosity = 1, searchStrategy = SearchStrategy.PRIORITY_QUEUE, lookaheadDepth = 1
HROT("R2,C2,S3,B3,NN"), 4, 1, 6, ShipSymmetry.ODD,
verbosity = 1, searchStrategy = SearchStrategy.PRIORITY_QUEUE, //lookaheadDepth = 0,
direction = Coordinate(1, 1)
)
search.search()

Expand Down

0 comments on commit b0e2034

Please sign in to comment.