
-----------------------------------
xXInsanityXx
Sat Nov 26, 2005 3:09 pm

DWITE NOVEMBER 25 2005 PROBLEM 3 SOLUTION
-----------------------------------
Hi i was wondering if you guys can give me suggestions,feedback, and simplifications to this code. Please feel free to criticize as much as you want.

Please and Thank You

NOTE: PLEASE DO NOT CLAIM THIS CODE AS YOURS  -not that its that great-

-----------------------------------
MysticVegeta
Sat Nov 26, 2005 11:20 pm


-----------------------------------
May I ask where the code is?

-----------------------------------
Hikaru79
Sun Nov 27, 2005 12:01 am


-----------------------------------
Attached to his post?

-----------------------------------
MysticVegeta
Sun Nov 27, 2005 1:00 am


-----------------------------------
I cannot see it  :?

-----------------------------------
Hikaru79
Sun Nov 27, 2005 1:03 am


-----------------------------------
Hm, wierd =/ I'll upload it to this post. Can you see it on mine?

-----------------------------------
MysticVegeta
Sun Nov 27, 2005 11:35 am


-----------------------------------
yeah, heres mine by the ways. 
var fi, fo : int

open : fi, "DATA31.txt", get
open : fo, "OUT31.txt", put

var lines : string
var numbers : array 1 .. 5 of int
var syl : string := "24682"
var current, high, lineno, original : int := 0


fcn wordCount (word : string) : int
    var count := 0
    for s : 1 .. length (word)
        if word (s) = " " or word (s) = "-" then
            count += 1
        end if
    end for
    result count + 1
end wordCount

proc errors
    for x : 1 .. 5
        numbers (x) := strint (syl (x)) - numbers (x)
        if numbers (x) not= 0 then
            current := abs (numbers (x))
            if current > high then
                original := numbers (x)
                high := current
                lineno := x
            end if
        end if
    end for
end errors

for s : 1 .. 5
    for x : 1 .. 5
        get : fi, lines : *
        numbers (x) := wordCount (lines)
    end for
    errors
    if abs (original) = original then
        put : fo, "LINE ", lineno, " - ", original, " SYLLABLE(S) TOO FEW"
    else
        put : fo, "LINE ", lineno, " - ", abs (original), " SYLLABLE(S) TOO MANY"
    end if
    lineno := 0
    original := 0
    current := 0
    high := 0
end for
close (fi)
close (fo)

I dont know if this is the original one or the bad one.. I sorta screwed up my folder because I was p!ssed earlier. lol  :lol:

-----------------------------------
Cervantes
Sun Nov 27, 2005 11:53 am


-----------------------------------
MysticVegeta: Weren't you supposed to put nothing if all the lines are correct?  And won't that put "LINE  0 -  0 SYLLABLE(S) TOO FEW"?

-----------------------------------
Hikaru79
Sun Nov 27, 2005 12:34 pm


-----------------------------------
This sort of problem is where Java's beautiful library comes in handy. One line, StringTokenizer st = new StringTokenizer (in.readLine()," -"); and the whole question just falls apart :D When you're on a timed contest, this sort of thing is great.

-----------------------------------
MysticVegeta
Sun Nov 27, 2005 2:01 pm


-----------------------------------
MysticVegeta: Weren't you supposed to put nothing if all the lines are correct?  And won't that put "LINE  0 -  0 SYLLABLE(S) TOO FEW"?

Never said that one the question that all lines will be correct.

Hikaru: What does the String.Tokenizer do?

-----------------------------------
Hikaru79
Sun Nov 27, 2005 2:10 pm


-----------------------------------
MysticVegeta: Weren't you supposed to put nothing if all the lines are correct?  And won't that put "LINE  0 -  0 SYLLABLE(S) TOO FEW"?

Never said that one the question that all lines will be correct.

Hikaru: What does the String.Tokenizer do?

StringTokenizer splits up a string based on the presence of certain characters. Notice how when I call the StringTokenizer constructor, I gave it an argument " -"? What that does is take a String, and break it into a different piece whenever it finds a space or a '-' character -- basically solving the problem for you. Then you simply have to count the amount of Tokens that StringTokenizer gives you, and voila, you know how many syllables there are :)

-----------------------------------
MysticVegeta
Sun Nov 27, 2005 2:33 pm


-----------------------------------
Dont you need two of these commands, 1 for " ", and other for "-"? Also, mind telling me the stringSplit command in Java? Thanks a lot :)

-----------------------------------
Hikaru79
Sun Nov 27, 2005 2:54 pm


-----------------------------------
Dont you need two of these commands, 1 for " ", and other for "-"?
Nope :) The second parameter is optional, but if you give it, it treats every single character in the string as a delimiter. No need to tokenize the tokens twice, that would just be painful. StringTokenizer is a powerful tool, I think I use it on just about every contest I've ever written.

Also, mind telling me the stringSplit command in Java? Thanks a lot :)
I've never heard of a stringSplit method, sorry :(

-----------------------------------
Cervantes
Sun Nov 27, 2005 3:16 pm


-----------------------------------
Dont you need two of these commands, 1 for " ", and other for "-"? 
Notice that the parameter he passed in contained two characters: a space and a hyphen.  I assume that it would tokenize the string based on every character in that string parameter.  Seems to me that it would make more sense if it passed in an array of characters.  That would also give more flexibility: you could tokenize the string at space, hyphen, and a double hyphen.

