Forum: Ruby Ruby Challenge

D66396a04f8bee38d6282e634357aef7?d=identicon&s=25 aseret nuagen (tun51690)
on 2011-11-05 03:40
Here is a ruby challenge for all you computer science lovers out there,
lets see how many ways we can solve this problem:

create a word frequency generator; that is, a program that takes in a
text file and generates a list of words and counts (you know, pairs of
things). Lets say you have a text file.

If the text file contained this sentence, the output of your program
would look something like this:

1 contained
1 file
1 if
1 like
1 look
1 of
1 output
1 program
1 sentence
1 something
1 text
1 would
1 your
2 the
2 this

Consider a "word" to be any space-delimited token. How would you also do
this with punctuation included?
45196398e9685000d195ec626d477f0e?d=identicon&s=25 Thomas Sawyer (7rans)
on 2011-11-05 04:56
(Received via mailing list)
Why does this sound like a school assignment?

    file = 'sample.txt'
    freq = Hash.new{|h,k| h[k] = 0}
    File.read(file).scan(/\w+/) do |w|
      freq[w] += 1
    end
    freq.each do |w,c|
      puts "#{c} #{w}"
    end

Untested.
Ab1e7e93a3ee0ecebbe887f5ee788a09?d=identicon&s=25 Russell (Guest)
on 2011-11-05 05:06
(Received via mailing list)
A solution like this is in the Pickaxe book as well.
D66396a04f8bee38d6282e634357aef7?d=identicon&s=25 aseret nuagen (tun51690)
on 2011-11-05 05:59
Thomas Sawyer wrote in post #1030247:
>
>     file = 'sample.txt'
>     freq = Hash.new{|h,k| h[k] = 0}
>     File.read(file).scan(/\w+/) do |w|
>       freq[w] += 1
>     end
>     freq.each do |w,c|
>       puts "#{c} #{w}"
>     end



There should be an "if" / "else" statement in a looping method, to add
the word in the list if it's not there and a word count.
24ad906535e7c0ea9355b6442233888a?d=identicon&s=25 Sylvester Keil (Guest)
on 2011-11-05 11:40
(Received via mailing list)
On Nov 5, 2011, at 5:59 AM, teresa nuagen wrote:

>>    end
>>
>> Untested.
>
>
> There should be an "if" / "else" statement in a looping method, to add
> the word in list or word count.

Careful, you don't want to annoy the people who help you. The code
solves your problem admirably: paste this (don't copy the ### marks)
into a file and run it, and you will get exactly the output you wanted:

###

freq = Hash.new{|h,k| h[k] = 0}
DATA.read.scan(/\w+/) do |w|
  freq[w.downcase] += 1
end
freq.each.sort_by {|w,c| [c,w] }.each do |w,c|
  puts "#{c} #{w}"
end

__END__

If the text file contained this sentence, the output of your program
would look something like this

###

Before claiming a proposed solution to a 'challenge' you posted is
missing something, have the decency at least to run it to see if it
works. In this case, Intransition's solution sets the counter for each
word to zero (this is what the first line does: if you add a word to the
freq hash for the first time the counter is set to zero). The scan
method is your 'looping method' and executes the block at each
iteration. Finally, `freq[w.downase] += 1` increases the counter for
each word. By defining, the zero default, Intransition's solution
doesn't require your if/else statement. So, please, next time, instead
of simply stating 'there should be an if/else statement there', how
about 'cool solution! Can you explain to me why this works without an
explicit if/else statement?'.
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (robert_k78)
on 2011-11-05 11:54
(Received via mailing list)
On Sat, Nov 5, 2011 at 3:40 AM, teresa nuagen <unguyen90@aim.com> wrote:
> 1 contained
> 1 would
> 1 your
> 2 the
> 2 this
>
> Consider a "word" to be any space-delimited token. How would you also do
> this with punctuation included?

Now, where's the challenge?  I rather get the impression that you want
to make other people do your work by spicing the task with the word
"challenge".  If that should indeed be the case please be aware that
this kind of behavior is not appreciated in our community.

Cheers

robert
D66396a04f8bee38d6282e634357aef7?d=identicon&s=25 aseret nuagen (tun51690)
on 2011-11-05 18:26
Robert Klemme wrote in post #1030275:
> On Sat, Nov 5, 2011 at 3:40 AM, teresa nuagen <unguyen90@aim.com> wrote:
>> 1 contained
>> 1 would
>> 1 your
>> 2 the
>> 2 this
>>
>> Consider a "word" to be any space-delimited token. How would you also do
>> this with punctuation included?
>
> Now, where's the challenge?  I rather get the impression that you want
> to make other people do your work by spicing the task with the word
> "challenge".  If that should indeed be the case please be aware that
> this kind of behavior is not appreciated in our community.
>
> Cheers
>
> robert

Don't worry this is just for fun, because it's a social ruby forum for
talented programmers and those who enjoy challenges. The key challenge
to this is to incorporate punctuations to it, writing the program with
punctuations in the words.
7353db17cf19f920fbd24479c8157781?d=identicon&s=25 Jonan S. (jonan_s)
on 2011-11-05 19:53
Totally unrelated to any husker computer science programs right? Like
the previous homework you posted about reversing a poem?

Uyen I'm not sure you understand how very public this forum is, and how
easily someone from your school could question your academic integrity
with information they find here.

Asking for advice is entirely welcome here; handing off homework is not.
D110867fefd12de5e388c03b146e07cb?d=identicon&s=25 Stephen Ramsay (sramsay)
on 2011-11-09 03:10
Jonan S. wrote in post #1030330:

> Uyen I'm not sure you understand how very public this forum is, and how
> easily someone from your school could question your academic integrity
> with information they find here.

You mean like the professor for the course?  Because that would be me .
. .  That "challenge" is copied almost verbatim from a problem set.

I would just like to take this opportunity to thank the members of this
board for their general vigilance in this matter.  As we all know,
students (some students) try this kind of thing all the time, and yet
the community can be relied upon to call them on it.

No one asks you to do that, and certainly, no professor would expect
people who are otherwise just trying to be helpful to act as the ethics
police (nor could I blame anyone who answers the question in good
faith).  But the truth is, someone nearly always calls them on it, and I
think those of us who teach programming are very grateful for your help.
You're upholding the ethical standards of our discipline, and you really
do a great service to the profession by doing so.



Steve
D66396a04f8bee38d6282e634357aef7?d=identicon&s=25 aseret nuagen (tun51690)
on 2011-11-09 04:52
> You mean like the professor for the course?  Because that would be me .
> . .  That "challenge" is copied almost verbatim from a problem set.
>
> I would just like to take this opportunity to thank the members of this
> board for their general vigilance in this matter.  As we all know,
> students (some students) try this kind of thing all the time, and yet
> the community can be relied upon to call them on it.
>
> No one asks you to do that, and certainly, no professor would expect
> people who are otherwise just trying to be helpful to act as the ethics
> police (nor could I blame anyone who answers the question in good
> faith).  But the truth is, someone nearly always calls them on it, and I
> think those of us who teach programming are very grateful for your help.
> You're upholding the ethical standards of our discipline, and you really
> do a great service to the profession by doing so.
>
>
>
> Steve

I'm sorry for the trouble. I'm a friend who she came to for
help with this problem and she did not ask me to post this. I created
this forum acct under her email address which i know now is a huge
mistake for jeopardizing her "honesty" identity like this. She asked me
for help and I didn't know how to do it, so instead I took the easy
route and ask it in here forgetting that it is public. She told me that
what i was doing was wrong and that if i did not know then i shouldn't
ask the public to try and solve it. She said "i rather do this on my own
then to turn in somebody else's work. In my school this is considered
academic dishonesty, and as a senior soon to graduate, I cannot risk it.
If I do not understand it, then I will not turn it in. I'm  better off
dropping the course then to pass on an assignment that i did not write."
Those were her exact words and once she officially dropped the class on
Saturday, I knew that she was serious and refuse to get involve in what
is posted on here. I may have asked the community for help on a problem,
but she did a noble choice in refusing to use the problem and would
rather not turn the assignment. she said that she has missed 2
assignment and because of that, her only resort is to drop the class.
She said she is very devastated by this because you're her favorite
teacher, but this is the only option since she didn't do the problems.

I'm sorry for the trouble this has caused you.
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (robert_k78)
on 2011-11-09 09:47
(Received via mailing list)
On Wed, Nov 9, 2011 at 4:52 AM, aseret nuagen <unguyen90@aim.com> wrote:
>> police (nor could I blame anyone who answers the question in good
>> faith). But the truth is, someone nearly always calls them on it, and I
>> think those of us who teach programming are very grateful for your help.
>> You're upholding the ethical standards of our discipline, and you really
>> do a great service to the profession by doing so.

You are welcome!

> If I do not understand it, then I will not turn it in. I'm better off
> I'm sorry for the trouble this has caused you.
You are focusing on the "get free help" matter but if I understand
this correctly and all this is true then this can be seen as a case of
identity theft, which may even be subject to legal prosecution.  I
have to say I find impersonating someone else by (ab)using their email
address even worse than trying to get something for free from the
community.  Why on earth did you not use your own email account for
this?  This is such a great community and I am very sad seeing things
like this happening here.

Regards

robert
45196398e9685000d195ec626d477f0e?d=identicon&s=25 Thomas Sawyer (7rans)
on 2011-11-09 13:50
(Received via mailing list)
Come on. Let's not be so harsh. If truth is being told, then this girl
has
now dropped a class over it. And what good does that serve? Now she
won't
be learning any Ruby, Programming, or (IMHO) how to truly "Think".
Shaming
her or her friend isn't going to make the world a better place.
Encouraging
her to earnestly try, on her own, regardless of the outcome or the grade
she might receive is more noble. As long as she learns, even just a
small
portion of what her classmates manage, then at least it is something
positive. And relative growth is far more important than absolutes. For
what might seem small to you and me can in fact be quite huge to a
newbie.
C7e977010e5ce904ef18630b7bf2586a?d=identicon&s=25 Sam Rose (Guest)
on 2011-11-09 14:00
(Received via mailing list)
Hmm... That last post from Uyen sounds very much made up to me...

But I agree with Intransition. Well said :)

I've only been on this list for a few weeks and already I'm feeling as
if I'll be frequenting for a long time.
D66396a04f8bee38d6282e634357aef7?d=identicon&s=25 aseret nuagen (tun51690)
on 2011-11-09 15:47
Attachment: image.jpg (50 KB)
Attachment: image.jpg (50 KB)
i attached a photo of the message she sent me. She wanted the truth be
told and with my apologies that's what i did. I'm sorry for turning the
problem into a "challenge" i'm international not from this different
culture so i don't know.
7353db17cf19f920fbd24479c8157781?d=identicon&s=25 Jonan S. (jonan_s)
on 2011-11-09 18:36
(Received via mailing list)
I'm also lamenting the loss of another learner.

Good luck Uyen, I hope you keep programming.
5a837592409354297424994e8d62f722?d=identicon&s=25 Ryan Davis (Guest)
on 2011-11-09 23:09
(Received via mailing list)
On Nov 9, 2011, at 04:50 , Intransition wrote:

> Come on. Let's not be so harsh.

Leave it to you to side with intellectual dishonesty.

No, let's be harsh. If this kid has gotten to college level and not
learned that taking credit for someone else's work is not only wrong,
but going to bite you in the ass hard once you leave academia, then it
is certainly time to drive that lesson home. What we don't need out
there is another plagerist.

> If truth is being told, then this girl has now dropped a class over it.

You don't know what the policy of the school is. Don't assume you have
any idea what the outcome will be.

> And what good does that serve?

It serves a lot of good. Both for her and for society in general. Look
at the devastating effects of the work of Victor Ninov and Jan Hendrik
Schn. A distinct lack of ethics and intellectual dishonesty caused this.
Do we need more of it? No.

> Now she won't be learning any Ruby, Programming, or (IMHO) how to truly "Think".

Again, you don't know that. You have no idea what the disciplinary
policy of this school is.

> Shaming her or her friend isn't going to make the world a better place.
Encouraging her to earnestly try, on her own, regardless of the outcome or the
grade she might receive is more noble. As long as she learns, even just a small
portion of what her classmates manage, then at least it is something positive. 
And
relative growth is far more important than absolutes.

So, taking credit for someone else's work, as long as she can claim she
learned something from it, is a good thing in your opinion. What happens
when she's out in the real world with a real job and she tries that? She
gets fired, without benefits, and that reference is forever burned. It
probably follows her around as well.

> For what might seem small to you and me can in fact be quite huge to a newbie.

Which is why driving this lesson home now is a Good Thing.
99804651e19d8b0dffbc0da53e39114e?d=identicon&s=25 Adam Prescott (Guest)
on 2011-11-09 23:24
(Received via mailing list)
On Wed, Nov 9, 2011 at 22:08, Ryan Davis <ryand-ruby@zenspider.com>
wrote:

> Again, you don't know that. You have no idea what the disciplinary policy
> of this school is.
>

I know you seem to like to get to the point in this aggressive way, and
I
have no idea what existing issues you have with Intransition are (and I
don't want to know), but the comments are being made based on the prior
post that the girl has already dropped out because she finds the class
difficult, not because of whatever assumptions about disciplinary
policies.
5a837592409354297424994e8d62f722?d=identicon&s=25 Ryan Davis (Guest)
on 2011-11-09 23:56
(Received via mailing list)
On Nov 9, 2011, at 14:23 , Adam Prescott wrote:

>> "Think".
>>
>> Again, you don't know that. You have no idea what the disciplinary policy
>> of this school is.
>>
>
> I know you seem to like to get to the point in this aggressive way, and I
> have no idea what existing issues you have with Intransition are (and I
> don't want to know), but the comments are being made based on the prior
> post that the girl has already dropped out because she finds the class
> difficult, not because of whatever assumptions about disciplinary policies.

This has less to do with trans and more to do with my absolute
intolerance for intellectual dishonesty. I've been that teacher before.
My best friend actually worked on element 118 with Victor Ninov. (and
Trans has reused my code and violated my license terms). I have a zero
tolerance policy for such behavior and think we should, as a society,
discipline/blacklist/shun (as appropriate) said people.

That said, I did overlook that post and misunderstand the alleged
explanation as it was given (simple TL;DR error on my part). Thank you
for calling me to task. The rest of my point still stands.
349d851184514340f1757f3a71b6807a?d=identicon&s=25 luke gruber (luke-gru)
on 2011-11-10 01:33
More predictable twists than an M. Night Shyamalan movie!

> Posted by Sam Rose
> Hmm... That last post from Uyen sounds very much made up to me...

Even if I try to fight my more cynical instincts, it still sounds
like it's the same person.

Which is fine, we all make mistakes. I just hope whoever it is that did
whatever they did (or did not do) will keep learning Ruby. I also hope
that whoever that was that was posting will work on their persuasive
techniques.

-Luke
45196398e9685000d195ec626d477f0e?d=identicon&s=25 Thomas Sawyer (7rans)
on 2011-11-10 02:18
(Received via mailing list)
The Lord have mercy on your soul, Ryan. You must honestly be one of the
saddest persons in the world. You had a fit over six lines of code that
I
used from MiniTest to get Turn to work with MiniTest --b/c you changed
the
MiniTest API and I had to do a work around. And once you pointed out
this
bit of code, your copyright notice was added to the project --a project
I
worked extensively on and never asked for one iota of credit.

No one else recalls it now, I'm sure, but the Hoe project was a complete
ripoff of my original Reap project. But I didn't complain. I saw that
you
did a good job on it and I admittedly muffed up the management of the
original project (I was completely new to project management at the
time).
Is that what all this hate is about? You stole my project and have been
compensating for the guilt this whole time?
D469019a435a5dbd5c792016fdf67a0b?d=identicon&s=25 Jon Forums (jonm)
on 2011-11-10 17:15
>>> Come on. Let's not be so harsh.
>> ...
>> Leave it to you to side with intellectual dishonesty.
> ...
> The Lord have mercy on your soul, Ryan. You must honestly be one of the
> saddest persons in the world.

Please, no more.

You two have developed an amazing ability to push each others buttons,
react, escalate, and devolve into personal attacks in very public ways.

Sadly, these comments distract from your main ideas and the interesting
work both of you are doing. Not to mention that it appears neither of
you find it particularly fun, or what you'd really like to be spending
your time doing.

If you can't check it at the door or resolve it in private, at least
make it entertaining for those of us to don't want to blacklist either
of you.

You could always refocus and whip up a Heroku-Sinatra-HTML5-Canvas
version of

  http://shop.mattel.com/product/index.jsp?productId=3761723

for a Transmutated Zen Spider Celebrity Rumble in the Jungle.

Jon
F141ba99f29e55f02207f5488fe5ce95?d=identicon&s=25 Dave Aronson (Guest)
on 2011-11-10 18:01
(Received via mailing list)
On Thu, Nov 10, 2011 at 11:15, Jon Forums <jon.forums@gmail.com> wrote:

> If you can't check it at the door or resolve it in private, at least
> make it entertaining for those of us to don't want to blacklist either
> of you.
>
> You could always refocus and whip up a Heroku-Sinatra-HTML5-Canvas
> version of
>
>  http://shop.mattel.com/product/index.jsp?productId=3761723
>
> for a Transmutated Zen Spider Celebrity Rumble in the Jungle.

They can make it the sequel to Real Steel....

-Dave
E1b909a4fb4b0310f85912b9adcdcb9e?d=identicon&s=25 Lee Karven (leekarven)
on 2014-01-22 08:07
Oh my God, for starters, I, this is a problem.

-----------------------------------------------
http://www.toyswill.com
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.