Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #54008

Rosetta: Compare a list of strings

From "Robert L." <No_spamming@noWhere_7073.org>
Newsgroups comp.lang.forth
Subject Rosetta: Compare a list of strings
Date 2017-01-14 18:35 +0000
Organization Aioe.org NNTP Server
Message-ID <o5dr21$qtp$1@gioia.aioe.org> (permalink)

Show all headers | View raw


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)

Ruby:

def all_equal( array )
  array.uniq.size < 2
end

all_equal []
    ==>true
all_equal ["i"]
    ==>true
all_equal ["i","i","i"]
    ==>true
all_equal ["i","i","i","o"]
    ==>false

def ascending( array )
  array.each_cons(2).all?{|a,b| a<b}
end

ascending( [] )
    ==>true
ascending( ['a'] )
    ==>true
ascending( ['a','a'] )
    ==>false
ascending( ['a',"b"] )
    ==>true
ascending( ['a',"b","c"] )
    ==>true
ascending( ['a',"b","c","c"] )
    ==>false
ascending( ['a',"b","c","d"] )
    ==>true
ascending( ['a',"b","c","d","d"] )
    ==>false

In Forth?

-- 
The major media are controlled and run by Jews. They want White people dead,
replaced, mixed, and immigrated and migrated and refugeed out of existence.
Telling the truth about racially-motivated attacks on Whites by Blacks does not
fit their agenda.
nationalvanguard.org/2016/10/how-can-we-stop-the-mystery-attacks/

Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread


Thread

Rosetta: Compare a list of strings "Robert L." <No_spamming@noWhere_7073.org> - 2017-01-14 18:35 +0000

csiph-web