The Resistance is organizing ships to confront the Empire. R2D2 has a list with the ships. The Resistance will attack in groups of 3 ships, but there could be a group with fewer ships. The droid should get a list with the average ammunition for each group of ships along with the names of the ships in that group. You must code R2D2's AI to print a single list where each element contains the average ammunition and the names of the ships in the corresponding group. This will help organize the defense against the Empire.
Retrieve collection parts
Application
Report a typo
Sample Input 1:
XWing-100 YWing-200 TWing-50 TIEFighter-300Sample Output 1:
[(116, [XWing, YWing, TWing]), (300, [TIEFighter])]Write a program in Kotlin
class Ship(val name: String, val ammunition: Int)
fun main() {
val ships = readln().split(" ")
val shipsList = ships.map { Ship(it.split("-")[0], it.split("-")[1].toInt()) }
// write your code here
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.