Talk:Find the missing permutation: Difference between revisions

Line 80:
: I would prefer the universe of symbols to be undefined, and for the code to be generic. You might as well think of the data being 0x41, 0x42, 0x43 and 0x44 integer values, 65.0f, 66.0f, 67.0f, 68.0f, or even Rosemary, Paprika, Sage, Thyme; My intent was to consider and compare the permutations of symbols, not <em>necessarily</em> the exact symbols used. It would probably be best to avoid hardcoded assumptions about the universe of symbols --[[User:Short Circuit|Michael Mol]] 05:14, 28 December 2009 (UTC)
: You could also exhibit both solutions, stating in the adjoining text that one is more general than the other. Like that you'd illustrate a point about the J language as well as providing the solution in various levels of elegance. –[[User:Dkf|Donal Fellows]] 13:46, 28 December 2009 (UTC)
 
== Fortran example incorrect? ==
 
The fortran example was marked incorrect. Indeed, the result is wrong when compiled with gfortran. However, g95 gives the correct result. I believe this to be a bug in gfortran. I narrowed down the problem in the following test program:
<lang fortran>program missing_permutation_test
 
implicit none
character (4), dimension (23), parameter :: list = &
& (/'ABCD', 'CABD', 'ACDB', 'DACB', 'BCDA', 'ACBD', 'ADCB', 'CDAB', &
& 'DABC', 'BCAD', 'CADB', 'CDBA', 'CBAD', 'ABDC', 'ADBC', 'BDCA', &
& 'DCBA', 'BACD', 'BADC', 'BDAC', 'CBDA', 'DBCA', 'DCAB'/)
integer :: i
 
write (*, *) list (:) (1 : 1)
write (*, *) list (1) (1 : 1)
write (*, *) list (:) (1 : 1) == list (1) (1 : 1)
i = 1
write (*, *) list (1) (i : i)
write (*, *) list (:) (1 : 1) == list (1) (i : i)
 
end program missing_permutation_test</lang>
The output of this program when compiled with gfortran is:
<lang> ACADBAACDBCCCAABDBBBCDD
A
T F T F F T T F F F F F F T T F F F F F F F F
A
F F F F F F F F F F F F F F F F F F F F F F F</lang>
It seems to me that comparing <code>list (:) (1 : 1)</code> to either <code>list (1) (1 : 1)</code> or <code>list (1) (i : i)</code> when <code>i = 1</code> should give the same result. However, I am not 100% certain about my claim.
When compiled with g95 we get:
<lang> ACADBAACDBCCCAABDBBBCDD
A
T F T F F T T F F F F F F T T F F F F F F F F
A
T F T F F T T F F F F F F T T F F F F F F F F</lang>
For now, I will leave the "incorrect" label, until we find a definite answer.
Anonymous user