Difference between revisions of "Activity assignment 1"
Jump to navigation
Jump to search
Line 12: | Line 12: | ||
* 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>. | * 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> | ||
+ | |||
+ | * Create a function that gets a string <code>line</code> and a list of pairs - <code>[(Int,Int)]</code>. Each of these pairs contain two indexes (starting from 0) ant it describes a swap between two positions in the original string <code>line</code>. Function returns the original string where all these swaps have been applied. | ||
<syntaxhighlight lang="Haskell" > | <syntaxhighlight lang="Haskell" > | ||
count :: String -> String -> Int | count :: String -> String -> Int |
Revision as of 10:18, 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 charactera
is multipliedn
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
andb
. It will print how many times the stringa
contains the stringb
.
count :: String -> String -> Int
count "AbcAbcabcAbc" "Abc" = 3
- Create a function that gets a string
line
and a list of pairs -[(Int,Int)]
. Each of these pairs contain two indexes (starting from 0) ant it describes a swap between two positions in the original stringline
. Function returns the original string where all these swaps have been applied.
count :: String -> String -> Int
count "AbcAbcabcAbc" "Abc" = 3