William James
3/21/2016 7:35:00 AM
Given a list of arbitrarily many strings, show how to:
test if they are all lexically equal
test if every string is lexically less than the one after it
(i.e. whether the list is in strict ascending order)
OCaml:
let rec all_neighbors test = function
[] | [_] -> true
| a::b::more -> if test a b then all_neighbors test (b::more) else false ;;
let equal_list = all_neighbors (=) ;;
let ascending_list = all_neighbors (<) ;;
equal_list ["is";"is";"is"];;
===>
true
equal_list ["is";"is";"isn't"];;
===>
false
ascending_list ["aa";"ab";"bb"];;
===>
true
ascending_list ["aa";"ab";"bb";"bb"];;
===>
false
equal_list [9;9;9] ;;
===>
true
--
If confirmed, Garland would be the fourth Jewish justice on the nation's
highest court, which is comprised entirely of Jews and Catholics. The three
current Jewish members of the Supreme Court are Ruth Bader Ginsburg, Elana
Kagan, and Stephen Breyer.
www.jta.org/2016/03/16/news-opinion/united-states/obama-to-name-jewish-federal-judge-to-supreme-court