I can't believe I've gone about a month without posting another challenge. Time to set things right Graphing Calculator

Hello Omnimaga/CodeWalrus/Cemetech/friends/Romans/countrymen/lend/me/your/ears, and welcome to the ninth installment of...
Code Golf: The Reboot

As you can see, I am @JWinslow23 , the guy who started this idea in the first place. You may recall my weird fifth challenge I devised, and if you do, I'm doing something just as sinister.

Don't know what code golf is? Check out this contest thread OR this really old contest thread for an explanation. Don't know what code is? Then you will not understand this website in general Razz

Without further ado...

Challenge 9

Problem

Family Feud is a game show where you try to guess the most popular responses to survey questions, such as "Name something people often steal from the office to use at home", "Name something that gets hard when it gets cold", or "Tell me a famous Dennis". This, of course, has been adapted into many video game ports, including one in 1993 on the Super Nintendo Entertainment System (SNES).

Now, the SNES version has one glitch that makes the game that much more funny: as long as there are the right letters in the right order, the game counts it as correct. This can lead to some rather interesting answers being counted, as seen in this video.

Based on this, here is your challenge: Create a program that, given a string containing a typed-in answer, and another string containing all the accepted answers (encoded in a format explained below), tells the user the answer they matched, and if no answer was matched, tells the user they got a strike.

Let me explain:

The string with the possible answers the game will accept will be encoded and interpreted as follows:
    Answers will be written in uppercase letters.
    Backslashes "" separate multiple valid answers for a given entry.
    Optional parts of answers are enclosed by a pair of underscores "_", i.e. "_RED_ MEAT" means that "RED MEAT" and "MEAT" are both valid.
    A caret "^" indicates that the following character is optional, i.e. "PICKLE^S" means that "PICKLES" and "PICKLE" are both valid.
    Spaces are usually optional (except in special cases). For the purposes of the contest, they are always optional.
    Any double letters are always optional, e.g. "RACCOON" means that "RACCOON" and "RACON" are both valid.

Input for your program will be in the form of "ANSWER YOU TYPED IN:POSSIBLE ANSWER 1:POSSIBLE ANSWER 2:ETC". Output for your program will be in the form of either the lowest answer on the board that it matches, or "STRIKE!" if it matches no answers. To clarify, here are examples:


Code:
Input: "CLEANER FLUID:CAR\AUTO:CLOTH_ES_:_KITCHEN_ FLOOR:BODY:TOWEL^S:BATHROOM:DISH_ES_"
Output: "CAR\AUTO"

Input: "FABULOUS DIET WATER:CLOTH_ES_\SHOES:FAT\WEIGHT:BILLS:FOOD:TIME"
Output: "FOOD"

Input: "CODE GOLF CONTEST EIGHT:SOCK^S\HOSE\STOCKINGS\NYLONS:PURSE^S\POCKETBOOK\BAG:POLISH:LACES"
Output: "STRIKE!"


If any more clarification is needed, contact me. I'll try not to give you COMMANDS FOR US INVASION... (whoops, I mean CONFUSION Razz )

Scoring

All non-calc languages will be scored with this counter.
Assembly programs will be scored on binary size (minus the header), and TI-BASIC and Axe will be scored on on-calc source size (again, minus the header). For Axe, the entire first line (for example, ".PROGNAME") does not count.

Submission

PM me over on Omnimaga, Cemetech, or CodeWalrus with the code, or make an unlisted YouTube video and PM me the link. (If you take the latter option, then congrats for you Razz )

Good luck! I wanna see if Feud come up with clever answers!

Head over to Codewalrus or Omnimaga for a nicely formatted table of the winners so far.

Here is the code for the SysRPL, C, and Java entries, respectively. I guess the contest died, even I didn't notice it was already over. But hey, it was fun. Smile


Code:
::
  ' :: OVERSWAP BINT1 POSCHR
    DUP#0=csedrp NULL$SWAP
    2DUP #!+LAST$ UNROT
    1_#1+SUB$ ;
  'NOP 2NULLLAM{}_ BIND
  CHR_: 2GETEVAL 1PUTLAM BEGIN
    CHR_: 2GETEVAL DUP BEGIN
      CHR \5C 2GETEVAL
      ONEONE BEGIN
        3PICKOVER
        OVERLEN$ OVER#< case
        :: 3RDROP 6DROP
          SWAPDROP ABND ;
        SUB$1#
        BINT32 OVER#=case
        :: DROP #1+ AGAIN ;
        BINT94 OVER#=case
        :: DROP #2+ AGAIN ;
        BINT95 OVER#=case
        :: DROP3PICK tokuscore_
          ROT#1+ POS$ #1+ AGAIN ;
        1GETLAM $PICK SUB$1#
        #=ITE #1+ SWAP#1+SWAP
      1GETLAM LEN$ 3PICK #< UNTIL
    3DROP DUPNULL$? UNTIL
  2DROP DUPNULL$? UNTIL
  DROP ABND "STRIKE!"
;



Code:
#include<stdio.h>
main(int c,char**v){char*i,*a,*s=v[1];while(1){while(*s&&*s!=58&&*s!=92)++s;if(!*s)break;if(*s++==58)a=s;i=v[1];while(*i!=58)switch(*s){case 0:case 58:case 92:while(*a&&*a!=58)printf("%c",*a++);return;case 94:++s;case 32:++s;break;case 95:++s;while(*s++!=95);break;default:if(*i==*s)++s;else++i;}}printf("STRIKE!");}



Code:
class G{public static void main(String[]c){c=c[0].split(":");for(int n=0;++n<c.length;)for(String s:c[n].split("\\\\"))for(int x=0,y=0;x<c[0].length(){if(y>=s.length()){System.out.print(c[n]);return;}switch(s.charAt(y)){case 94:++y;case 32:++y;break;case 95:y=s.indexOf(95,y+1)+1;break;default:if(c[0].charAt(x)==s.charAt(y))++y;else++x;}}System.out.print("STRIKE!");}}
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement