/**
 * Given the apparent magnitude of a celestial object and its distance from Earth,
 * calculate its absolute magnitude using the inverse square law of light
 */
import kotlin.math.log10


fun calculateMagnitude(apparentMagnitude: Double, distance: Double): String {

    // Calculate the absolute magnitude
    val absoluteMagnitude = apparentMagnitude - 5 * log10(distance) + 5

    // Check if the absolute magnitude falls into specific ranges
    val classification = when {
        absoluteMagnitude < -3.0 -> "Supergiant"
        absoluteMagnitude in -3.0..-1.0 -> "Bright Giant"
        absoluteMagnitude in -1.0..3.0 -> "Main Sequence"
        absoluteMagnitude in 3.0..6.0 -> "Subgiant"
        absoluteMagnitude in 6.0..15.0 -> "Dwarf"
        else -> "Unknown"
    }

    return classification
}
import kotlin.math.log10

/**
 * Given the apparent magnitude of a celestial object and its distance from Earth,
 * calculate its absolute magnitude using the inverse square law of light
 */
fun calculateMagnitude(apparentMagnitude: Double, distance: Double): String {
import kotlin.math.log10

/**
 * Given the apparent magnitude of a celestial object and its distance from Earth,
 * calculate its absolute magnitude using the inverse square law of light
 */
fun calculateMagnitude(apparentMagnitude: Double, distance: Double): String {

    // Calculate the absolute magnitude
    val absoluteMagnitude = apparentMagnitude - 5 * log10(distance) + 5

    // Check if the absolute magnitude falls into specific ranges
    val classification = when {
        absoluteMagnitude < -3.0 -> "Supergiant"
        absoluteMagnitude in -3.0..-1.0 -> "Bright Giant"
        absoluteMagnitude in -1.0..3.0 -> "Main Sequence"
        absoluteMagnitude in 3.0..6.0 -> "Subgiant"
        absoluteMagnitude in 6.0..15.0 -> "Dwarf"
        else -> "Unknown"
    }

    return classification
}