DNPotapov / Codewars-katas-

0 stars 0 forks source link

Ideal electron distribution (6 kyu) #21

Open DNPotapov opened 1 year ago

DNPotapov commented 1 year ago
import math
def atomic_number(electrons):
    if round(math.sqrt(electrons/2))+1 - math.sqrt(electrons/2) > 0:
        chislo_obolochek = round(math.sqrt(electrons/2))+1
    else:
        chislo_obolochek = round(math.sqrt(electrons/2))
    count = 1
    result = []
    for item in range(chislo_obolochek):
        if electrons > 2*(count**2):
            result.append(2*(count**2))
            electrons = electrons - 2*(count**2)
        else:
            result.append(electrons)
            return result
        count += 1
    return result
DNPotapov commented 1 year ago

You are a khmmadkhm scientist and you decided to play with electron distribution among atom's shells. You know that basic idea of electron distribution is that electrons should fill a shell untill it's holding the maximum number of electrons.

Rules:

Maximum number of electrons in a shell is distributed with a rule of 2n^2 (n being position of a shell). For example, maximum number of electrons in 3rd shield is 2*3^2 = 18. Electrons should fill the lowest level shell first. If the electrons have completely filled the lowest level shell, the other unoccupied electrons will fill the higher level shell and so on. Ex.: atomicNumber(1); should return [1] atomicNumber(10); should return [2, 8] atomicNumber(11); should return [2, 8, 1] atomicNumber(47); should return [2, 8, 18, 19]

DNPotapov commented 1 year ago

https://www.codewars.com/kata/59175441e76dc9f9bc00000f