Log In · Register

 
Program this!, Programming thread
mipadi
post Mar 23 2009, 09:27 AM
Post #1


Senior Member
******

Group: Administrator
Posts: 2,648
Joined: Apr 2008
Member No: 639,265



I'm of the understand that there are a few Technology forum aficionados that are programmers, or are at least interested in programming, so I thought I'd start a thread -- a sort of game. The game was inspired by this thread. It's pretty simple: just implement the following program in whatever language you desire. If someone's already posted a program in your favorite language, see if you can do better! You get bragging rights if you implement the program in a weird/unusual/rare language.

Here are the guidelines for the program:

  1. Write a method named matchesPattern1() that accepts a String as input. This method determines whether or not the input String has the following property:

    The string has a number of c's equal to the total number of a's and b's.

    In other words, every word in this language is of the form:

    anbmc(n + m), where n ≥ 0 and m ≥ 0.

    n and m may be equal, but this is not required.

    Thus, bc, abccac, aabbcccc and abbbbccccc are all valid words in this language.

    Your method should return a boolean value: true if the input string satisfies these requirements, and false if it does not.

    For example, given a String such as aabbcc, your method should return false.
  2. Write a method named matchesPattern2() that accepts a String as input. This method determines whether or not the input String has the following properties:

    The string has a number of c's equal to the total number of a's and b's.
    All a's come before any b's, and all b's come before any c's. (HINT: Can you test for this using one or more boolean variable "flags"?)


    In other words, every word in this language is of the form:

    anbmc(n + m), where n ≥ 0 and m ≥ 0.

    n and m may be equal, but this is not required.

    Thus, aabbcccc and abbbbccccc are valid words in this language, but abaccc and abc are not.

    Your method should return a boolean value: true if the input string satisfies these requirements, and false if it does not.

    For example, given a String such as aabbcc, your method should return false.

    This pattern is identical to the one above, except it imposes a specific ordering requirement on the input string.
  3. Write a method named matchesPattern3() that accepts a String as input. This method determines whether or not the input String has the following properties:

    The string has an equal (nonzero) number of a's and c's, and any number of (zero or more) b's.
    All a's come before any b's, and all b's come before any c's.


    In other words, every word in this language is of the form:

    anb*cn, where n > 0.

    Thus, aabbcc and ac are valid words in this language, but abaccc and aabc are not.

    Your method should return a boolean value: true if the input string satisfies these requirements, and false if it does not.

    For example, given a String such as aabbaa, your method should return false.
 
 
Start new topic
Replies
heyo-captain-jac...
post Mar 23 2009, 10:35 AM
Post #2


/人◕‿‿◕人\
*******

Group: Official Member
Posts: 8,283
Joined: Dec 2007
Member No: 602,927



Any specific language we have to use?

I might start on this later.
 
mipadi
post Mar 23 2009, 12:09 PM
Post #3


Senior Member
******

Group: Administrator
Posts: 2,648
Joined: Apr 2008
Member No: 639,265



QUOTE(9001 @ Mar 23 2009, 11:35 AM) *
Any specific language we have to use?

I might start on this later.

No, use whatever you want. (But if I have a way to run the program, I might check it.)

QUOTE(Uronacid @ Mar 23 2009, 11:38 AM) *
Like that?

It looks good, but I haven't run it.

Maybe I should post a text file with some valid/invalid strings that programs can be checked against...
 
Uronacid
post Mar 23 2009, 01:11 PM
Post #4


Senior Member
******

Group: Official Member
Posts: 1,574
Joined: Aug 2007
Member No: 555,438



QUOTE(mipadi @ Mar 23 2009, 01:09 PM) *
No, use whatever you want. (But if I have a way to run the program, I might check it.)
It looks good, but I haven't run it.

Maybe I should post a text file with some valid/invalid strings that programs can be checked against...


you can just copy it to a text file and change to extension to *.vbs double click it and it will run.
 
mipadi
post Mar 23 2009, 06:41 PM
Post #5


Senior Member
******

Group: Administrator
Posts: 2,648
Joined: Apr 2008
Member No: 639,265



QUOTE(Uronacid @ Mar 23 2009, 02:11 PM) *
you can just copy it to a text file and change to extension to *.vbs double click it and it will run.

Yeah, but I don't have an interpreter for VBScript.
 
Uronacid
post Mar 23 2009, 09:25 PM
Post #6


Senior Member
******

Group: Official Member
Posts: 1,574
Joined: Aug 2007
Member No: 555,438



QUOTE(mipadi @ Mar 23 2009, 07:41 PM) *
Yeah, but I don't have an interpreter for VBScript.


You don't have windows?
 
mipadi
post Mar 23 2009, 09:39 PM
Post #7


Senior Member
******

Group: Administrator
Posts: 2,648
Joined: Apr 2008
Member No: 639,265



QUOTE(Uronacid @ Mar 23 2009, 10:25 PM) *
You don't have windows?

Negative; I use Mac OS X.

(Well, I have a Windows machine that I could run it on, except it's not on and I don't feel like turning it on right now. _smile.gif But I spent four years writing web apps in VBScript, so I understand the code quite well.)
 

Posts in this topic
mipadi   Program this!   Mar 23 2009, 09:27 AM
mipadi   Haskell CODEmatchesPattern1 s = mp s (0, 0, 0...   Mar 23 2009, 09:28 AM
mipadi   Erlang CODE-module(matcher). -export(...   Mar 23 2009, 09:29 AM
Uronacid   I'd love to do this, but "anbmc(n + m), w...   Mar 23 2009, 10:21 AM
mipadi   QUOTE(Uronacid @ Mar 23 2009, 11:21 AM) I...   Mar 23 2009, 10:24 AM
Uronacid   QUOTE(mipadi @ Mar 23 2009, 11:24 AM) It...   Mar 23 2009, 10:38 AM
9001   Any specific language we have to use? I might sta...   Mar 23 2009, 10:35 AM
mipadi   QUOTE(9001 @ Mar 23 2009, 11:35 AM) Any s...   Mar 23 2009, 12:09 PM
Uronacid   QUOTE(mipadi @ Mar 23 2009, 01:09 PM) No,...   Mar 23 2009, 01:11 PM
mipadi   QUOTE(Uronacid @ Mar 23 2009, 02:11 PM) y...   Mar 23 2009, 06:41 PM
Uronacid   QUOTE(mipadi @ Mar 23 2009, 07:41 PM) Yea...   Mar 23 2009, 09:25 PM
mipadi   QUOTE(Uronacid @ Mar 23 2009, 10:25 PM) Y...   Mar 23 2009, 09:39 PM
Uronacid   QUOTE(mipadi @ Mar 23 2009, 10:39 PM) Neg...   Mar 23 2009, 10:19 PM
9001   Cool. I'll see if I can somehow get this done...   Mar 23 2009, 12:15 PM
mipadi   Ruby CODEdef matches_pattern_1?(s) if s ...   Mar 23 2009, 12:32 PM
mipadi   C CODE#include <stdio.h> #include <str...   Mar 23 2009, 01:05 PM
mipadi   Python CODEdef matches_pattern_1(s): ...   Mar 23 2009, 07:21 PM
mipadi   Hey! There are more programmers than just the ...   Apr 5 2009, 01:55 PM
9001   QUOTE(mipadi @ Apr 5 2009, 12:55 PM) Hey...   Apr 5 2009, 02:44 PM
mipadi   QUOTE(9001 @ Apr 5 2009, 03:44 PM) At lea...   Apr 5 2009, 02:47 PM
mipadi   Objective-C This one isn't dramatically diffe...   Apr 5 2009, 02:30 PM


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members: