Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: Counting chars (was Simple things should be simple to do ?)

From: jeff:rebol at: 16-Nov-2000 10:19

Here's another two approaches that are fun: REBOL [] count: func [x /local count cur n1 n2][ sort x count: copy [] cur: first x n1: 1 forall x [ if any [all [tail? next x n1: n1 - 1] x/1 <> cur] [ repend count [cur (n2: index? x) - n1] n1: n2 cur: x/1 ] ] count ] str: "sdfsdfsdfsdfsdfsdfsdfsdf" probe count str count2: func [x /local count rule schar wchar][ rule: copy count: copy [] foreach char unique x [ do reduce [schar: to-set-word form char 0] wchar: to-word :schar append rule compose [(char) (to-paren reduce [:schar wchar '+ 1]) | ] repend count [char wchar] ] remove back tail rule parse x [some rule] reduce count ] probe count2 str