https://kotlinlang.org logo
#android
Title
# android
a

Andrew Ambia

02/25/2020, 5:54 AM
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

Nikola Milovic

02/25/2020, 7:58 AM
You have to ask a question. What exactly are you having issues with?
r

Raul Tunduc

02/25/2020, 8:09 AM
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

satyan

02/25/2020, 8:19 AM
I guess now instead of finding solutions to simple problems we should directly ask the answer 😉
😂 2
a

Andrew Ambia

02/25/2020, 9:23 AM
🤣
2 Views