Cross reference calculator

I’m relatively new to Kotlin I’m building this simple calculator for the gym where users can calculate and submit data, weight, reps, and RPE with this information they can then calculate an estimated 1RM and next set weight.

I’ve built something similar in Excel where I use a cross-reference datasheet, it works fairly simply the user’s input, amount of reps(6) and RPE rate(8) would lookup the corresponding %(79) input weight(120) 120/79x100 = 1rm (152)

And the other way around wanted reps(3) wanted RPE (9) corresponding %(89) 1rm (152)
152x0,89 = 135

I can’t figure out how to build something similar in Kotlin. Anyone got any idea how to make this work?

What do you need to know exactly? For UI I would suggest either Android or JavaFX (desktop). But other than that you just need to learn, learn and eventually implement it (and learn!).

I’m using Android Studio to build it, I’ve basically built the user interface to my liking. Now I need a back page for the calculator with all the information needed to make the calculations according to the information put in the UI

In Excel, I can use a cross reference on a data sheet like shown in the second photo using the Vlookup command.

I would like to know if I can do something similar in Android Studio using Kotlin or if there is another better way to do this.

I can’t find any information about this

I’m guessing that what you want is some kind of lookup table…? (Either two tables, or one table with two indexes.)

Though the data looks so regular that I’d be surprised if there’s not a way to simply calculate the required value in each case instead.

Exactly, it would need to be 1 table with 2 indexes to find the corresponding % needed to do the rest of the calculation

If the value(reps) =6 / value (rpe) =8 then value (%) =…

It sounds like a simple map (?):

val table = mapOf(
    10.0 to mapOf(1 to 1.0, 2 to 0.955, 3 to 0.922),
    9.5 to mapOf(1 to 0.978, 2 to 0.939, 3 to 0.907),
println(table[9.5]!![2]) // 0.939

However, because we have a contiguous data here and because using doubles as map keys isn’t ideal, we can actually use an array of arrays or even a single flat array:

fun main() {
    println(getRatio(4, 1.5)) // 0.44

private val table = arrayOf(
    0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12, // RPE: 0.5
    0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, // RPE: 1.0
    0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5, 0.51, 0.52, // RPE: 1.5
private val maxReps = 12
fun getRatio(reps: Int, rpe: Double) = table[((rpe * 2).roundToInt() - 1) * maxReps + reps - 1]

Please note I have no idea what are these reps, rpes, etc. This is just an example.

1 Like