Skip to content

Instantly share code, notes, and snippets.

@kuribas
Last active June 25, 2018 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuribas/cd0f725b9de6ff909326ad2856441943 to your computer and use it in GitHub Desktop.
Save kuribas/cd0f725b9de6ff909326ad2856441943 to your computer and use it in GitHub Desktop.
all numbers in a string
import Data.List
import Data.Function
import Text.Read
import Data.Maybe
import Data.Char
all_numbers :: String -> [Int]
all_numbers =
mapMaybe (readMaybe :: String -> Maybe Int) .
groupBy ((==) `on` isDigit)
(defun all-nums (s)
(mapcar #'parse-integer
(split-by s (complement #'digit-char-p))))
(defun split-by (c f &key (start 0))
(let* ((start2 (position-if-not f c :start start))
(end (and start2 (position-if f c :start start2))))
(and start2
(cons (subseq c start2 end)
(and end
(split-by c f :start end))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment