Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NIO 2003: Lingo (simple challenge)
#1
The game Lingo is the subject of a daily TV Game of ID-TV that is broadcasted by the TROS and other foreign broadcasting companies.
The goal in Lingo is to guess a word of 5 letters. The first letter of the word is always given. De player inputs an existing word beginning with the specified letter. All letters that are on good postion are marked (in this challenge with a "+"), and letters that are in the word, but not on the right position, are marked differently (here with a "/"). Letters that don't occur in the word are marked by a "." (colon, point).
[Image: lingo.jpg]

In this challenge your program's input is the word to be guesed. Also they receive a list with allowed words; these 8179 words are in the file words.dat (DOWNLOAD HERE) with every word on one line. The words are all in capitals, in alphabetic sorting (ascending). They're English words, so that problems with the IJ or Y in Dutch don't occur.

Your programs in the parts A, B and C research the behaviour of a computerplayer that plays according to the following algorithm: All words that, according to the known information, are not valid are left out. The word that is guessed by the computer is the first word in the list of words that are still available.


Example: The word to be guessed is ZYMES
The previously described player plays as follows:
Code:
1: ZAIRE   +.../
2: ZEBEC   +..+.
3: ZONED   +..+.
4: ZYMES   +++++

Input
The to be guessed word is in a file LINGO.IN which consists of 1 line. On this line there is a word of 5 capital letters. This word also occurs in the words.dat file.
Example LINGO.IN: ZYMES

NOTE: This file is used as example input in all problems.


Overview
Code:
Part A: timelimit: 2 sec; outputfile: 1a.out; max points: 16;
Part B: timelimit: 5 sec; outputfile: 1b.out; max points: 24;
Part C: timelimit: 5 sec; outputfile: 1c.out; max points: 27;
Part D: timelimit: 10 sec; outputfile 1d.out; max points: 33;


Problem A
Write a program nio1a that reads from a file LINGO.IN. The program outputs a file 1a.out consisting of one line. On this line is the information the computerplayer gets when it chose the first word from the valid-words-list with the correct beginning letters (in the example this word is ZAIRE).

Output on given example: +.../

Problem B
Write a program nio1b that reads from a file LINGO.IN. The program outputs a file 1b.out consisting of one line. On that line is indicated how many words after the information of Problem A are still valid for a good solution.

Output on given example: 7

Problem C
Write a program nio1c that reads from a file LINGO.IN. The program outputs a file 1c.out consisting of a number of lines. On every line there is a word that is guessed by the computer player. The last line obviously contains the to-be-guessed word. Hereby the computer player plays with the algorithm as defined in the introduction.

Output on given example:
ZAIRE
ZEBEC
ZONED
ZYMES

Problem D
In this problem, you look for a largest collection of words that, except for the beginning letter, have no other letters in common.
Write a program nio1d that reads from a file LINGO.IN. The program outputs a file 1d.out consisting of a number of lines. On every line there is a word from the previously described collection. The words are on alphabetic sorting. The last line of the file is always the word "ready" (lower case).

Output on given example:
ZANZA
ZILCH
ready


Well, this was one of the problems I had to do in the 2nd round of NIO 2003 Wink I didn't score very good on this problem, I scored a total of 16 points for A, B, C and D together (that's very bad). However, I was able to end up 3rd because I scored a massive amount of points on NIO 2003 Problem 2, 3, and 4. (Note that NIO 2003 Problem 3 was the problem "Recognising Letters", which I posted in a topic a while back). (Btw, NO ONE had points for Problems C and D, and I was one of the three people who had 12 points for Problem B).
The timelimit for this complete problem (A, B, C and D together) was about 1 hour, however, you all may take as much time as you like! Big Grin

Have fun! Big Grin (You'll probably all score higher than I did! Tongue)
Reply
#2
Words.dat and lingo.in should be in a .\lingo\ subdirectory.

I got done with part C before an hour, but here it's all combined into one program:

Code:
DECLARE SUB NoCommon ()
DECLARE SUB GetMask ()
DECLARE SUB Cull ()
DEFINT A-Z
DECLARE FUNCTION IsValid! ()

DIM SHARED Guess$, Target$, Mask$, Test$, NumGood

'File number constants
CONST Lingo = 1
CONST Valid = 2
CONST AOut = 3
CONST BOut = 4
CONST COut = 5
CONST Temp = 6
CLS

Mask$ = "+...."

OPEN ".\lingo\lingo.in" FOR INPUT AS #1
INPUT #1, Target$
CLOSE 1

PRINT "Largest group of words with no shared letters except the first:"
NoCommon
PRINT

Guess$ = LEFT$(Target$, 1) + "    "
PRINT "First Letter: ", Guess$

OPEN ".\lingo\words.dat" FOR INPUT AS #1
OPEN ".\lingo\valid.dat" FOR OUTPUT AS #2

DO
  LINE INPUT #1, Test$
  IF IsValid THEN
    PRINT #2, Test$
  END IF
LOOP UNTIL EOF(1)

CLOSE

PRINT "Guess:", "Result:", "Valid Entries Remaining:"

DO
  Cull

  OPEN ".\lingo\valid.dat" FOR INPUT AS Valid
  INPUT #Valid, Guess$
  CLOSE #Valid

  GetMask
  OPEN ".\lingo\1c.out" FOR APPEND AS #COut
  PRINT #COut, Guess$
  CLOSE

  PRINT Guess$, Mask$, NumGood
LOOP UNTIL Guess$ = Target$

SUB Cull

NumGood = 0

OPEN ".\lingo\valid.dat" FOR INPUT AS Valid
OPEN ".\lingo\temp" FOR OUTPUT AS Temp

DO
  INPUT #Valid, Test$
  IF IsValid AND (Test$ <> Guess$) THEN PRINT #Temp, Test$
LOOP UNTIL EOF(Valid)

CLOSE

OPEN ".\lingo\temp" FOR INPUT AS #Temp
OPEN ".\lingo\valid.dat" FOR OUTPUT AS #Valid

DO
  INPUT #Temp, s$
  PRINT #Valid, s$
  NumGood = NumGood + 1
LOOP UNTIL EOF(Temp)

'PRINT "Remaining: "; NumGood
OPEN ".\lingo\1b.out" FOR APPEND AS #BOut
PRINT #BOut, NumGood

CLOSE



END SUB

SUB GetMask

Mask$ = ""

FOR n = 1 TO 5
  s$ = MID$(Guess$, n, 1)
  a$ = "."
  IF INSTR(Target$, s$) THEN a$ = "/"
  IF MID$(Target$, n, 1) = s$ THEN a$ = "+"
  Mask$ = Mask$ + a$
NEXT

'Note: For challange, change 'APPEND' to 'OUTPUT'

OPEN ".\lingo\1a.out" FOR APPEND AS #AOut
PRINT #AOut, Mask$
CLOSE #AOut


END SUB

DEFSNG A-Z
SUB GetNext

OPEN "./lingo/valid.dat" FOR INPUT AS Valid
INPUT #Valid, Guess
PRINT Guess
CLOSE Valid


END SUB

FUNCTION IsValid

IsValid = 1

FOR n = 1 TO 5
  s$ = MID$(Mask$, n, 1)
  IF s$ = "+" THEN
    IF MID$(Test$, n, 1) <> MID$(Guess$, n, 1) THEN IsValid = 0
  END IF

  IF s$ = "/" THEN
    IF INSTR(Test$, MID$(Guess$, n, 1)) = 0 THEN IsValid = 0
    IF MID$(Guess$, n, 1) = MID$(Test$, n, 1) THEN IsValid = 0
  END IF

  IF s$ = "." THEN
    IF INSTR(Test$, MID$(Guess$, n, 1)) > 0 THEN IsValid = 0
  END IF

NEXT

END FUNCTION

DEFINT A-Z
SUB NoCommon
s$ = LEFT$(Target$, 1)
k$ = RIGHT$(Target$, 4)

OPEN ".\lingo\words.dat" FOR INPUT AS #1
OPEN ".\lingo\1d.out" FOR OUTPUT AS #2

DO
  LINE INPUT #1, a$
  IF LEFT$(a$, 1) = s$ THEN
    Bad = 0
    a$ = RIGHT$(a$, 4)

    FOR n = 1 TO LEN(k$)
      IF INSTR(a$, MID$(k$, n, 1)) THEN Bad = 1
    NEXT

    IF Bad = 0 THEN
      PRINT s$; a$
      PRINT #2, s$; a$
      k$ = k$ + a$
    END IF
  END IF
LOOP UNTIL EOF(1)

PRINT #2, "ready"
CLOSE


END SUB

The output files have more than one line because the program goes through the whole algorithm, but oh well, it's easy enough to change.


Would I get bonus points for writing it on a computer without a mouse?
Reply
#3
Ah, an entry Big Grin

I've tested your program, and I start with the following: you have more points than I received back then Tongue (doh!)
Here's the result scheme (I don't show the words I've used, else it's no fun anymore Big Grin):

1st Test Points: 4, 6, 6.75, 0
2nd Test Points: 4, 6, 6.75, 0
3rd Test Points: 4, 6, 6.75, 0
4th Test Points: 4, 6, 6.75, 0
Total points: 16+24+27+0=67

Congratulations!
(NOTE: Note that making this exercise under the circumstances I was in, would have been much harder).
Quote:Would I get bonus points for writing it on a computer without a mouse?
No.

_______________________


Now, as for the rest of you... you can surely improve that record! Wink
Moneo... Meg... Relsoft... NaThan... the rest... Wink
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)