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

sort/scramble

 [1/5] from: hallvard:ystad:oops-as:no at: 4-Jan-2004 0:54


Hi I need a function that will make sure a block is _not_ sorted. ex:
>> sort/scramble [ 1 2 7 7 7 4 9 f 3 h h h h 3e 54 5 4 k] >> [ 1 h 2 7 h 4 9 f 3 h 7 3e 54 7 h 5 4 k]
Is this feasible without a lot of work? Would anyone happen to have such a function in a drawer somewhere? Thanks, HY

 [2/5] from: antonr:iinet:au at: 4-Jan-2004 11:59


Try this on: sort/compare blk func [a b][(random 2) - 1] Anton.

 [3/5] from: joel:neely:fedex at: 3-Jan-2004 20:06


Hi, Hallvard, Hallvard Ystad wrote:
> Hi > > I need a function that will make sure a block is _not_ sorted. >
How about this:
>> random [0 1 2 3 4 5 6 7 8 9]
== [8 9 3 4 2 1 7 6 0 5] Of course, there's a 1 in 3628800 chance that a random arrangement of ten values will actually be in order! ;-) If you really mean *NOT* sorted (and your values are distinct), but don't care about randomness, then reverse sort foo will make sure that FOO is _not_ sorted in ascending order. Can you provide a little more detail on your requirements? -jn-

 [4/5] from: carl::cybercraft::co::nz at: 24-Jan-2004 11:42


On 04-Jan-04, Hallvard Ystad wrote:
> Hi > I need a function that will make sure a block is _not_ sorted. > ex: >>> sort/scramble [ 1 2 7 7 7 4 9 f 3 h h h h 3e 54 5 4 k] >>> [ 1 h 2 7 h 4 9 f 3 h 7 3e 54 7 h 5 4 k]
Is that a real, in-use block? As I get an error with it...
>> blk: [ 1 2 7 7 7 4 9 f 3 h h h h 3e 54 5 4 k]
** Syntax Error: Invalid decimal -- 3e ** Near: (line 1) [ 1 2 7 7 7 4 9 f 3 h h h h 3e 54 5 4 k]
> Is this feasible without a lot of work? Would anyone happen to have > such a function in a drawer somewhere?
RANDOM can be used directly on blocks (and series). ie...
>> random [ 1 2 7 7 7 4 9 f 3 h h h h 3 e 54 5 4 k]
== [3 1 4 7 7 h h 5 3 h 2 7 54 k e f 9 4 h]
>> random [ 1 2 7 7 7 4 9 f 3 h h h h 3 e 54 5 4 k]
== [3 h 7 4 h 54 4 5 1 2 e 7 k h h 7 9 3 f]
>> random [ 1 2 7 7 7 4 9 f 3 h h h h 3 e 54 5 4 k]
== [9 4 h 5 3 4 7 2 7 7 3 h f 1 54 h e h k] It just depends on how you define unsorted... -- Carl Read

 [5/5] from: AJMartin:orcon at: 24-Jan-2004 11:42


> Is this feasible without a lot of work? Would anyone happen to have such a
function in a drawer somewhere? 'random seems to work OK for me:
>> random [ 1 2 7 7 7 4 9 f 3 h h h h 3 54 5 4 k]
== [4 3 7 k 7 h 2 54 7 4 h 9 1 3 h f h 5] (Once I changed that '3e to something that Rebol could accept.) Andrew J Martin Speaking in tongues and performing miracles. ICQ: 26227169 http://www.rebol.it/Valley/ http://valley.orcon.net.nz/ http://Valley.150m.com/