[Solved] ICS Problem sheet 5

$25

File Name: ICS_Problem_sheet_5.zip
File Size: 178.98 KB

SKU: [Solved] ICS Problem sheet 5 Category: Tag:
5/5 - (1 vote)
Problem 5.1: base b numbers closed form

Consider a base b number system (b > 1) with n digits and the number 11b (n times the digit 1).

  1. Define a sum formula that provides the value of the n-digit number 11b.
  2. Proof via induction that the value of the n-digit number 11b is given by the following closed form:

For example, the 4-digit base 5 number 11115 has the value .

Problem 5.2: unicode and utf-8 encoding

The content of a file containing UTF-8 Unicode encoded text is given by the following sequence of bytes in hexadecimal notation:

48 65 6c 6c 6f 20 f0 9f 8c 8d 21 0a

  1. Write each byte in binary notation.
  2. Identify the unicode code points of the characters. What is the text stored in the file?
  3. Which line end convention is used? What are other popular line end conventions?

Problem 5.3: long years (haskell)

According to the ISO8601 calendar, most years have 52 weeks, but some have 53 weeks. These are so called long years. There is a relatively simple way to calculate whether a given year y is a long year. The function w(y) determines with the helper function p(y) the number of weeks in the year y. (Note that the functions use integer division.)

otherwise

Implement a Haskell function isLongYear :: Int -> Bool to determine whether a year is a long year. Use the isLongYear function to calculate all long years in the range 2000..2100.

Submit your Haskell code as a plain text file.

Problem 5.4: decimal to binary and binary to decimal (haskell)

Implement a function to convert a decimal number into a binary notation and one function to convert from a binary notation back.

  1. Implement a function dtob :: Int -> String that converts a non-negative integer number into a String (consisting of the characters 0 and 1) representing the integer number as a binary number. It is not necessary to handle negative integers in a meaningful way.
  2. Implement a function dtob :: String -> Int that converts a String (consisting of the characters 0 and 1) representing a binary number into the corresponding non-negative integer number. It is not necessary to handle unexpected strings in a meaningful way.

Submit your Haskell code as a plain text file. Below is a template file with a few unit test cases.

1 module Main (main) where

2

3 import Test.HUnit

4

  • |The dtob function converts a non-negative integer number into a
  • String providing a binary representation of the number.
  • dtob :: Int -> String
  • dtob _ = undefined

9

10 |The btod function converts a String representing a non-negative 11 integer number as a binary number into an integer number.

  • btod :: String -> Int
  • btod _ = undefined

14

  • {-
  • Below are some test cases.
  • -}

18

  • dtobTests = TestList [ dtob 0 ~?= 0
  • , dtob 1 ~?= 1
  • , dtob 2 ~?= 10
  • , dtob 127 ~?= 1111111
  • , dtob 12345 ~?= 11000000111001
  • ]

25

  • btodTests = TestList [ btod 0 ~?= 0
  • , btod 1 ~?= 1
  • , btod 10 ~?= 2
  • , btod 1111111 ~?= 127
  • , btod 11000000111001 ~?= 12345
  • ]

32

33 main = runTestTT $ TestList [ dtobTests, btodTests ]

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] ICS Problem sheet 5[Solved] ICS Problem sheet 5
$25