Basically, this is an implementation of scrambling that uses swaps. I
remember this method for scrambling from way back, but I can't seem to find
a good reference for it at the moment.
Where should I send my solutions?
Ideally, solutions should be sent to the Ruby Talk mailing list for all to see and learn from. All solutions sent to Ruby Talk are archived with the quiz. If you do not subscribe to Ruby Talk, you may send your messages to me and I will forward them to the list for you. Solutions are easy to find if your message subject includes a [SOLUTION], so that's probably the best tactic to make sure your work is recognized.
-a
···
On 23.4.2006, at 17:52, Daniel Harple wrote:
On Apr 21, 2006, at 2:34 PM, Ruby Quiz wrote:
The three rules of Ruby Quiz:
[...]
Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone
on Ruby Talk follow the discussion.
Can you also suggest that people reply to the original thread instead of making new ones when they send their solutions? Right now there is:
- Original ruby quiz thread
- [QUIZ][SOLUTION] ...
- [QUIZ] ... A solution
- [QUIZ] ... A simplistic solution
- [SOLUTION] ...
this quiz is probably easier than usually, as, for the first time
ever, i felt up to it, and created a solution in not so much time.
i'll be posting it in 48 hrs
greetings, Dirk.
···
2006/4/21, James Edward Gray II <james@grayproductions.net>:
On Apr 21, 2006, at 8:10 AM, Florian Groß wrote:
> Ruby Quiz wrote:
>
>> Your task for this quiz, then, is to take a text as input and
>> output the text in
>> this fashion. Scramble each word's center (leaving the first and
>> last letters of
>> each word intact). Whitespace, punctuation, numbers -- anything
>> that isn't a
>> word -- should also remain unchanged.
>
> What about writing an unscrambler? Could that also be done for this
> quiz or might that be next week's task?
It's not part of the challenge this week or next, but you know I'm
always for setting your own goals.
Given a word like "there's" or "that's", does the letter before the
apostrophe count as a "last" letter? In other words, could "that's"
become "ttha's"?
In the example above, there's no case where that letter gets
scrambled. It's possible that that's coincidence, but it doesn't look
like it.
Do it whichever way you like it...
I don't know what the study said about contractions, if anything.
Personally, I think I would consider the parts before and after as
separate words, which would be slightly less scrambled, but my
intuition (which could be wrong) says that counting it as one whole
word might throw off legibility more than expected.
I guess if the part after the ' isn't going to be mixed in with the
part before (which I definitely don't think it should be), then the
part before does really count as a word, so its first and last letters
would be preserved.
my fully oo version is 12 lines and only 40 words.
i went golfing and got one line : 96 chars
let the games begin
-a
···
On Sat, 22 Apr 2006, Ryan Leavengood wrote:
Strictly speaking, any Ruby code can be made into one line with
liberal use of the semi-colon (;). It would just be an extremely long
line!
My full, nicely abstracted solution for this quiz is 36 lines
(including empty lines), but I also wrote a somewhat obfuscated
one-line version which is 104 characters. But it is missing some of
the features of the full one. But overall it solves the quiz. It is
probably possible to make an even shorter version.
Ryan
--
be kind whenever possible... it is always possible.
- h.h. the 14th dali lama
Also, for a swap method to give random results doesn't one need to
swap from a random position in the array which has not been passed
through yet? (see Wikipedia, the free encyclopedia
/Shuffle noting Fisher-
Yates shuffling.)
Yes. You are right. My memory didn't serve me well in this case.
Instead of j = rand(i+1), it should have been: j = i + rand(x.length-i)
Thanks for the reference.
Himadri
···
On 4/23/06, Albert Vernon Smith <smithav@cshl.edu> wrote:
On 4/23/06, Albert Vernon Smith <smithav@cshl.edu> wrote:
Is the performance better if you skip swaps when i == j ?
Also, for a swap method to give random results doesn't one need to
swap from a random position in the array which has not been passed
through yet? (see Shuffling - Wikipedia noting Fisher-
Yates shuffling.)
-a
On 23.4.2006, at 09:45, Himadri Choudhury wrote:
> print ARGF.read.gsub!(/\B[a-z]+\B/) {|x|
> x.length.times {|i|
> j = rand(i+1)
> x[j], x[i] = x[i] , x[j]
> }
> x
> }
>
> Basically, this is an implementation of scrambling that uses swaps. I
> remember this method for scrambling from way back, but I can't seem
> to find
> a good reference for it at the moment.
> I also figured that this method would be faster since it is linear,
> while
> the sorts are n log(n) (n = length of the word)
>
> To by surprise, I found this method to actually be slower for any
> normal
> text. One possible explanation is that when words are relatively
> short you
> don't gain much from the n vs. nlogn difference, and you lose
> because while
> this method always has n swaps, sorting may have less.
On Apr 23, 2006, at 1:02 PM, Albert Vernon Smith wrote:
From rubyquiz.com:
Where should I send my solutions?
Ideally, solutions should be sent to the Ruby Talk mailing list for all to see and learn from. All solutions sent to Ruby Talk are archived with the quiz. If you do not subscribe to Ruby Talk, you may send your messages to me and I will forward them to the list for you. Solutions are easy to find if your message subject includes a [SOLUTION], so that's probably the best tactic to make sure your work is recognized.
} this quiz is probably easier than usually, as, for the first time
} ever, i felt up to it, and created a solution in not so much time.
} i'll be posting it in 48 hrs
Yes, I sent my solution directly to James. He or I will repost it on
Sunday.
} greetings, Dirk.
--Greg
···
On Fri, Apr 21, 2006 at 11:16:38PM +0900, Dirk Meijer wrote:
} 2006/4/21, James Edward Gray II <james@grayproductions.net>:
} > On Apr 21, 2006, at 8:10 AM, Florian Gro? wrote:
} >
} > > Ruby Quiz wrote:
} > >
} > >> Your task for this quiz, then, is to take a text as input and
} > >> output the text in
} > >> this fashion. Scramble each word's center (leaving the first and
} > >> last letters of
} > >> each word intact). Whitespace, punctuation, numbers -- anything
} > >> that isn't a
} > >> word -- should also remain unchanged.
} > >
} > > What about writing an unscrambler? Could that also be done for this
} > > quiz or might that be next week's task?
} >
} > It's not part of the challenge this week or next, but you know I'm
} > always for setting your own goals.
} >
} > James Edward Gray II
} >
}
}
Oh great... Now I have to read these solutions when writing up a summary.
(Suddenly, I have recollections of my time as a teaching assistant,
having to read mountains of pages of Pascal code written by freshman
newbie programmers.... <shudder>.)
···
On 4/21/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
On Sat, 22 Apr 2006, Ryan Leavengood wrote:
> Strictly speaking, any Ruby code can be made into one line with
> liberal use of the semi-colon (;). It would just be an extremely long
> line!
>
> My full, nicely abstracted solution for this quiz is 36 lines
> (including empty lines), but I also wrote a somewhat obfuscated
> one-line version which is 104 characters. But it is missing some of
> the features of the full one. But overall it solves the quiz. It is
> probably possible to make an even shorter version.
>
> Ryan
my fully oo version is 12 lines and only 40 words.
86 chars after removing all the extraneous spaces. Of course, now it
looks like the Camping source.
Not bad for my first Ruby Quiz.
I have to say I am in favor of making quizzes of varying
difficulty. Like some others here, I've been a bit intimidated by all
the heavy meta stuff in the past, but with varying difficulty I can
work my way up to the tough stuff.
Mmh, for my first participation, i get a quizz solved by a one-liner.
And still i discover things
Yoann
···
On Fri, Apr 21, 2006 at 11:27:08PM +0900, Gregory Seidman wrote:
On Fri, Apr 21, 2006 at 11:16:38PM +0900, Dirk Meijer wrote:
} this quiz is probably easier than usually, as, for the first time
} ever, i felt up to it, and created a solution in not so much time.
} i'll be posting it in 48 hrs
Neo:~/Desktop$ ruby gregory_seidmans_solution.rb test_document.txt
Atchtaed is my résumé.
Neo:~/Desktop$ ruby gregory_seidmans_solution.rb test_document.txt
Acaehttd is my résumé.
Neo:~/Desktop$ ruby gregory_seidmans_solution.rb test_document.txt
Atceahtd is my résumé.
Neo:~/Desktop$ ruby gregory_seidmans_solution.rb test_document.txt
Ahaecttd is my résumé.
James Edward Gray II
···
On Apr 21, 2006, at 9:27 AM, Gregory Seidman wrote:
On Fri, Apr 21, 2006 at 11:16:38PM +0900, Dirk Meijer wrote:
} this quiz is probably easier than usually, as, for the first time
} ever, i felt up to it, and created a solution in not so much time.
} i'll be posting it in 48 hrs