This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//An exampple of Polymorphism in Swift | |
class A{ | |
func makeSound(){ | |
print("from A") | |
} | |
} | |
class B : A{ | |
override func makeSound(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
//Day 1: Interquartile Range | |
func medianFunc(numbers: [Int]) -> Double { | |
let sortedNumbers = numbers.sorted(by: { num1, num2 in | |
return num1 < num2 }) | |
let midIndex = numbers.count / 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
//Day 1: Quartiles | |
func medianFunc(numbers: [Int]) -> Double { | |
let sortedNumbers = numbers.sorted(by: { num1, num2 in | |
return num1 < num2 }) | |
let midIndex = numbers.count / 2 | |
var median = Double(sortedNumbers[midIndex]) | |
if(numbers.count % 2 == 0){ | |
median = Double(sortedNumbers[midIndex] + sortedNumbers[midIndex - 1]) / Double(2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
//Day 1: Standard Deviation | |
func StandardDeviation(numbers: [Int]) -> Double { | |
var sum = 0.0 | |
for eachNo in numbers { | |
sum += Double(eachNo) | |
} | |
let mean = sum / Double(numbers.count) | |
var sumOfSquare : Double = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
//Day 0:weightMean | |
func weightMean(numbers: [Int] , weights : [Int]) -> Double { | |
var sum = 0.0 | |
var totalWeights = 0 | |
for i in 0..<numbers.count { | |
sum += Double(numbers[i] * weights[i]) | |
totalWeights += weights[i] | |
} | |
let weightMean = sum / Double(totalWeights) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
10 Days of Statistics | |
Objective | |
In this challenge, we practice calculating the mean, median, and mode. Check out the Tutorial tab for learning materials and an instructional video! | |
Task | |
Given an array, , of integers, calculate and print the respective mean, median, and mode on separate lines. If your array contains more than one modal value, choose the numerically smallest one. | |
Note: Other than the modal value (which will always be an integer), your answers should be in decimal form, rounded to a scale of decimal place (i.e., , format). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Diagonal Difference | |
Given a square matrix, calculate the absolute difference between the sums of its diagonals. | |
For example, the square matrix is shown below: | |
1 2 3 | |
4 5 6 | |
9 8 9 | |
The left-to-right diagonal = . The right to left diagonal = . Their absolute difference is . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Compare the Triplets | |
Alice and Bob each created one problem for HackerRank. A reviewer rates the two challenges, awarding points on a scale from to for three categories: problem clarity, originality, and difficulty. | |
We define the rating for Alice's challenge to be the triplet , and the rating for Bob's challenge to be the triplet . | |
Your task is to find their comparison points by comparing with , with , and with . | |
If , then Alice is awarded point. | |
If , then Bob is awarded point. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Cats and a Mouse | |
Two cats and a mouse are at various positions on a line. You will be given their starting positions. Your task is to determine which cat will reach the mouse first, assuming the mouse doesn't move and the cats travel at equal speed. If the cats arrive at the same time, the mouse will be allowed to move and it will escape while they fight. | |
You are given queries in the form of , , and representing the respective positions for cats and , and for mouse . Complete the function to return the appropriate answer to each query, which will be printed on a new line. | |
If cat catches the mouse first, print Cat A. | |
If cat catches the mouse first, print Cat B. | |
If both cats reach the mouse at the same time, print Mouse C as the two cats fight and mouse escapes. | |
For example, cat is at position and cat is at . If mouse is at position , it is units from cat and unit from cat . Cat will catch the mouse. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Electronics Shop | |
//Problem | |
/* | |
Monica wants to buy a keyboard and a USB drive from her favorite electronics store. The store has several models of each. Monica wants to spend as much as possible for the items, given her budget. | |
Given the price lists for the store's keyboards and USB drives, and Monica's budget, find and print the amount of money Monica will spend. If she doesn't have enough money to both a keyboard and a USB drive, print -1 instead. She will buy only the two required items. | |
For example, suppose she has to spend. Three types of keyboards cost . Two USB drives cost . She could purchase a , or a . She chooses the latter. She can't buy more than items so she can't spend exactly . | |
Function Description |
NewerOlder