1. Fun Test Problem

See here.

Post your results!

new topic     » topic index » view message » categorize

2. Re: Fun Test Problem

include get.e 
 
atom fn 
fn = open("input.in","r") 
 
sequence setup 
setup = gets(fn) 
 
--parse setup 
object word_length, num_of_words, num_of_testcases 
word_length = {} 
num_of_words = {} 
num_of_testcases = {} 
 
for i = 1 to length(setup) do 
	if not equal(setup[i],' ') then 
		word_length = append(word_length,setup[i]) 
	else 
		setup = setup[i+1..length(setup)] 
		exit 
	end if 
end for 
 
word_length = value(word_length) 
word_length = word_length[2] 
 
for i = 1 to length(setup) do 
	if not equal(setup[i],' ') then 
		num_of_words = append(num_of_words,setup[i]) 
	else 
		setup = setup[i+1..length(setup)] 
		exit 
	end if 
end for 
 
num_of_words = value(num_of_words) 
num_of_words = num_of_words[2] 
 
for i = 1 to length(setup) do 
	num_of_testcases = append(num_of_testcases,setup[i]) 
end for 
 
num_of_testcases = value(num_of_testcases) 
num_of_testcases = num_of_testcases[2] 
 
sequence words, test_cases, test_cases_seq 
words = {} 
test_cases = {} 
 
for i = 1 to num_of_words + num_of_testcases do 
	if i < num_of_words + 1 then 
		words = append(words,gets(fn)) 
	elsif i > num_of_words then 
		test_cases = append(test_cases,gets(fn)) 
	end if 
end for 
 
close(fn) 
 
integer index  --index into each sub-sequence per test case.  i.e. (ab) index = 1 = a 
index = 1 
 
integer letter_position  --index for each letter position.  i.e. (ab)(bc)(cd) letter_position = 2 = (bc) 
letter_position = 1 
 
integer subsequence  --are we working in a sub-sequence? 
subsequence = 0 
 
integer test_case_length 
 
test_cases_seq = repeat(repeat({},word_length),num_of_testcases) 
for i = 1 to num_of_testcases do  --length of list of test cases 
	if test_cases[i][length(test_cases[i])] = '\n' then 
		test_case_length = length(test_cases[i]) - 1 
	else 
		test_case_length = length(test_cases[i]) 
	end if 
	for j = 1 to test_case_length do  --length of current test case 
		if equal(test_cases[i][j],'(') then  --beginning of possible letter combination? 
			subsequence = 1 
		end if 
		if not equal(test_cases[i][j],')') and not equal(test_cases[i][j],'(') then 
			if not subsequence then 
				test_cases_seq[i][letter_position] = {test_cases[i][j]} 
				letter_position += 1 
			else 
				test_cases_seq[i][letter_position] = append(test_cases_seq[i][letter_position],test_cases[i][j]) 
			end if 
		elsif not equal(test_cases[i][j],'(') then 
			letter_position += 1 
			subsequence = 0 
		end if 
	end for 
	letter_position = 1 
end for 
 
sequence case 
case = repeat(0,num_of_testcases) 
 
 
for i = 1 to num_of_words do 
	for j = 1 to num_of_testcases do 
		while letter_position < word_length + 1 do 
			if find(words[i][letter_position],test_cases_seq[j][letter_position]) then 
				letter_position += 1 
			else 
				exit 
			end if 
			if letter_position = word_length and find(words[i][letter_position],test_cases_seq[j][letter_position]) then 
				case[j] += 1 
			end if 
		end while 
		letter_position = 1 
	end for 
end for 
 
atom fn_out 
fn_out = open("Output.txt","w") 
for i = 1 to num_of_testcases do 
	printf(fn_out,"Case #%d: %d\n",{i,case[i]}) 
end for 
close(fn_out) 
new topic     » goto parent     » topic index » view message » categorize

3. Re: Fun Test Problem



There's not enough info to do this.

The problem example is:

-- first, the dictionary list of "You may assume that all known words provided are unique.":
40 abc
41 bca
42 dac
43 dbc
44 cba

-- now, the "recieved" and garbled unknown words:
45 (ab)(bc)(ca)
46 abc
47 (abc)(abc)(abc)
48 (zyx)bc
49

