From a7183ddc1ad31e201fbf30bf176c3e5bf77611a9 Mon Sep 17 00:00:00 2001 From: Vladimir Bes Date: Mon, 17 Feb 2020 00:28:51 +1000 Subject: [PATCH 1/2] lesson-1 --- lesson_1/.keep | 0 .../Contents.swift | 61 +++++++++++++++++++ .../contents.xcplayground | 4 ++ 3 files changed, 65 insertions(+) create mode 100644 lesson_1/.keep create mode 100644 lesson_1/1Iesson_BesedinVladimir.playground/Contents.swift create mode 100644 lesson_1/1Iesson_BesedinVladimir.playground/contents.xcplayground diff --git a/lesson_1/.keep b/lesson_1/.keep new file mode 100644 index 0000000..e69de29 diff --git a/lesson_1/1Iesson_BesedinVladimir.playground/Contents.swift b/lesson_1/1Iesson_BesedinVladimir.playground/Contents.swift new file mode 100644 index 0000000..6594e52 --- /dev/null +++ b/lesson_1/1Iesson_BesedinVladimir.playground/Contents.swift @@ -0,0 +1,61 @@ +import UIKit + +// +// 1. Решить квадратное уравнение. +let a:Int = 1 +var b:Int = 12 +let c:Int = 36 + +// b в квадрате +let pw:Int = Int(pow(Double(b), 2)) +//Дискриминант +let d:Int = pw - 4 * a * c +if d > 0 { + // корень b^2 - 4ac + let sqr:Int = Int(sqrt(Double(pw - (4 * a * c)))) + + let x1 = (-(b) + sqr) / 2 * a + let x2 = (-(b) - sqr) / 2 * a + print("Уравнение имеет два корня") + print("x1: " + String(x1)) + print("x2: " + String(x2)) +}else if d == 0 { + let sqr:Int = Int(sqrt(Double(pw - (4 * a * c)))) + + let x1 = (-(b) + sqr) / 2 * a + + print("уравнение имеет один корень") + print("x1: " + String(x1)) + +}else { + print("Нет действительных корней") +} + +// 2. Даны катеты прямоугольного треугольника. Найти площадь, периметр и гипотенузу треугольника. +// Катет А +let katetA = 3 +// Катет B +let katetB = 4 +// Площадь +let area = (1 * katetA * katetB) / 2 +print("Площадь: " + String(area)) +//Гипотенуза +let powA = Int(pow(Double(katetA), 2)) +let powB = Int(pow(Double(katetB), 2)) +let gipot = Int(sqrt(Double(powA + powB))) +print("Гипотенуза: " + String(gipot)) +// Периметр +let perim = katetA + katetB + gipot +print("Периметр: " + String(perim)) + + +// 3. * Пользователь вводит сумму вклада в банк и годовой процент. Найти сумму вклада через 5 лет. + +let deposit:Int = 100000 +let percent:Float = 0.14 +var sum = Float(deposit) +for _ in 1...5 { + sum += sum * percent +} +var total = Int(sum) +print("Сумма после 5 лет: " + String(total)) diff --git a/lesson_1/1Iesson_BesedinVladimir.playground/contents.xcplayground b/lesson_1/1Iesson_BesedinVladimir.playground/contents.xcplayground new file mode 100644 index 0000000..5da2641 --- /dev/null +++ b/lesson_1/1Iesson_BesedinVladimir.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file From aaf1601c9cbf72b1ba8ac031fcc3a3574b0e3f05 Mon Sep 17 00:00:00 2001 From: Vladimir Bes Date: Wed, 19 Feb 2020 21:33:25 +1000 Subject: [PATCH 2/2] lesson-2 --- .../Contents.swift | 61 ------------- {lesson_1 => lesson_2}/.keep | 0 .../Contents.swift | 90 +++++++++++++++++++ .../contents.xcplayground | 0 4 files changed, 90 insertions(+), 61 deletions(-) delete mode 100644 lesson_1/1Iesson_BesedinVladimir.playground/Contents.swift rename {lesson_1 => lesson_2}/.keep (100%) create mode 100644 lesson_2/2lesson_BesedinVladimir.playground/Contents.swift rename {lesson_1/1Iesson_BesedinVladimir.playground => lesson_2/2lesson_BesedinVladimir.playground}/contents.xcplayground (100%) diff --git a/lesson_1/1Iesson_BesedinVladimir.playground/Contents.swift b/lesson_1/1Iesson_BesedinVladimir.playground/Contents.swift deleted file mode 100644 index 6594e52..0000000 --- a/lesson_1/1Iesson_BesedinVladimir.playground/Contents.swift +++ /dev/null @@ -1,61 +0,0 @@ -import UIKit - -// -// 1. Решить квадратное уравнение. -let a:Int = 1 -var b:Int = 12 -let c:Int = 36 - -// b в квадрате -let pw:Int = Int(pow(Double(b), 2)) -//Дискриминант -let d:Int = pw - 4 * a * c -if d > 0 { - // корень b^2 - 4ac - let sqr:Int = Int(sqrt(Double(pw - (4 * a * c)))) - - let x1 = (-(b) + sqr) / 2 * a - let x2 = (-(b) - sqr) / 2 * a - print("Уравнение имеет два корня") - print("x1: " + String(x1)) - print("x2: " + String(x2)) -}else if d == 0 { - let sqr:Int = Int(sqrt(Double(pw - (4 * a * c)))) - - let x1 = (-(b) + sqr) / 2 * a - - print("уравнение имеет один корень") - print("x1: " + String(x1)) - -}else { - print("Нет действительных корней") -} - -// 2. Даны катеты прямоугольного треугольника. Найти площадь, периметр и гипотенузу треугольника. -// Катет А -let katetA = 3 -// Катет B -let katetB = 4 -// Площадь -let area = (1 * katetA * katetB) / 2 -print("Площадь: " + String(area)) -//Гипотенуза -let powA = Int(pow(Double(katetA), 2)) -let powB = Int(pow(Double(katetB), 2)) -let gipot = Int(sqrt(Double(powA + powB))) -print("Гипотенуза: " + String(gipot)) -// Периметр -let perim = katetA + katetB + gipot -print("Периметр: " + String(perim)) - - -// 3. * Пользователь вводит сумму вклада в банк и годовой процент. Найти сумму вклада через 5 лет. - -let deposit:Int = 100000 -let percent:Float = 0.14 -var sum = Float(deposit) -for _ in 1...5 { - sum += sum * percent -} -var total = Int(sum) -print("Сумма после 5 лет: " + String(total)) diff --git a/lesson_1/.keep b/lesson_2/.keep similarity index 100% rename from lesson_1/.keep rename to lesson_2/.keep diff --git a/lesson_2/2lesson_BesedinVladimir.playground/Contents.swift b/lesson_2/2lesson_BesedinVladimir.playground/Contents.swift new file mode 100644 index 0000000..fdb75ce --- /dev/null +++ b/lesson_2/2lesson_BesedinVladimir.playground/Contents.swift @@ -0,0 +1,90 @@ +import UIKit + + +//1. Написать функцию, которая определяет, четное число или нет. +func even (_ x:Int) -> Bool { + return x % 2 == 0 +} +even(-2) + +// 2. Написать функцию, которая определяет, делится ли число без остатка на 3. +func residue (_ x:Int) -> Bool { + return x % 3 == 0 +} +residue(-99) + +// 3. Создать возрастающий массив из 100 чисел. + +var massive : [Int] = [] + +for i in 1...100 { + massive.append(i) +} +// 4. Удалить из этого массива все четные числа и все числа, которые не делятся на 3. + +for (_, value) in massive.enumerated() { + if even(value) || residue(value) == true { + massive.remove(at: massive.firstIndex(of: value) ?? 0) + } +} + +//5. * Написать функцию, которая добавляет в массив новое число Фибоначчи, и добавить при помощи нее 100 элементов. +var fibMassive: [Decimal] = [] + +func fib(_ n: Int) { + if n == 0 {fibMassive.append(0)} + if n <= 2 {fibMassive.append(1)} + if n > 2{ + var x:Decimal = 1 + var y:Decimal = 1 + var ans:Decimal = 0 + var i = 2 + while i < n { + ans = x + y + x = y + y = ans + i += 1 + } + fibMassive.append(ans) + } +} +for i in 1...100 { + fib(i) +} +// рекурсией не вывозит это норм? так и должно быть? + + +//6.* Заполнить массив из 100 элементов различными простыми числами. Натуральное число, большее единицы, называется простым, если оно делится только на себя и на единицу. +//a +var simpleMassive: [Int] = [] + +func addMassive (_ n:Int) { + var testMassive: [Int] = [] + for i in 2...n { + let count = 2...i + for j in count{ + if i % j == 0 { + testMassive.append(i) + } + }; + if testMassive.count > 1 { + testMassive.removeAll() + }else{ + testMassive.removeAll() + simpleMassive.append(i) + } + } +} + +addMassive(550) +print(simpleMassive) +//b +let p = simpleMassive.first +//с Не понял что значит зачеркнуть??? + + + + + + + diff --git a/lesson_1/1Iesson_BesedinVladimir.playground/contents.xcplayground b/lesson_2/2lesson_BesedinVladimir.playground/contents.xcplayground similarity index 100% rename from lesson_1/1Iesson_BesedinVladimir.playground/contents.xcplayground rename to lesson_2/2lesson_BesedinVladimir.playground/contents.xcplayground