Skip to content

Commit 034616f

Browse files
committed
Use longs for swindlers, allowing even bigger swindlers
1 parent 9f2df70 commit 034616f

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

Common/src/main/java/at/petrak/hexcasting/api/casting/ActionUtils.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,18 @@ fun List<Iota>.getPositiveInt(idx: Int, argc: Int = 0): Int {
199199
throw MishapInvalidIota.of(x, if (argc == 0) idx else argc - (idx + 1), "int.positive")
200200
}
201201

202+
fun List<Iota>.getPositiveLong(idx: Int, argc: Int = 0): Long {
203+
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
204+
if (x is DoubleIota) {
205+
val double = x.double
206+
val rounded = double.roundToLong()
207+
if (abs(double - rounded) <= DoubleIota.TOLERANCE && rounded >= 0) {
208+
return rounded
209+
}
210+
}
211+
throw MishapInvalidIota.of(x, if (argc == 0) idx else argc - (idx + 1), "int.positive")
212+
}
213+
202214
fun List<Iota>.getPositiveIntUnder(idx: Int, max: Int, argc: Int = 0): Int {
203215
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
204216
if (x is DoubleIota) {

Common/src/main/java/at/petrak/hexcasting/common/casting/actions/stack/OpAlwinfyHasAscendedToABeingOfPureMath.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
55
import at.petrak.hexcasting.api.casting.eval.OperationResult
66
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
77
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
8-
import at.petrak.hexcasting.api.casting.getPositiveInt
8+
import at.petrak.hexcasting.api.casting.getPositiveLong
99
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs
1010
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds
11-
import it.unimi.dsi.fastutil.ints.IntArrayList
11+
import it.unimi.dsi.fastutil.longs.LongArrayList
1212

1313
// "lehmer code"
1414
object OpAlwinfyHasAscendedToABeingOfPureMath : Action {
@@ -18,10 +18,10 @@ object OpAlwinfyHasAscendedToABeingOfPureMath : Action {
1818
if (stack.isEmpty())
1919
throw MishapNotEnoughArgs(1, 0)
2020

21-
val code = stack.getPositiveInt(stack.lastIndex)
21+
val code = stack.getPositiveLong(stack.lastIndex)
2222
stack.removeLast()
2323

24-
val strides = IntArrayList()
24+
val strides = LongArrayList()
2525
for (f in FactorialIter()) {
2626
if (f <= code)
2727
strides.add(f)
@@ -37,7 +37,7 @@ object OpAlwinfyHasAscendedToABeingOfPureMath : Action {
3737
for (divisor in strides.asReversed()) {
3838
val index = radix / divisor
3939
radix %= divisor
40-
editTarget[0] = swap.removeAt(index)
40+
editTarget[0] = swap.removeAt(index.toInt())
4141
// i hope this isn't O(n)
4242
editTarget = editTarget.subList(1, editTarget.size)
4343
}
@@ -46,12 +46,12 @@ object OpAlwinfyHasAscendedToABeingOfPureMath : Action {
4646
return OperationResult(image2, listOf(), continuation, HexEvalSounds.NORMAL_EXECUTE)
4747
}
4848

49-
private class FactorialIter : Iterator<Int> {
50-
var acc = 1
51-
var n = 1
49+
private class FactorialIter : Iterator<Long> {
50+
var acc = 1L
51+
var n = 1L
5252
override fun hasNext(): Boolean = true
5353

54-
override fun next(): Int {
54+
override fun next(): Long {
5555
val out = this.acc
5656
this.acc *= this.n
5757
this.n++

0 commit comments

Comments
 (0)