Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Punnet Square Generator
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Rextester { public class Program { private static char[] firstAlleles1; private static char[] secondAlleles1; private static char[] firstAlleles2; private static char[] secondAlleles2; public static void Main(string[] args) { //Input is already entered. //Console.WriteLine("Genotype combination 1:"); string genotypeCollection1 = Console.ReadLine(); //Input is already entered. //Console.WriteLine("Genotype combination 2:"); string genotypeCollection2 = Console.ReadLine(); Console.Write("\n\n"); int genotypeCount = genotypeCollection1.Length / 2; string[] genotypes1 = new string[genotypeCount]; string[] genotypes2 = new string[genotypeCount]; firstAlleles1 = new char[genotypeCount]; secondAlleles1 = new char[genotypeCount]; firstAlleles2 = new char[genotypeCount]; secondAlleles2 = new char[genotypeCount]; for (int i = 0; i < genotypeCount; i++) { genotypes1[i] = genotypeCollection1.Substring(i * 2, 2); genotypes2[i] = genotypeCollection2.Substring(i * 2, 2); } for (int i = 0; i < genotypeCount; i++) { firstAlleles1[i] = genotypes1[i][0]; secondAlleles1[i] = genotypes1[i][1]; firstAlleles2[i] = genotypes2[i][0]; secondAlleles2[i] = genotypes2[i][1]; } string[] combinations1 = getCombinations(new string[] { string.Empty }, firstAlleles1.Length - 1, firstAlleles1, secondAlleles1); string[] combinations2 = getCombinations(new string[] { string.Empty }, firstAlleles2.Length - 1, firstAlleles2, secondAlleles2); string[,] results = new string[combinations1.Length, combinations2.Length]; for (int i = 0; i < combinations1.Length; i++) { for (int k = 0; k < combinations2.Length; k++) { string crossResult = string.Empty; for (int m = 0; m < genotypeCount; m++) { if ((int)combinations1[k][m] <= (int)combinations2[i][m]) { crossResult += combinations1[k][m].ToString() + combinations2[i][m].ToString(); } else { crossResult += combinations2[i][m].ToString() + combinations1[k][m].ToString(); } } results[i, k] = crossResult; } } Console.WriteLine("Punnet square of possible results of a(n) {0} x {1} cross:\n\n", genotypeCollection1, genotypeCollection2); Console.Write(new string(' ', genotypeCount + 1)); foreach (string alleleCombination in combinations1) { Console.Write(alleleCombination + new string(' ', genotypeCount + 1)); } for (int i = 0; i < combinations2.Length; i++) { Console.Write("\n" + combinations2[i] + ' '); for (int k = 0; k < combinations1.Length; k++) { Console.Write(results[i, k] + ' '); } } //Only for running on a computer //Console.ReadKey(true); } private static string[] getCombinations(string[] currentArray, int allelePosition, char[] firstAlleles, char[] secondAlleles) { if (allelePosition >= 0) { string[] newCombinations = new string[currentArray.Length * 2]; for (int i = 0; i < currentArray.Length; i++) { newCombinations[i] = firstAlleles[allelePosition] + currentArray[i]; newCombinations[i + currentArray.Length] = secondAlleles[allelePosition] + currentArray[i]; } return getCombinations(newCombinations, allelePosition - 1, firstAlleles, secondAlleles); } else { return currentArray; } } } }
run
|
edit
|
history
|
help
0
linq subquery z grupowaniem po dwóch polach
test
Demo
Problem: on_off
Truncate String by Byte
Check if string is palindrome
Free cash app money
RGEFCSZX
Problem: rstring
Write a program to sort given array using bubble sort.