Last active
December 2, 2017 14:03
-
-
Save mbloms/b76940a37034dc9ccbc85c078faa32d9 to your computer and use it in GitHub Desktop.
En kvällskluring; implementera en funktion som gör följande: [2 3 5 10] -> [150 100 60 30] (varje tal i outputen är produkten av hela inputen, bortsett från talet på samma index) Naiv lösning är trivial, men om lösningen INTE får vara O(n^2) och INTE får använda division? Hur smart kan man göra den?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
funkyProduct lst = zipWith | |
(*) | |
(scanl (*) 1 lst) | |
(scanr (*) 1 $ (tail lst)) | |
--Prelude> funkyProduct [2,3,5,10] | |
--[150,100,60,30] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment