Skip to content

Instantly share code, notes, and snippets.

@pulcheri
Created June 21, 2016 08:10
Show Gist options
  • Save pulcheri/ecfb17be6be0a97ecb6d6a9366c7851a to your computer and use it in GitHub Desktop.
Save pulcheri/ecfb17be6be0a97ecb6d6a9366c7851a to your computer and use it in GitHub Desktop.
-- solution to Haskell kata
-- https://www.codewars.com/kumite/new?group_id=5463fbb024b6c287a0000016&review_id=5463fbb024b6c287a0000014
module IPv4 where
import Data.List (intercalate)
import Data.Word (Word32)
import Data.Int (Int32)
import Data.Bits ((.&.), shiftR)
type IPString = String
int32ToIP :: Int32 -> IPString
int32ToIP x = intercalate "." $ map (\n -> show $ w `shiftR` n .&. 0xff) [24,16..0]
where w = (fromIntegral x) :: Word32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment