Program this!, Programming thread |
Program this!, Programming thread |
![]()
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:
|
|
|
![]() |
![]()
Post
#2
|
|
![]() Senior Member ![]() ![]() ![]() ![]() ![]() ![]() Group: Administrator Posts: 2,648 Joined: Apr 2008 Member No: 639,265 ![]() |
Haskell
CODE matchesPattern1 s = mp s (0, 0, 0) where mp [] (a, b, c) = a + b == c mp (x:xs) (a, b, c) | x == 'a' = mp xs ((a + 1), b, c) | x == 'b' = mp xs (a, (b + 1), c) | x == 'c' = mp xs (a, b, (c + 1)) matchesPattern2 s = mp s (0, 0, 0) (False, False, False) where mp [] (a, b, c) _ = a + b == c mp (x:xs) (a, b, c) (sa, sb, sc) | x == 'a' = if sb || sc then False else mp xs ((a + 1), b, c) (True, sb, sc) | x == 'b' = if sc then False else mp xs (a, (b + 1), c) (sa, True, sc) | x == 'c' = mp xs (a, b, (c + 1)) (sa, sb, True) matchesPattern3 s = mp s (0, 0, 0) (False, False, False) where mp [] (a, b, c) _ = (a == c) && (a > 0) mp (x:xs) (a, b, c) (sa, sb, sc) | x == 'a' = if sb || sc then False else mp xs ((a + 1), b, c) (True, sb, sc) | x == 'b' = if sc then False else mp xs (a, (b + 1), c) (sa, True, sc) | x == 'c' = mp xs (a, b, (c + 1)) (sa, sb, True) Source: Matcher.hs |
|
|
![]() ![]() |