C# /Linq Yet another Brain Teaser -
Friends, there is still another scenario to solve, I am working without implementing Linq. But I hope that if you share your code in linux, then I have a great chance to learn Linq.
L - Lover
A <->
/ P>
M - (husband)
e - enemy
s - sister
Description of problem:
Two names will be given (male, female). We have to exclude common papers from both names, then we will have to calculate the number of remaining letters after killing common characters with both names. In the end, we have to repeat the stem flames and by the time we do not reach the letters alone, we have to extract the letters in the flames. The remaining single character shows the relation I will explain the process in more detail in the following examples. (Ignore case and spaces).
Example:
Step 1
Men: Albert Women: The letter "A", "E", "B" is common in both names. (Strike those letters with both strings, even in two "A" names in the "Hernna" you are allowed to kill the string "a" both in the name "Albert" Only the single "A" is).
The resulting string male: $ l $$ rt woman: h $$$ rna
Step 2:
Calculate the remaining letters from both stars.
Count: 7
Step 3:
Let us use the string "FLAMES" To repeat the following method,
the fire ear 1 2 3 4 5 6 7 (here count 7 ends F at the end, hence the F) strike
< P> You will get $ lames
(start your countdown from the next letter immediately (it should not be a hit already) If it The last letter ("S") is, then start with the first letter "F" if the 'F' initiative Not only has been killed.
$ lames (igonre) 1 2 3 4 5 (ignored) 6 7
Never counted Even the hit letter is not considered.
$ 4 $ ignorance of MES 1 2 3 ignore 4 6 7
"S" will be hit.
ignore $ $ $ $ 1 ignore 3 3 4 ignore 5 6 7
"L" hit Ignore
$ $ $ ME $ 2 2 Ignore 2 6 7
In the end, "M" will be killed, after which only the remaining If the letter is "e" then Albert is the enemy to Herbana.
Update: The Letter "R" is also common in both names. I forgot to kill him Either way this process has been explained. Thanks for pointing it out.
step 1 and step 2
var firstLookup = firstName.ToLookup (C => c.ToLower ()); Var Second Lookup = Second Name To lookup (c => c.ToLower ()); Var allChars = First Lookup. Union (second lookup.); Int count = (In the allchars, before c, first count = firstLookup [c]. Count () secondCount = secondLookup [c] Let's count () select firstCount & lt; secondCount? SecondCount - firstCount: firstCount - secondCount) .sum ()
Step 3 (Unchester)
list & lt; Char & gt; Word = "flames". Ollist (); While (word count & gt; 1) {int wordCount = word.Count; Int remove = (count-1)% wordCount; Word = word Selection ((C, I) => New {c, i = i == Remove? 0: i & lt; Remove? I + wordCount + 1: i}). Orderbay (x = & gt; xi) Select (x = & gt; xc). Skip (1) .Olist (); } Four results = words. Single ();
Comments
Post a Comment