Sha256: bb51c774b47b47656ea35c00d94435585ce963feb76dd13594ad752cdb33a1bc

Contents?: true

Size: 490 Bytes

Versions: 253

Compression:

Stored size: 490 Bytes

Contents

module BinarySearch
  ( find
  ) where

import Prelude
import Data.Array (length, (!!))
import Data.Maybe (Maybe(Just, Nothing))

find :: Int -> Array Int -> Maybe Int
find i a = go 0 (length a - 1)
  where go l h | l > h = Nothing
        go l h =
          let m = l + (h - l) / 2
          in case a !! m of
               Nothing -> Nothing
               Just j | j == i    -> Just m
                      | j < i     -> go (m + 1) h
                      | otherwise -> go l (m - 1)

Version data entries

253 entries across 253 versions & 1 rubygems

Version Path
trackler-2.2.1.38 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.37 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.36 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.35 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.34 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.33 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.32 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.31 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.30 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.29 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.28 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.27 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.26 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.25 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.24 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.23 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.22 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.21 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.20 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.19 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs