Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Halp with regex

Name: Anonymous 2008-08-04 3:54

Hey /prog/,
Lets say I have a file with many lines,
each line consists of a very very long random number (string)
Is it possible to write a regular expression to find the longest series of repeated numbers shared by all lines
aka
120123456789948761238746102347106416239847113958719385
217490812741234567890182472103571938547019112413956138756183756183756817356817356
192346112345678978932671658917612746183724681734682173649187245

(I bolded it for readability)

tldr;
how does I finded biggest repeaded series of numbers contained in all lines? (using regex or something one-line'ish)

Name: Anonymous 2008-08-04 15:46

Here's an OFIOC slow as fuck solution to your problem:

import Control.Monad.Instances
import Data.Ord
import Monad
import List

main =
   do numbers <- fmap lines getContents
      putStrLn
         $ map (head numbers !!) $ map head $ maximumBy (comparing length)
         $ groupSequences $ sortBy (comparing (zipWith (-) =<< tail))
         $ map (map fst) $ filter (\l -> all ((snd (head l) ==) . snd) l)
         $ sequence $ map (zip [0..]) numbers
   where
      groupSequences matchList =
         uncurry (:)
            $ mapAccumL ((.) (uncurry $ flip (,)) . flip splitAt) matchList
            $ liftM2 (:) ((+1) . head) (zipWith (-) =<< tail)
            $ findIndices (uncurry $ (/=) . map (subtract 1))
            $ (zip =<< tail) $ matchList

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List