One of the popular interivew tasks…
You are given a head of a linked list. Its known list contains cycle. The goal is to determine the length of the loop.
Here is straghtforward solution in haskell
{-data Node a instance Eq a => Eq (Node a) next :: Node a -> Node a -} data Phase = TryFindLoop | FindLength deriving (Eq) loopSize :: Eq a => Node a -> Int loopSize a = slowAndFast a a 0 TryFindLoop where slowAndFast :: (Eq node) => Node node -> Node node -> Int -> Phase -> Int slowAndFast slow fast len phase = let nextSlow = next slow nextPreFast = next fast nextFast = next nextPreFast in if (slow == nextPreFast || slow == nextFast) then if (phase == FindLength) then if (nextPreFast == nextFast) then 1 else 2*(len+1) - len - (if slow == nextFast then 0 else 1) else slowAndFast nextSlow nextSlow 0 FindLength else slowAndFast nextSlow nextFast (len + 1) phase Complexity: time o(n), memory o(1)
There is nice leiningen plugin named “Ultra” which can significantly improve your clojure‘s repl interaction.
Main features:
colorized output of data structures (using solarized theme) clear test output better stacktraces java object introspection.
Dont forget about Last-Modified/If-Modified-Since, ETag/If-None-Match headers while retrieving rss feeds. Details can be found in this article.
p.s. fyi header field definitions rfc2616
To run ui test from command line you can use instruments app as described here.
instruments -w deviceID -t defaultTemplateFilePath targetAppName \ -e UIASCRIPT scriptFilePath -e UIARESULTSPATH resultsFolderPath The problem is defaultTemplateFilePath depends on xcode version. Documentation says Automation.tracetemplate is located here :
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate Since xcode 6 Automation.tracetemplate can be found:
/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate
I have just found a couple of nice articles about review of popular javascript frameworks angular and react. Recommend to read it.