Liberty BASIC Community Forum
« Mad Lib Game Voting »

Welcome Guest. Please Login or Register.
Jun 25th, 2017, 12:24am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 poll_icon_closed  Poll  Poll Question: Which code best demonstrates Liberty BASIC?
meerkat 1 VotesImageVotes 0 (0%)
Dan Teel VotesVotesVotes 3 (75%)
tsh73 VotesImageVotes 0 (0%)
meerkat 2 VotesVotesVotes 1 (25%)
Total votes: 4  
 thread  Author  Topic: Mad Lib Game Voting  (Read 527 times)
Admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 14484
xx Mad Lib Game Voting
« Thread started on: Mar 8th, 2012, 11:19am »

Please vote for the code (below) that best represents Liberty BASIC. The winner will be placed on the Open Source Board for further discussion/tweaking and inclusion on Rosetta Code.

Mad Libs

Thanks, Dan, Dan (meerkat), and Anatoly. Great stuff!

Code:
'meerkat 1:
template$ = "<name> went for a walk in the park. " _
+ " <he or she> found a <noun>. <name> decided to take it home."
[loop]
i    = i + 1
i     = instr(template$,"<",i)
if i <> 0 then
    j    = instr(template$,">",i)
    a$    = mid$(template$,i,j-i + 1)
    print "Give me a name for ";a$
    input n$
    template$ = strRep$(template$,a$,n$)
    goto [loop]
end if
print template$
wait
FUNCTION strRep$(str$,rep$,with$)
ln    = len(rep$)
ln1    = ln - 1
i    = 1
while i <= len(str$)
    if mid$(str$,i,ln) = rep$ then
        strRep$ = strRep$ + with$
        i = i + ln1
    else
        strRep$ = strRep$ + mid$(str$,i,1)
    end if
i = i + 1
WEND
END FUNCTION
 

Code:
'Dan Teel:
temp$="<name> went for a walk in the park. <he or she> found a <noun>. <name> decided to take it home."

while word$(temp$,2,"<")<>""
    what$=word$(word$(temp$,2,"<"),1,">")
    input "";what$;": ";rep$
    temp$=strrep$(temp$,"<";what$;">",rep$)
wend

print temp$

function strrep$(str$,what$,with$)
    for i=1 to len(str$)
        if mid$(str$,i,len(what$))=what$ then
            strrep$=strrep$+with$
            i=i+len(what$)-1
        else
            strrep$=strrep$+mid$(str$,i,1)
        end if
    next i
end function
 

Code:
'tsh73:
CrLf$=chr$(13)+chr$(10)
txt$=""
txt$=txt$+      "<name> went for a walk in the park. <he or she>"
txt$=txt$+CrLf$+"found a <noun>. <name> decided to take it home."

'print txt$

keys$=""        '01<key1>02<key2> etc...
dim value(99)   'NN
N=0

txt2$=""
p2=0

while 1
    p1=instr(txt$, "<", p2)
    if not(p1) then exit while
    txt2$=txt2$+mid$(txt$, p2+1,(p1-p2-1))
    p2=instr(txt$, ">", p2+1)
    key$=mid$(txt$, p1,(p2-p1+1))
    k=instr(keys$, key$)
    if k then
        NN=val(mid$(keys$, k-2, 2))
        repl$=value$(NN)
    else
        N=N+1
        input "Enter replacement for ";key$;" :";repl$
        value$(N)=repl$
        keys$=keys$+using("##",N);key$ 
    end if
    txt2$=txt2$+ repl$ 
wend
txt2$=txt2$+mid$(txt$, p2+1)
print "-------------------------"
'print keys$
print txt2$
 

Code:
'meerkat 2:
template$ = "<name> went for a walk in the park. " _
+ " <he or she> found a <noun>. <name> decided to take it home."
i    = instr(template$,"<",i)
while i
    j    = instr(template$,">",i)
    a$    = mid$(template$,i,j-i + 1)
    print "Give me a name for ";a$;
    input n$
     k   = instr(template$,a$)
    while k
        template$ = left$(template$,k - 1) + n$ + mid$(template$,k + len(a$))
         k   = instr(template$,a$)
    wend
    i    = instr(template$,"<",i)
wend

print template$
wait
 
User IP Logged

tsh73
Moderator
ImageImageImageImageImage


member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1661
xx Re: Mad Lib Game Voting
« Reply #1 on: Mar 9th, 2012, 04:26am »

Alyce,
Please draw the deadline for voting.
User IP Logged

The existence of bug reports means somebody is using the software and actually cares to report back to you that he is having a problem with it, instead of just deleting it from their hard disk.
(Janusz Marcin Gorycki)
Admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 14484
xx Re: Mad Lib Game Voting
« Reply #2 on: Mar 9th, 2012, 05:15am »

on Mar 9th, 2012, 04:26am, tsh73 wrote:
Alyce,
Please draw the deadline for voting.


Anatoly, pardon my confusion. Are you asking for a deadline for the voting to end?

Or, are you asking for a deadline for people to enter?

The contest was meant to be very casual with no particular time-frame. I waited until we had several good entries, which happened quite quickly. At that point I opened the polls.

If you want a deadline for the polls to be closed, shall we say Saturday? (That is tomorrow.)

Thanks again to all who participated or voted.

Let's do this again! If you find a task not yet completed in Liberty BASIC that would make a good, small contest/challenge, let us know. Post it here on this voting thread. Janet is suggesting the deranged anagram task. wink
User IP Logged

Admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 14484
xx Re: Mad Lib Game Voting
« Reply #3 on: Mar 9th, 2012, 05:18am »

I'd also like to point out that RC solutions are not "set in stone". Rosetta Code is a wiki and is always changing. If we find a better (or additional) solution to any task, we can update it.

We'll put the contest winner on the Open Source board for discussion and tweaking (maybe with your newest code!) before we add it to the RC page.

« Last Edit: Mar 9th, 2012, 05:21am by Admin » User IP Logged

tsh73
Moderator
ImageImageImageImageImage


member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1661
xx Re: Mad Lib Game Voting
« Reply #4 on: Mar 10th, 2012, 06:27am »

Quote:
If you want a deadline for the polls to be closed, shall we say Saturday? (That is tomorrow.)

I meant just that.
Saturday sounds fine for me.
« Last Edit: Mar 11th, 2012, 08:08am by tsh73 » User IP Logged

The existence of bug reports means somebody is using the software and actually cares to report back to you that he is having a problem with it, instead of just deleting it from their hard disk.
(Janusz Marcin Gorycki)
Admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 14484
xx Re: Mad Lib Game Voting
« Reply #5 on: Mar 11th, 2012, 06:15am »

Congrats, Dan Teel!

Look for your code on the Open Source Board for the Rosetta Code project.

Thanks, everybody!
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls