Skip to content

Latest commit

 

History

History
24 lines (13 loc) · 2.31 KB

S04-EN-functions.md

File metadata and controls

24 lines (13 loc) · 2.31 KB

Functions

  1. E01-city-distances: Write an algorithm that takes as input a sequence of pairs of city names and distances between these cities (measured in miles) and reports the distances in kilometers. Note that the end of the input is determined by two cities with the same name and distance 0. Example: For the sequence "Caracas" "Valencia" "98" "Caracas" "Maturin" "312" "Caracas" "Caracas" "0", your algorithm should print:

    Caracas Valencia: 156.8 Caracas Maturin: 499.2

  2. E02-extract-digits: Create an algorithm for a function that receives two parameters, N and K, and returns the K leftmost digits of N. Example: extractDigits(542207, 2) should return 54.

  3. E03-palindrome-substring: Create an algorithm that determines if a 6-digit number N contains any 3-digit palindrome number. Example: If N = 485992, there are no contained palindrome numbers, but N = 106562 does contain one (656).

  4. E04-sort-numbers: Write a function or action that receives 5 numbers as parameters and prints the numbers from highest to lowest and also determines the maximum and minimum among them.

  5. E05-days-to-month: Create a function that receives a month of the year as input and determines the number of days elapsed from the beginning of the year to the first day of the month.

  6. E06-days-between-dates: Create a function that uses the function created in problem 5 to create another function that takes as input two dates (day, month, and year) and calculates the number of days elapsed between the dates. You can also assume that there is a function to determine if a year is a leap year.

  7. E07-point-in-rectangle: Create a function to determine if a point (X, Y) is inside a rectangle. The rectangle is defined by the coordinate of the top-left vertex, its height, and its width.

  8. E08-rectangle-intersection: Using the function developed in problem 7, create a function that takes as input two rectangles and determines if any vertex of the 1st rectangle is contained in the 2nd rectangle.

  9. E09-bank-account: Create a program that simulates a bank account. It should allow you to deposit, withdraw, and check the account balance.

  10. E10-rock-paper-scissors: Create a program that simulates the game rock-paper-scissors. The program should allow the user to play against the computer.