fork download
  1. @Mathematica
  2.  
  3. (* Functions *)
  4. sortOdds[lst_]:=Module[{evens,odds,newodds},
  5.  
  6. (* Analysis *)
  7. {evens,odds}=lst//
  8. MapIndexed[List,#]&//
  9. {Select[#,EvenQ[#[[1]]]&],Select[#,OddQ[#[[1]]]&]}&;
  10.  
  11. newodds=odds//
  12. {Map[#[[1]]&,#],Map[#[[2]]&,#]}&//
  13. {Sort[#[[1]]],#[[2]]}&//
  14. MapThread[List,#]&;
  15.  
  16. (* Results *)
  17. {evens,newodds}//
  18. Flatten[#,1]&//
  19. Sort[#,#2[[2,1]]>#1[[2,1]]&]&//
  20. Map[#[[1]]&,#]&
  21. ];
  22.  
  23.  
  24. sortEvensOdds[lst_]:=Module[{evens,odds,newevens,newodds},
  25.  
  26. (* Analysis *)
  27. {evens,odds}=lst//
  28. MapIndexed[List,#]&//
  29. {Select[#,EvenQ[#[[1]]]&],Select[#,OddQ[#[[1]]]&]}&;
  30.  
  31. newevens=evens//
  32. {Map[#[[1]]&,#],Map[#[[2]]&,#]}&//
  33. {Sort[#[[1]]/2,Greater],#[[2]]}&//
  34. MapThread[List,#]&;
  35.  
  36. newodds=odds//
  37. {Map[#[[1]]&,#],Map[#[[2]]&,#]}&//
  38. {Sort[#[[1]]],#[[2]]}&//
  39. MapThread[List,#]&;
  40.  
  41. (* Results *)
  42. {newevens,newodds}//
  43. Flatten[#,1]&//
  44. Sort[#,#2[[2,1]]>#1[[2,1]]&]&//
  45. Map[#[[1]]&,#]&
  46. ];
  47.  
  48.  
  49. (* Results *)
  50. In[1] := sortOdds[{6, 5, 4, 3, 2, 1}]
  51. Out[1] = {6, 1, 4, 3, 2, 5}
  52.  
  53. In[2] := sortEvensOdds[{6, 5, 4, 3, 2, 1}]
  54. Out[2] = {3, 1, 2, 3, 1, 5}
  55.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty