Jump to content

Talk:Find the missing permutation: Difference between revisions

(→‎Fortran example incorrect?: no, some gfortran versions have bug)
(→‎Simple solution: new section)
Line 199:
 
:: I also suspect that the difference is that when we are using constant number, the slicing is done at compile time, while when there's a variable that must be evaluated, the slicing is done at runtime and problems arises for the "immutable" nature of the parameter. So as already said a work-around is to remove the parameter attribute...! —[[User:ShinTakezou|ShinTakezou]] 19:45, 27 May 2010 (UTC)
 
== Simple solution ==
 
Since there's exactly one permutation missing, there's actually a very simple solution which probably beats all solutions given so far in execution time (unless I've overlooked something, all solutions try to generate all permutations and find them in the list):
* For each position, count how often each letter appears.
* The one which appears one time less than the others is at this position in the missing permutation.
In the given example:
*Position 1: A:6, B:6, C:6, '''D:5'''
*Position 2: A:6, '''B:5''', C:6, D:6
*Position 3: '''A:5''', B:6, C:6, D:6
*Position 4: A:6, B:6, '''C:5''', D:6
Therefore the missing permutation is DBAC. --[[User:Ce|Ce]] 19:49, 16 August 2010 (UTC)
973

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.