ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
Re: scramble sentence, how to better program?
by S2 other posts by this author
May 8 2008 2:25PM messages near this date
Re: scramble sentence, how to better program? | windows prompt, how to write [ ] ?
globalrev wrote:

>  i have written a program that takes a sentence as input and outputs
>  the sentence with the words rearranged.
>  

sentence = "this is a sentence with the word sentence repeaed"

sentence = sentence.split(' ')
scr = []
scri = []

while scri.length != sentence.length
  i = rand(sentence.length)
  scri << i unless scri.include? i
end

scri.each {|i| scr << sentence[i]}
p scr.join(' ')
Thread:
Globalrev
David A. Black
S2
S2
Globalrev
S2
7stud --
David A. Black
Rob Biedenharn
S2
S2

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved