# This code is written in the Julia language # Function I wrote to Knuth shuffle an array! function shuffle(x, length) i = 1 while i < length j = i + rand(0:length - i) temp = x[i] x[i] = x[j] x[j] = temp i += 1 end return x end # x = [1,2,3,4,5,6,7,8,9,10] # for the other version x = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] l = length(x) trials = 100000000 function hasSorD(x, length) i = 1 while i <= length if x[i] == i return true end j = x[i] if x[j] == i return true end i += 1 end return false end count = 0 i = 0 while i < trials x = shuffle(x, l) if (!hasSorD(x, l)) count += 1 end i += 1 end print(count/trials)