Created
July 10, 2017 08:10
-
-
Save hcn1519/c28db17e3b3974851dbd6a22f552ce9c to your computer and use it in GitHub Desktop.
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
//: Playground - noun: a place where people can play | |
import UIKit | |
var str = "Hello, playground" | |
1 + 3 | |
2 / 4 | |
12 * 20 | |
78 / 9 | |
func add(number1: Int, number2: Int) -> Int { | |
return number1 + number2 | |
} | |
MemoryLayout<Int>.size | |
MemoryLayout<Bool>.size | |
MemoryLayout<String>.size | |
var ํ๊ธ = "hey" | |
print("๐") | |
func distance(ax: Int, ay: Int, bx: Int, by: Int) -> Float { | |
var result: Float = 0.0 | |
let xLength: Float = Float(ax - bx) | |
let yLength: Float = Float(ay - by) | |
let x2 = xLength * xLength | |
let y2 = yLength * yLength | |
result = sqrt(x2+y2) | |
return result | |
} | |
distance(ax: 1, ay: 1, bx: 5, by: 6) | |
var dict: [String: Int] = [:] | |
print(dict["a"] ?? 100) | |
typealias Point = (number1: Int, number2: Int) | |
func dis(a: Point, b: Point) -> Double { | |
var result: Double = 0.0 | |
let xLength = Double(a.number1 - b.number1) | |
let yLength = Double(a.number2 - b.number2) | |
let x2 = xLength * xLength | |
let y2 = yLength * yLength | |
result = sqrt(x2+y2) | |
return result | |
} | |
//print(dis(a: (1, 1), b: (5, 6))) | |
func age(_ from: String) -> Int { | |
let yearRange = from.startIndex...from.index(from.startIndex, offsetBy: 1) | |
var birth = "" | |
if let yearData = Int(from[yearRange]) { | |
if yearData > 20 { | |
// 1900๋ ๋ ์ | |
birth = "19" + from[yearRange] | |
} | |
else { | |
// 2000๋ ์ ์ดํ | |
if yearData < 10 { | |
birth = "20" + "0" + String(yearData) | |
} else { | |
birth = "20" + String(yearData) | |
} | |
} | |
} | |
let year = 2017 | |
let age = year - Int(birth)! | |
return age | |
} | |
// | |
//print(age("881202")) | |
//print(age("001202")) | |
// | |
//func makeSandwitch() throw { | |
// print("make a Sandwitch") | |
//} | |
// | |
//do { | |
// try makeSandwitch() | |
//} | |
func enumerateList(_ A : [Int]) { | |
var item = A[0] | |
print("\(item) -> ", terminator: "") | |
while item != -1 { | |
print("\(A[item]) -> ", terminator: "") | |
item = A[item] | |
} | |
} | |
func countOfList(_ A: [Int]) { | |
var item = A[0] | |
var counter = 1 | |
while item != -1 { | |
counter += 1 | |
item = A[item] | |
} | |
print("\n๊ธธ์ด : \(counter)") | |
} | |
func isFullList(_ A : [Int]) -> Bool { | |
var item = A[0] | |
var counter = 1 | |
while item != -1 { | |
counter += 1 | |
item = A[item] | |
} | |
var result: Bool = false | |
if counter == A.count { | |
result = true | |
} | |
return result | |
} | |
let a = [1, 4, -1, 3, 2] | |
enumerateList(a) | |
countOfList(a) | |
print(isFullList(a)) | |
var intValue = 10 | |
let increment = { | |
[intValue] (n : Int) in | |
print(intValue + n) | |
} | |
intValue = 100 | |
increment(5) | |
let complex = { (array: [Int]) -> Int in | |
let filtered = array.filter({ $0 % 2 == 0 || $0 % 3 == 0}) | |
let newArray = filtered.map { $0 * 5 } | |
let total = newArray.reduce(0, { $0 + $1 }) | |
return total | |
} | |
print(complex([1,2,3,4,5,6,7,8,9,10])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment