Difference between revisions of "Activity assignment 1"

From Marek Běhálek Wiki
Jump to navigation Jump to search
Line 11: Line 11:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
* Create
+
* Create a function that takes two strings - <code>a</code> and <code>b</code>. It will print how many times the string <code>a</code> contains the string <code>b</code>.
 +
<syntaxhighlight lang="Haskell" >
 +
count :: String -> String -> Int
 +
</syntaxhighlight>
 +
<syntaxhighlight lang="Haskell" class="myDark" >
 +
count "AbcAbcabcAbc" "Abc" = 3
 +
</syntaxhighlight>

Revision as of 10:14, 11 November 2019

Activity assignments

Implement following functions. There will be 5 points for each of these functions.

  • Create a function that gets a list of tuples - [(Int, Char)]. This function takes these pairs and for each of these pairs (n, a) generates a string where the character a is multiplied n times. The function result is a concatenation of these sub-strings.
create :: [(Int, Char)] -> String
create [(2,'a'), (3,'B')] = "aaBBB"
  • Create a function that takes two strings - a and b. It will print how many times the string a contains the string b.
count :: String -> String -> Int
count "AbcAbcabcAbc" "Abc" = 3