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


Groups > comp.lang.forth > #54008 > unrolled thread

Rosetta: Compare a list of strings

Started by"Robert L." <No_spamming@noWhere_7073.org>
First post2017-01-14 18:35 +0000
Last post2017-01-14 18:35 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.forth


Contents

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

#54008 — Rosetta: Compare a list of strings

From"Robert L." <No_spamming@noWhere_7073.org>
Date2017-01-14 18:35 +0000
SubjectRosetta: Compare a list of strings
Message-ID<o5dr21$qtp$1@gioia.aioe.org>
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/

[toc] | [standalone]


Back to top | Article view | comp.lang.forth


csiph-web