Erlang.删除列表的第一季度,以及以相反顺序排列的第三个元素



set列表的长度为4个。这是我的变体 ->

-import(lists, [filter/2, member/2, split/2, reverse/1]).
foo(L) when (length(L) rem 4) =/= 0 -> "Your list in non-multiple to 4!!!";
foo(L) ->   {Sub1, Sub2} = split(length(L) div 2, L),
            { _ ,Second} = split(length(Sub1) div 2, Sub1),
            {Third,Fourth} = split(length(Sub2) div 2, Sub2),
             Second ++ reverse(Third) ++ Fourth.

可能是某人有更好的想法。谢谢!

我有非常有效的解决方案:

2> timer:tc(fun(L) -> fun() -> F(L) end end(lists:seq(1, 1000000))).
{22770,
 [250001,250002,250003,250004,250005,250006,250007,250008,
  250009,250010,250011,250012,250013,250014,250015,250016,
  250017,250018,250019,250020,250021,250022,250023,250024,
  250025,250026,250027|...]}
3> timer:tc(fun(L) -> fun() -> F(L) end end(lists:seq(1, 32))).                                                                                                                                                                                                       
{79,                                                                                                                                                                                                                                                                   
 [9,10,11,12,13,14,15,16,24,23,22,21,20,19,18,17,25,26,27,28,                                                                                                                                                                                                          
  29,30,31,32]}

您要为F/1定义付多少钱?

最新更新