podsekwencje długości n od wydajności listy
Zaimplementowałem wersję tej odpowiedzihttps://stackoverflow.com/a/9920425/1261166 (Nie wiem, co zamierzała osoba odpowiadająca)
sublistofsize 0 _ = [[]]
sublistofsize _ [] = []
sublistofsize n (x : xs) = sublistsThatStartWithX ++ sublistsThatDontStartWithX
where sublistsThatStartWithX = map (x:) $ sublistofsize (n-1) xs
sublistsThatDontStartWithX = sublistofsize n xs
nie jestem pewien, co to jestsublistsThatStartWithX = map (x:) $ sublistofsize (n-1) xs
Zakładam, że mapa (x :) daje mądry problem, ale nie wiem, jak go rozwiązać. Zrobiłem profilowanieprint $ length $ sublistofsize 5 $ primesToTakeFrom 50
COST CENTRE MODULE no. entries %time %alloc %time %alloc
sublistofsize Main 112 4739871 46.9 39.9 96.9 100.0
sublistofsize.sublistsThatDontStartWithX Main 124 2369935 2.2 0.0 2.2 0.0
sublistofsize.sublistsThatStartWithX Main 116 2369935 47.8 60.1 47.8 60.1
Czy wdrożyłem go w dobry sposób? Czy są szybsze sposoby na to?