-----------------------------------
MysticVegeta
Sun Nov 27, 2005 3:25 pm


-----------------------------------
Yeah I noticed it before posting too but then I thought about it and thought that since "-" and " " form 1 string, maybe it would tokenize the part where it would find " -". If it does otherwise, how can we tokenize a string with more than 1 character?

-----------------------------------
Hikaru79
Sun Nov 27, 2005 4:41 pm


-----------------------------------
Dont you need two of these commands, 1 for " ", and other for "-"? 
Notice that the parameter he passed in contained two characters: a space and a hyphen.  I assume that it would tokenize the string based on every character in that string parameter.  Seems to me that it would make more sense if it passed in an array of characters.  That would also give more flexibility: you could tokenize the string at space, hyphen, and a double hyphen.

Hmm, that's an excellent idea. I don't know why Sun never thought of that.

Perhaps I'll make a class Extending StringTokenizer which can do just that :D

-----------------------------------
zylum
Mon Nov 28, 2005 10:11 am


-----------------------------------
you should use String.split(String s); rather than tokenizer.. its much more powerful. it accepts a string as a parameter and it returns an array of strings. the string is split based on the string you provided. you can even use regular expressions as a parameter. so for the example above ie hyphen, space, or both you would  do: 

String[] splitArray = stringToSplit.split("[ -]++");

-----------------------------------
bugzpodder
Mon Nov 28, 2005 10:38 am


-----------------------------------
umm not really (to the post above zylum). there are design issues with this idea.

for example, if we were to tokenize based on "--" and "-"
on the string

omg---omg

-----------------------------------
MysticVegeta
Mon Nov 28, 2005 2:04 pm


-----------------------------------
I am confused  :? Does the (" -") split both " " and "-"? also, what is the "++" for?  :x

-----------------------------------
bugzpodder
Mon Nov 28, 2005 2:41 pm


-----------------------------------
i believe thats regular expressions.

-----------------------------------
Cervantes
Mon Nov 28, 2005 4:12 pm


-----------------------------------
umm not really (to the post above zylum). there are design issues with this idea.

for example, if we were to tokenize based on "--" and "-"
on the string

omg---omg

Good point.  I guess you'd throw an error if one of the strings is a substring of another string.  ie. "-" is a substring of "--".  

Still, it could be useful.

-----------------------------------
xXInsanityXx
Mon Nov 28, 2005 6:28 pm


-----------------------------------
To Mysticvegeta,

Ignore my idiocy, but in this particular case, doesnt your way seem to be a bit too complicated, or elongated, and the logic is stretching much more farther than the necessity, please i want feedback and opinions from everybody. Honestly, i would love to have programming skills like mystic, but wouldnt this take much more time?

-----------------------------------
MysticVegeta
Mon Nov 28, 2005 6:54 pm


-----------------------------------
what the heck? Your team scored more than me! Besides if you want programming skills really good, make them like Zylum, Bugz, Cervantes, wtd, rizzix, Hikaru.... I am really a noobie compared to them  :!:

-----------------------------------
bugzpodder
Mon Nov 28, 2005 7:01 pm


-----------------------------------
umm not really (to the post above zylum). there are design issues with this idea.

for example, if we were to tokenize based on "--" and "-"
on the string

omg---omg

Good point.  I guess you'd throw an error if one of the strings is a substring of another string.  ie. "-" is a substring of "--".  

Still, it could be useful.

what about trying to use
hello
lol
as tokens on

hellololol

there are two problems here, hello and lol overlap, and lol overlaps with itself.

too many errors thrown, i'd say.

-----------------------------------
Cervantes
Mon Nov 28, 2005 8:17 pm


-----------------------------------
Good point, bugzpodder.

Still, it seems like a feature that would be useful.  Consider the same problem, except instead of using "-" they used "--".  One wouldn't be able to use the tokenizer then.  

Perhaps it would work with an precedence order.  First it splits everything up based on the first element of the array, then splits those up based on the second, etc.

-----------------------------------
bugzpodder
Mon Nov 28, 2005 10:27 pm


-----------------------------------
acutally you can still use the tokenizer.  i am just not sure the correct behaviour though, you might either get empty string between the double dash or you might not get it.  its easy enough to just skip over the empty strings.

All in all, I see no point in extending tokenizer to general strings.  if you want the behaviour you descirbed, you can just use the find/search command for the first string, then the second, etc...

-----------------------------------
zylum
Mon Nov 28, 2005 11:06 pm


-----------------------------------
can anybody post the harder problems from the last contest?

-----------------------------------
JackTruong
Mon Nov 28, 2005 11:30 pm


-----------------------------------
Which ones are the harder ones? I thought the hard ones were #4 and possibly #5. I can post the Java for them.

-----------------------------------
zylum
Tue Nov 29, 2005 2:00 pm


-----------------------------------
i mean the problems not the solutions...

-----------------------------------
xXInsanityXx
Wed Nov 30, 2005 1:16 pm


-----------------------------------
i mean the problems not the solutions...

go to dwite.org previous contest, november 2005, scroll down and you will find a list of the problems in pdf format read em test em with data, and solve em too  :wink:

-----------------------------------
MysticVegeta
Wed Nov 30, 2005 2:34 pm


-----------------------------------
oh. dont worry about him, he will complete all 5 in 45 mins.
