Greetings guys, I'm having a challenge, I have a n...
# android
a
Greetings guys, I'm having a challenge, I have a number 15, and need to get an array of integers out of it, where, the last index in that array should be a 1, first index should be a square of a number, and the numbers in between the first and the last index can either be a square and a 1 or a number and 1 example 15 = {3^2, 2^2, 1, 1}; 8 = {2^2, 2, 1, 1}
👎 1
n
You have to ask a question. What exactly are you having issues with?
r
Copy code
val array = mutableListOf<Int>()
var number = 15 // the number you need to decompose
while (number != 0) {
  var index = 1
  while (index * index <= number) {
    index = index + 1
  }
  index = index - 1
  number = number - index * index
  array.add(index)
}
return array;
😬 3
it works, at least
s
I guess now instead of finding solutions to simple problems we should directly ask the answer 😉
😂 2
a
🤣