Advertisement
LDDestroier

cc genetic thing test

May 1st, 2017
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.55 KB | None | 0 0
  1. --pastebin get 5Www9BPT gen
  2. term.clear()
  3. local prompt = function(txt)
  4.     term.setTextColor(colors.yellow)
  5.     write(txt..": ")
  6.     term.setTextColor(colors.white)
  7.     return read()
  8. end
  9. while true do
  10. local g1 = prompt("genotype 1"):sub(1,2)
  11. local g2 = prompt("genotype 2"):sub(1,2)
  12. term.clear()
  13.  
  14. local grid = {
  15.     {g1:sub(1,1)..g2:sub(1,1),g1:sub(2,2)..g2:sub(1,1)},
  16.     {g1:sub(1,1)..g2:sub(2,2),g1:sub(2,2)..g2:sub(2,2)},
  17. }
  18.  
  19. local displayGrid = function(g)
  20.     print("     "..g1:sub(1,1).."    "..g1:sub(2,2).."  ")
  21.     print("")
  22.     print("   ###########")
  23.     print("   #    #    #")
  24.     print(" "..g2:sub(1,1).." # "..g[1][1].." # "..g[1][2].." #")
  25.     print("   #    #    #")
  26.     print("   ###########")
  27.     print("   #    #    #")
  28.     print(" "..g2:sub(2,2).." # "..g[2][1].." # "..g[2][2].." #")
  29.     print("   #    #    #")
  30.     print("   ###########")
  31.     local domAmnt = 0
  32.     local XX,Xx,xx = 0, 0, 0
  33.     for a = 1, #g do
  34.         for b = 1, #g do
  35.             if g[a][b]:find(g[a][b]:sub(1,1):upper()) then
  36.                 domAmnt = domAmnt + 1
  37.             end
  38.             if g[a][b] == (g[a][b]:sub(1,1):lower())..(g[a][b]:sub(1,1):lower()) then
  39.                 xx = xx + 1
  40.             elseif g[a][b] == (g[a][b]:sub(1,1):upper())..(g[a][b]:sub(1,1):lower()) then
  41.                 Xx = Xx + 1
  42.             elseif g[a][b] == (g[a][b]:sub(1,1):lower())..(g[a][b]:sub(1,1):upper()) then
  43.                 Xx = Xx + 1
  44.             elseif g[a][b] == (g[a][b]:sub(1,1):upper())..(g[a][b]:sub(1,1):upper()) then
  45.                 XX = XX + 1
  46.             end
  47.         end
  48.     end
  49.     print("Pheno Ratio: "..domAmnt..":"..(4-domAmnt).." ("..(domAmnt/4)..")")
  50.     print("Geno. Ratio: "..XX..":"..Xx..":"..xx)
  51.     print("")
  52. end
  53.  
  54. displayGrid(grid)
  55. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement