public State Apply(List <TuringTape> tapes) { var pattern = string.Join(string.Empty, Pattern.Replace('*', '.').ToList().ConvertAll(c => "(" + c + ")")); var replace = string.Empty; var index = 1; foreach (var c in Replacement.ToCharArray()) { if (c == '*') { replace += "$" + index + ","; index++; continue; } index++; replace += c + ","; } var newKonf = Regex.Replace(new string(tapes.ConvertAll(t => t.Read()).ToArray()), pattern, replace); newKonf = newKonf.Replace(",", ""); for (var i = 0; i < tapes.Count; i++) { switch (Movement[i]) { case HeadMovement.Left: tapes[i].WriteLeft(newKonf[i]); break; case HeadMovement.Right: tapes[i].WriteRight(newKonf[i]); break; case HeadMovement.Stay: tapes[i].WriteStay(newKonf[i]); break; } } return(ToState); }