Advertisement
Redxone

[ComputerCraft] Electron configurator

May 24th, 2016
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.54 KB | None | 0 0
  1. --]] Atom assemblr made by: Lewisk3 (Redxone)
  2. --]] order of ops
  3. --:KLMNOP = 2,8,18,32,32...
  4. --= 1s,                    
  5. --= 2s,2p,     
  6. --= 3s,3p,     
  7. --= 4s,3d,4p,  
  8. --= 5s,4d,5p,
  9. --= 6s,4f,5d,6p
  10. --= 7s,5f,6d,7p
  11. --= 8s
  12. --=_________________________________________=--
  13.  
  14. local suborbits = {
  15.     ['s'] = 2,
  16.     ['p'] = 6,
  17.     ['d'] = 10,
  18.     ['f'] = 14,
  19.     ['g'] = 18,
  20.     ['h'] = 22,
  21.     ['i'] = 26,
  22.     ['j'] = 30,
  23.     ['k'] = 34,
  24. }
  25. local shells = {
  26.     0,
  27.     0,
  28.     0,
  29.     0,
  30.     0,
  31.     0,
  32.     0,
  33.     0,
  34.     0,
  35. }
  36. local fillorder = {
  37.     {1,1},
  38.     {2,1},
  39.     {2,2},
  40.     {3,1},
  41.     {3,2},
  42.     {4,1},
  43.     {3,3},
  44.     {4,2},
  45.     {5,1},
  46.     {4,3},
  47.     {5,2},
  48.     {6,1},
  49.     {4,4},
  50.     {5,3},
  51.     {6,2},
  52.     {7,1},
  53.     {5,4},
  54.     {6,3},
  55.     {7,2},
  56.     {8,1},
  57.     {5,5},
  58.     {6,4},
  59.     {7,3},
  60.     {8,2},
  61.     {9,1},
  62. }
  63. local fills = {
  64.     {'s'}, -- K
  65.     {'s','p'}, -- L
  66.     {'s','p','d'}, -- M
  67.     {'s','p','d','f'}, -- N
  68.     {'s','p','d','f','g'}, -- O
  69.     {'s','p','d','f','g','h'}, -- P
  70.     {'s','p','d','f','g','h','i'}, -- Q
  71.     {'s','p','d','f','g','h','i','j'}, -- R
  72.     {'s','p','d','f','g','h','i','j','k'}, -- S
  73. }
  74. local e = 1
  75. -- minimum valence electrons
  76. local mnval = 1
  77. -- maximum valence electrons
  78. local mval = 8
  79. -- Get sub orbit ammount.
  80. function getsoa(soch)
  81.     return suborbits[soch]
  82. end
  83. -- Get shell orbit ammount
  84. function getshoa(so)
  85.     local acc = 0
  86.     for i = 1, #so do
  87.         acc = acc + getsoa(so[i])
  88.     end
  89.     return acc
  90. end
  91. -- Get max electrons from shell oribit table
  92. function getmaxe(atm)
  93.     local tacc = 0
  94.     for i = 1, #atm do
  95.         tacc = tacc + getshoa(atm[i])
  96.     end
  97.     return tacc
  98. end
  99. -- shell print
  100. function shprint(sh)
  101.     for i = 1, #sh do
  102.         if(sh[i] > 0)then print(sh[i]) end
  103.     end
  104. end
  105. -- gets needed shell ammount to make atom
  106. function getnshells(em)
  107.     local sizes = {2,8,32,50,72}
  108.     local fls = 0
  109.     for i = 1, #sizes do
  110.         fls = fls + sizes[i]
  111.         if(fls >= em)then
  112.             return i+1
  113.         end
  114.     end
  115. end
  116. -- distribute electrons
  117. local targs = { ... }
  118. if(#targs ~= 1)then error("Ussage: matom <electrons>") end
  119. -- convert to number
  120. targs[1] = tonumber(targs[1])
  121. if(targs[1] > 570 or targs[1] < 1)then error("Invalid electrons maximum is 570, minimum is 1. ") end
  122. -- give our electron count the provided electrons.
  123. local e = targs[1]
  124. local soa = 0
  125. local mshls = #fillorder
  126. for s = 1, #fillorder do
  127.     if(e == 0)then break end
  128.     local shl = fillorder[s][1]
  129.     local orb = fillorder[s][2]
  130.     if(shl <= mshls)then
  131.         local soa = getsoa(fills[shl][orb])
  132.         if(e >= soa)then
  133.             shells[shl] = shells[shl] + soa
  134.             e = e - soa
  135.         elseif(e <= 8)then
  136.             shells[shl] = shells[shl] + e
  137.             e = 0
  138.             break
  139.         end
  140.     else
  141.         break
  142.     end
  143. end
  144.  
  145. shprint(shells)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement