Commit e2fbc7f9 by Christoph Ruegge

### Pipe all notebooks through clean filter

parent 545381c7
 { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Exercises 02\n", "## problem 1\n", "\n", "- start the notebook\n", "- evaluate $2^{16}$\n", "- write a statement which checks if $2^{23} - 1000$ is greater than $2^{22.9999}$ (what is the difference between ** and ^?)\n", "- is $23 \\cdot 5 > 45 \\wedge ( 169/3 = 56 \\vee 4 = (53\\cdot3) \\% 5 )$ true or false?" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## problem 2\n", "\n", "\n", "write an own function tenfoldIfLess30, which multiplies numbers under 30 with 10. " ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## problem 3\n", "\n", "Write a function divbl2or3 which returns True for numbers which are dividable by 2 or 3 and False otherwise. " ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## problem 4\n", "\n", "implement the following functions:\n", "\n", "$f : \\mathbb{N}^3 \\to \\mathbb{N}$ with $f(x,y,z)= (x+y+z)/3$\n", "\n", "$g : \\mathbb{N}^3 \\to \\mathbb{N}$ with $g(a,b,c)=\\begin{cases}a :\\quad a > b,c\\\\b :\\quad b > a,c\\\\c : \\quad c \\geq a,b\\end{cases}$\n", "\n", "$h : \\mathbb{N}^2 \\to \\mathbb{N}$ with $h(i,j)=\\begin{cases}i :\\quad j=0\\\\ succ(h(i,j-1)) : \\quad otherwise\\end{cases}$" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## problem 5\n", "\n", "- write your own implementation of even'.\n", "- Look up even in _Hoogle_ () and/or\n", "\t_Hayoo!_ () (rem is aquivalent to mod for positive numbers).\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## problem 6\n", "\n", "the imaginary weather prediction module Magic.Weather.Prediction creates the variables \n", "\n", "\trainy :: Bool\n", "\tcold :: Bool\n", "\twindy :: Bool\n", "\n", "(assume that they are filled)\n", "\n", "Use if ... then ... else (and boolean operators) to return the following strings:\n", "\n", "- \"fly kites\" _(when windy but not rainy)_\n", "- \"take your umbrella\"\t_(when rainy but not cold)_\n", "- \"sit at the fireplace\" _(when rainy and cold)_\n", "- \"enjoy the sun\" _(when not rainy or windy)_\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## problem 7\n", "\n", "Brackets get very expensive. Try to reduce the number of brackets via using of the application operator $ from the following expressions:\n", "\n", "- max 23 (max 5 39)\n", "- max 23 (5 * (succ 4))\n", "- mod 23 (min 7 ((*) 2 3))\n", "- min (max 23 44) (max 5 (negate (-39)))\n", "\n", "Which brackets are redundant anyway? \n", "Which expression is an identity?" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Haskell", "language": "haskell", "name": "haskell" }, "language_info": { "codemirror_mode": "ihaskell", "file_extension": ".hs", "name": "haskell", "version": "7.10.3" } }, "nbformat": 4, "nbformat_minor": 0 } \ No newline at end of file "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Exercises 02\n", "## problem 1\n", "\n", "- start the notebook\n", "- evaluate$2^{16}$\n", "- write a statement which checks if$2^{23} - 1000$is greater than$2^{22.9999}$(what is the difference between ** and ^?)\n", "- is$23 \\cdot 5 > 45 \\wedge ( 169/3 = 56 \\vee 4 = (53\\cdot3) \\% 5 )$true or false?" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## problem 2\n", "\n", "\n", "write an own function tenfoldIfLess30, which multiplies numbers under 30 with 10. " ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## problem 3\n", "\n", "Write a function divbl2or3 which returns True for numbers which are dividable by 2 or 3 and False otherwise. " ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## problem 4\n", "\n", "implement the following functions:\n", "\n", "$f : \\mathbb{N}^3 \\to \\mathbb{N}$with$f(x,y,z)= (x+y+z)/3$\n", "\n", "$g : \\mathbb{N}^3 \\to \\mathbb{N}$with$g(a,b,c)=\\begin{cases}a :\\quad a > b,c\\\\b :\\quad b > a,c\\\\c : \\quad c \\geq a,b\\end{cases}$\n", "\n", "$h : \\mathbb{N}^2 \\to \\mathbb{N}$with$h(i,j)=\\begin{cases}i :\\quad j=0\\\\ succ(h(i,j-1)) : \\quad otherwise\\end{cases}$" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## problem 5\n", "\n", "- write your own implementation of even'.\n", "- Look up even in _Hoogle_ () and/or\n", "\t_Hayoo!_ () (rem is aquivalent to mod for positive numbers).\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## problem 6\n", "\n", "the imaginary weather prediction module Magic.Weather.Prediction creates the variables \n", "\n", "\trainy :: Bool\n", "\tcold :: Bool\n", "\twindy :: Bool\n", "\n", "(assume that they are filled)\n", "\n", "Use if ... then ... else (and boolean operators) to return the following strings:\n", "\n", "- \"fly kites\" _(when windy but not rainy)_\n", "- \"take your umbrella\"\t_(when rainy but not cold)_\n", "- \"sit at the fireplace\" _(when rainy and cold)_\n", "- \"enjoy the sun\" _(when not rainy or windy)_\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## problem 7\n", "\n", "Brackets get very expensive. Try to reduce the number of brackets via using of the application operator $ from the following expressions:\n", "\n", "- max 23 (max 5 39)\n", "- max 23 (5 * (succ 4))\n", "- mod 23 (min 7 ((*) 2 3))\n", "- min (max 23 44) (max 5 (negate (-39)))\n", "\n", "Which brackets are redundant anyway? \n", "Which expression is an identity?" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Haskell", "language": "haskell", "name": "haskell" }, "language_info": { "codemirror_mode": "ihaskell", "file_extension": ".hs", "name": "haskell", "version": "7.10.3" } }, "nbformat": 4, "nbformat_minor": 0 }
 { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Exercises 03\n", "\n", "## problem 1\n", "\n", "haskell\n", " alphabet = ['a'..'z']\n", "\n", "\n", "get the following information from alphabet:\n", "\n", "- length\n", "- first 3 characters\n", "- the 12th character\n", "- the 7-10th character\n", "- the last 5 characters\n", "\n", "and then create an aLPHABET with upper case characters and add it to the existing one\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## problem 2\n", "implement a function hasVowel which checks if a string contains a vowel character. Test the function with \"foo\", \"bar\" and \"bz\".\n", "\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## problem 3\n", "\n", "use list comprehensions for creating the following sets in haskell\n", "\n", "\n", "- $A = \\{ x \\,:\\, x \\in \\mathbb{N},\\, x \\text{ odd}\\}$ (only showing the first 5 elements)\n", "- $B = \\{ -x \\,:\\, x \\in \\mathbb{N},\\, 3|x ,\\, x < 10\\}$ ($3|x$ : 3 is a divisor of x)\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## problem 4 \n", "\n", "Create the set of all odd numbers smaller than 500, which are dividable through 5 and 7.\n", "\n", "$S=\\{x : x \\neq 0 \\land 5|x \\land 7|x\\}$\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# problem 5\n", "\n", "Let $A=\\{1,2,3\\}$, $B=\\{3,4,5\\}$. Calculate the intersection and the union of $A$ and $B$." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## problem 6\n", "\n", "Let less and greater be functions which have a value v and a list of values l of the same type as v. Return a list of all values which are less or greater as v.\n", "\n", "$\\text{less}(v,l) = \\{x : x \\in l, x < v\\}$\n", "\n", "Implement the functions using list comprehensions.\n", "\n", "Test: 5 [1..10]\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## problem 7\n", "\n", "the list generated with [0.1,0.3..0.9] has problems with precision (has roundingerror). Do it better via using list comprehensions. (Tip: ranges of integral types do not have rounding errors).\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Haskell", "language": "haskell", "name": "haskell" }, "language_info": { "codemirror_mode": "ihaskell", "file_extension": ".hs", "name": "haskell", "version": "7.10.3" } }, "nbformat": 4, "nbformat_minor": 0 } \ No newline at end of file "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Exercises 03\n", "\n", "## problem 1\n", "\n", "haskell\n", " alphabet = ['a'..'z']\n", "\n", "\n", "get the following information from alphabet:\n", "\n", "- length\n", "- first 3 characters\n", "- the 12th character\n", "- the 7-10th character\n", "- the last 5 characters\n", "\n", "and then create an aLPHABET with upper case characters and add it to the existing one\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## problem 2\n", "implement a function hasVowel which checks if a string contains a vowel character. Test the function with \"foo\", \"bar\" and \"bz\".\n", "\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## problem 3\n", "\n", "use list comprehensions for creating the following sets in haskell\n", "\n", "\n", "- $A = \\{ x \\,:\\, x \\in \\mathbb{N},\\, x \\text{ odd}\\}$ (only showing the first 5 elements)\n", "- $B = \\{ -x \\,:\\, x \\in \\mathbb{N},\\, 3|x ,\\, x < 10\\}$ ($3|x$ : 3 is a divisor of x)\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## problem 4 \n", "\n", "Create the set of all odd numbers smaller than 500, which are dividable through 5 and 7.\n", "\n", "$S=\\{x : x \\neq 0 \\land 5|x \\land 7|x\\}$\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# problem 5\n", "\n", "Let $A=\\{1,2,3\\}$, $B=\\{3,4,5\\}$. Calculate the intersection and the union of $A$ and $B$." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false