-- now the supposedly true results? :
50 Output
51 Case #1: 2 -- cannot be true, could also match several others
52 Case #2: 1 -- obviously, it's in the dictionary of known words
53 Case #3: 3 -- could match any known, and many unknown words
54 Case #4: 0 -- obviously true, no z, y, or x


So something is wrong somewhere. I mean besides needing to use the double backslashes to get newlines, and the 4 dashes in some places to get the 2-dash Eu comment format.

useless

edit by Derek to demonstrate alternative creoles tag so Kat doesn't have to use forced-line breaks etc ...

new topic     » goto parent     » topic index » view message » categorize

4. Re: Fun Test Problem

useless said...

There's not enough info to do this.

Of course there is. Read it properly.

useless said...

now the supposedly true results? :
51 Case #1: 2 --
cannot be true, could also match several others

So how many of the five words given do you think begin with a or b?

useless said...

53 Case #3: 3 -- could match any known, and many unknown words

And how many begin with a, b, or c?

If it isn't possible, how do you explain the solution that has just been posted?

new topic     » goto parent     » topic index » view message » categorize

5. Re: Fun Test Problem

Using Euphoria 4 syntax ...

include std/io.e 
include std/text.e 
include std/sequence.e 
include std/convert.e 
 
/* ** Get control data ** 

   This is one line containing three integers: 
      #1 = Maximum length of a word 
      #2 = Number of words in dictionary 
      #3 = Number of test cases in sample. 
*/ 
 
sequence dict = {} 
integer dictsize = 0 
 
integer inpf = open("input.txt", "r") 
if inpf = -1 then 
	puts(1, "Unable to open input.txt\n") 
	abort(0) 
end if 
 
integer outf = open("output.txt", "w") 
if outf = -1 then 
	puts(1, "Unable to open output.txt\n") 
	abort(0) 
end if 
 
object aLine 
 
aLine = gets(inpf) 
if atom(aLine) then 
	puts(1, "!! No data in input file\n") 
	abort(1) 
end if 
 
aLine = split(trim(aLine)) 
if length(aLine) != 3 then 
	puts(1, ` 

____ 
	!! Control data format error. 
	Expecting first line to contain exactly three integers 
	`) 

	abort(1) 
end if 
 
integer max_word_size = to_integer(aLine[1]) 
integer max_dict_size = to_integer(aLine[2]) 
integer max_test_size = to_integer(aLine[3]) 
 
for i = 1 to max_dict_size do 
	aLine = gets(inpf) 
	if atom(aLine) then 
		puts(1, "!!Expected more dictionary entries.\n") 
		abort(1) 
	end if 
	dict = append(dict, trim(aLine)) 
end for 
 
integer this_case = 0 
integer index 
integer state 
sequence pattern 
 
for i = 1 to max_test_size do 
	aLine = gets(inpf) 
	if atom(aLine) then 
		puts(1, "!!Expected more test entries.\n") 
		abort(1) 
	end if 
	 
	aLine = trim(aLine) 
	this_case += 1 
	pattern = {} 
	index = 1 
	state = 0 
	while index <= length(aLine) do 
		switch aLine[index] do 
			case '(' then 
				if state = 0 then 
					state = 1 
					pattern = append(pattern, {}) 
				else 
					printf(1, "%s\n", {aLine}) 
					printf(1, "!!Not expecting '(' at column %d\n", index) 
					abort(1) 
				end if 
				 
			case ')' then 
				if state = 1 then 
					state = 0 
				else 
					printf(1, "%s\n", {aLine}) 
					printf(1, "!!Not expecting ')' at column %d\n", index) 
					abort(1) 
				end if 
				 
			case else 
				if state = 0 then 
					pattern = append(pattern, {aLine[index]}) 
				else 
					pattern[$] &= aLine[index] 
				end if 
		end switch 
		index += 1 
	end while 
	 
	if state != 0 then 
		printf(1, "%s\n", {aLine}) 
		puts(1, "!!Missing ')'\n") 
		abort(1) 
	end if 
 
	-- At this point, we have a pattern set up, 
	-- so we check each word in the dictionary against the pattern.	 
	integer case_count = 0 
	for j = 1 to length(dict) label "dict_scan" do 
		sequence this_word = dict[j] 
		if length(this_word) != length(pattern) then 
			continue 
		end if 
		 
		for k = 1 to length(this_word) do 
			if find(this_word[k], pattern[k]) = 0 then 
				continue "dict_scan" 
			end if 
		end for 
	 
		case_count += 1 
		 
	end for 
	 
	printf(outf, "Case #%d:%d\n", {i, case_count}) 
