Skip to main content
deleted 53 characters in body
Source Link
Dr. belisarius
  • 116.8k
  • 13
  • 208
  • 466
f[1, _] = 1; f[n_, l1_] := If[l1[[n]] == l1[[n - 1]], f[n - 1]1, l1], n] f[#, Sort[-l]] & /@ Range@Length@l (* {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 14, 15, 16, 17, 17, 19, 20}*) 

trying if MapIndexed[] is any better. stay tuned.

f[1, _] = 1; f[n_, l1_] := If[l1[[n]] == l1[[n - 1]], f[n - 1], n] f[#, Sort[-l]] & /@ Range@Length@l (* {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 14, 15, 16, 17, 17, 19, 20}*) 

trying if MapIndexed[] is any better. stay tuned.

f[1, _] = 1; f[n_, l1_] := If[l1[[n]] == l1[[n - 1]], f[n - 1, l1], n] f[#, Sort[-l]] & /@ Range@Length@l (* {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 14, 15, 16, 17, 17, 19, 20}*) 
Post Undeleted by Dr. belisarius
added 82 characters in body
Source Link
Dr. belisarius
  • 116.8k
  • 13
  • 208
  • 466
Ordering[lf[1, All_] = 1; f[n_, Lessl1_] @@:= #If[l1[[n]] &]== l1[[n - 1]], f[n - 1], n] f[#, Sort[-l]] & /@ Range@Length@l  (* {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1312, 14, 15, 16, 17, 1817, 19, 20}*) 

trying if MapIndexed[] is any better. stay tuned.

Ordering[l, All, Less @@ # &] (* {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}*) 
f[1, _] = 1; f[n_, l1_] := If[l1[[n]] == l1[[n - 1]], f[n - 1], n] f[#, Sort[-l]] & /@ Range@Length@l  (* {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 14, 15, 16, 17, 17, 19, 20}*) 

trying if MapIndexed[] is any better. stay tuned.

Post Deleted by Dr. belisarius
Source Link
Dr. belisarius
  • 116.8k
  • 13
  • 208
  • 466

Ordering[l, All, Less @@ # &] (* {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}*)