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.18 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.17 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.16 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.15 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.14 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.13 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.12 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.11 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.10 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.9 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.8 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.7 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.6 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.5 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.4 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.3 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.2 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.1 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.1.0 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs
trackler-2.2.0.6 tracks/purescript/exercises/binary-search/examples/src/BinarySearch.purs