end for 
 
close(inpf) 
close(outf) 
-- end of code -- 
 
new topic     » goto parent     » topic index » view message » categorize

6. Re: Fun Test Problem


petelomax said...


useless said...


There's not enough info to do this.


Of course there is. Read it properly.


I guess i am incapable of that.

petelomax said...


useless said...


now the supposedly true results? :

51 Case #1: 2 --
cannot be true, could also match several others


So how many of the five words given do you think begin with a or b?


I think two:
40 abc
41 bca
How many do you think? And don't you think the count will go up with the 5000 word dictionary?

[quote petelomax]

useless said...


53 Case #3: 3 -- could match any known, and many unknown words


petelomax said...


And how many begin with a, b, or c?


I'll guess three, but you might want to check my math:
40 abc
41 bca
44 cba
How many do you think? And don't you think the count will go up with the 5000 word dictionary?

petelomax said...


If it isn't possible, how do you explain the solution that has just been posted?


Well, it isn't complete and exhaustive. I didn't run it.

useless

note to Derek that the triple brackets he edited my previous post with are not in the online help sections of the reply pages of euphorum

new topic     » goto parent     » topic index » view message » categorize

7. Re: Fun Test Problem

Kat said...

And don't you think the count will go up with the 5000 word dictionary?

Kat, I think you are missing an important point in the problem description. The input to the program will always contain the entire dictionary of known words.

So in the example given the we know that there are only five known words in total. The patterns given are to be matched against only those five words, and thus all other possible words are to be ignored.

Kat said...

note to Derek that the triple brackets he edited my previous post with are not in the online help sections of the reply pages of euphorum

Thanks Kat. I did know that and I thought the best way of explaining this tag would be to demonstrate its usage. There are also many other capabilities of Creole that are not mentioned in the "More Common Formatting" docs. I've asked, long ago, for a link to be placed in this area to a wiki page that would explain the full Creole usage.

new topic     » goto parent     » topic index » view message » categorize

8. Re: Fun Test Problem

DerekParnell said...

There are also many other capabilities of Creole that are not mentioned in the "More Common Formatting" docs. I've asked, long ago, for a link to be placed in this area to a wiki page that would explain the full Creole usage.

In the euweb svn, modifying source/templates/forum/post.etml should fix this.

I just added an example of this to the devel forum at http://demonology.redirectme.net/forum.wc (the reply link should bring up the reply page with the extra "To see even more formatting options, click here." link in it). post.etml itself is located in /home/demonology/euweb/source/templates/forum/post.etml on that server.

new topic     » goto parent     » topic index » view message » categorize

9. Re: Fun Test Problem

DerekParnell said...
Kat said...

And don't you think the count will go up with the 5000 word dictionary?

Kat, I think you are missing an important point in the problem description. The input to the program will always contain the entire dictionary of known words.

So in the example given the we know that there are only five known words in total. The patterns given are to be matched against only those five words, and thus all other possible words are to be ignored.


Actually, the point i was missing was: "where X is the test case number, starting from 1, and K indicates how many words in the alien language match the pattern.", not which words are matched.

David Cuny got me started on a spell checker years ago, and i think the only thing it doesn't do is count how many possible matches there are, tho it does everything else.

useless

new topic     » goto parent     » topic index » view message » categorize

10. Re: Fun Test Problem


So i misread the contest, filtering it thru my experience of finding typo'd words from a dictionary. To atone i'll give up the following bit of trivia.

In news.ex,

1)
put "without warning" at the top to suppress some warning i don't care about.

2)
in procedure search_url(),
before the line "sequence mytemp = get_url(url) go get the url",
insert "task_yield() --
let all the tasks print their existance right away",
so the screen gets instantly populated.

useless

new topic     » goto parent     » topic index » view message » categorize

11. Re: Fun Test Problem

DerekParnell said...

Using Euphoria 4 syntax ... <snip...>

Someday, I'll get around to downloading v4 and play with it. I haven't had much time for Euphoria programming lately, but I had some down time at work, saw this post while lurking, noticed nobody had attempted it, and thought I'd give it a try.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu