Skip to content

Latest commit

 

History

History
96 lines (57 loc) · 4.44 KB

README.MD

File metadata and controls

96 lines (57 loc) · 4.44 KB

Hi all,

Here you cand find some of my little Swift projects for practice.

6 kyu

To participate in a prize draw each one gives his/her firstname.

Each letter of a firstname has a value which is its rank in the English alphabet. A and a have rank 1, B and b rank 2 and so on. The length of the firstname is added to the sum of these ranks hence a number som. An array of random weights is linked to the firstnames and each som is multiplied by its corresponding weight to get what they call a winning number. Now one can sort the firstnames in decreasing order of the winning numbers. When two people have the same winning number sort them alphabetically by their firstnames.

Task:

  1. parameters: st a string of firstnames, we an array of weights, n a rank
  2. return: the firstname of the participant whose rank is n (ranks are numbered from 1)

Notes:

  • The weight array is at least as long as the number of names, it may be longer.
  • If st is empty return "No participants".
  • If n is greater than the number of participants then return "Not enough participants".

6 kyu

John has some amount of money of which he wants to deposit a part f0 to the bank at the beginning of year 1. He wants to withdraw each year for his living an amount c0.

Here is his banker plan:

  • deposit f0 at beginning of year 1
  • his bank account has an interest rate of p percent per year, constant over the years
  • John can withdraw each year c0, taking it whenever he wants in the year; he must take account of an inflation of i percent per year in order to keep his quality of living. i is supposed to stay constant over the years.
  • all amounts f0..fn-1, c0..cn-1 are truncated by the bank to their integral part
  • Given f0, p, c0, i the banker guarantees that John will be able to go on that way until the nth year.

6 kyu

Digital root is the recursive sum of all the digits in a number.

Given n, take the sum of the digits of n. If that value has more than one digit, continue reducing in this way until a single-digit number is produced. The input will be a non-negative integer.

6 kyu

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Finish the solution so that it returns the sum of all the multiples of 3 or 5 below the number passed in. Additionally, if the number is negative, return 0 (for languages that do have them).

Note: If the number is a multiple of both 3 and 5, only count it once.

6 kyu

Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral.

7 kyu

Take an integer n (n >= 0) and a digit d (0 <= d <= 9) as an integer.

Square all numbers k (0 <= k <= n) between 0 and n.

Count the numbers of digits d used in the writing of all the k**2.

Call nb_dig (or nbDig or ...) the function taking n and d as parameters and returning this count.

7 kyu

This time no story, no theory. The examples below show you how the function accum works:

Examples:

accum("abcd") -> "A-Bb-Ccc-Dddd" accum("RqaEzty") -> "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy" accum("cwAt") -> "C-Ww-Aaa-Tttt"

MagicCalculator

Codecademy

Created advanced calculator which can not only add, substract or multiply but it can also sort, map and filter values. Contains closures and Bubble Sort Algorythm.

Is-he-gonna-survive

8 kyu

Each dragon takes 2 bullets to be defeated, our hero has no idea how many bullets he should carry.. Assuming he's gonna grab a specific given number of bullets and move forward to fight another specific given number of dragons, will he survive? Return True if yes, False otherwise