Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.60 KB | None | 0 0
  1. package dero
  2.  
  3. import "strconv"
  4.  
  5. func ElectronicConfiguration(atomic_number int) string {
  6.    
  7.     solution := ""
  8.    
  9.     for level := 0 ; level < 7 ; level++ {
  10.  
  11.         //s orbital
  12.         if atomic_number > 0 && level != 0 {
  13.             if atomic_number >= 2 {
  14.                 solution += strconv.Itoa(level+1)
  15.                 solution += "p2 "
  16.                 atomic_number -= 2
  17.             } else {
  18.                 atomic_number -= 2
  19.                 solution += strconv.Itoa(level+1)
  20.                 solution += "s"
  21.                 solution += strconv.Itoa(2 + atomic_number)
  22.                 solution += " "
  23.                 break
  24.             }
  25.         }
  26.  
  27.         //p orbital
  28.         if atomic_number > 0 && level != 0 {
  29.             if atomic_number >= 6 {
  30.                 solution += strconv.Itoa(level+1)
  31.                 solution += "p6 "
  32.                 atomic_number -= 6
  33.             } else {
  34.                 atomic_number -= 6
  35.                 solution += strconv.Itoa(level+1)
  36.                 solution += "p"
  37.                 solution += strconv.Itoa(6 + atomic_number)
  38.                 solution += " "
  39.                 break
  40.             }
  41.         }
  42.  
  43.         //d orbital
  44.         if  level >= 2 && level <= 5 {
  45.             if atomic_number >= 10 {
  46.                 solution += strconv.Itoa(level+1)
  47.                 solution += "d10 "
  48.                 atomic_number -= 10
  49.             } else {
  50.                 atomic_number -= 10
  51.                 solution += strconv.Itoa(level+1)
  52.                 solution += "d"
  53.                 solution += strconv.Itoa(10 + atomic_number)
  54.                 solution += " "
  55.                 break
  56.             }
  57.         }
  58.  
  59.         //f orbital
  60.         if  level == 3 && level == 4 {
  61.             if atomic_number >= 14 {
  62.                 solution += strconv.Itoa(level+1)
  63.                 solution += "f14 "
  64.                 atomic_number -= 10
  65.             } else {
  66.                 atomic_number -= 14
  67.                 solution += strconv.Itoa(level+1)
  68.                 solution += "f"
  69.                 solution += strconv.Itoa(14 + atomic_number)
  70.                 solution += " "
  71.                 break
  72.             }
  73.         }
  74.        
  75.     }
  76.  
  77.     return solution
  78.    
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement