You need to break this down into its component parts: Write a method that tells you score of a character Write a method that tells you the score of a string (hint: use inject:into:) Write a method that tells you the dollar words (hint: use select: and splitOn:)
2008/9/24 Alex Chi alex_chi99@yahoo.com
Hi guys,
I am just beginner in Smaltalk and I have some problem with collection in smalltalk. For this problem I have to define the value of an alphabetic character based on its location in the alphabet. So 'a' and 'A' each have value 1, 'b' and 'B' each have 2, etc. Non-alphabetic characters can be considered to have value 0. The value of a word is the sum of the value of all its characters. So 'Smalltalk' has value 101 and 'abc' has value 6. A dollar word is a word whose value is 100. I want to add a method to the String class that returns all the dollar words in the string.
So for example if the input is 'SmallTalk' the result is ('SmallTlk' 'SmllTlk').
Please kindly help me guys. Really appreciate your help.
Thanks.
Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
At Wed, 24 Sep 2008 22:39:53 +0100, Marcin Tustin wrote:
Write a method that tells you score of a character
Yes.
Write a method that tells you the score of a string (hint: use inject:into:)
Yes.
Write a method that tells you the dollar words (hint: use select: and splitOn:)
This part is not really a Smalltalk question, I think. It is a problem of searching in a power set and finding the all solutions. It is not exactly a simple task, because the length of string may be fairly big, You would need to do some dynamic programming to pick 100 a's from a 10,000 characters string.
http://en.wikipedia.org/wiki/Dynamic_programming
-- Yoshiki
beginners@lists.squeakfoundation.org