Skip to content

Instantly share code, notes, and snippets.

@AnthonyBY
AnthonyBY / gist:17de3579e20cdb6fcdac5b4135d6a839
Created October 5, 2023 08:07
Swift class override quiz
import UIKit
class A {
func execute(ind: Int = 0) {
print("A: \(ind)")
}
}
class B: A {
override func execute(ind: Int = 1) {
@AnthonyBY
AnthonyBY / UIColor+Extension.swift
Last active October 16, 2019 07:34
UIColor to hex, and vice versa
extension UIColor {
convenience init(hexString: String, alpha: CGFloat = 1.0) {
let hexString: String = hexString.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
let scanner = Scanner(string: hexString)
if (hexString.hasPrefix("#")) {
scanner.scanLocation = 1
}
var color: UInt32 = 0
scanner.scanHexInt32(&color)
@AnthonyBY
AnthonyBY / Kosaraju.swift
Last active April 7, 2020 17:35
Kosaraju's strongly connected components (SCC) Algorithm, Swift 4
import Foundation
class Graph {
var nodes = [Node]()
var identifiersToNodes = [Int: Node]()
func addNode(node: Node) {
identifiersToNodes[node.identifier] = node
nodes += [node]
}
@AnthonyBY
AnthonyBY / StepicGausseCalculation.txt
Last active November 4, 2017 16:27
Stepic решение. 1.5 Решение систем линейных алгебраических уравнений
#include<iostream>
#include <math.h>
#include <stdlib.h>
using namespace std;
int main()
{
int i, j, n, m;
@AnthonyBY
AnthonyBY / InversionCount
Last active October 7, 2017 16:28
Swift 4: Inversion Counting Divide and Concur Algorithms (based on MergeSort)
//
// main.swift
// CountInversionWithMergeSort
//
// Created by Anthony Marchenko on 10/3/17.
// Copyright © 2017 Anthony Marchenko. All rights reserved.
//
import Foundation
@AnthonyBY
AnthonyBY / Find max sub array. Naive, Kadane, Divide and Conquer.txt
Last active November 4, 2017 16:29
Swift 4: Find max sub array. Naive, Kadane, Divide and Conquer
//
// main.swift
// MaxSubArray
//
// Created by Anthony Marchenko on 10/3/17.
// Copyright © 2017 Anthony Marchenko. All rights reserved.
//
import Foundation
@AnthonyBY
AnthonyBY / BinarySearch.txt
Last active November 4, 2017 16:26
Day 22: Binary Search Trees (Swift 3.1)
// Start of Node class
class Node {
var data: Int
var left: Node?
var right: Node?
init(d : Int) {
data = d
}
} // End of Node class
@AnthonyBY
AnthonyBY / SwiftRegularExpressionExample.txt
Last active November 4, 2017 16:28
Valid PAN format. Swift 3. HackerRank
import Foundation
// read the integer n
let n = Int(readLine()!)!
var arr = Array(repeating: "", count: n)
for index in 0...n-1 {
arr[index] = String(readLine()!)
}
@AnthonyBY
AnthonyBY / Fibonacci.txt
Last active December 29, 2022 11:44
Recursion: Fibonacci Numbers (Swift 3)
import Foundation
func fibonacci (n: Int) -> Int {
// Write your code here.
if (n == 0 || n == 1) {
return 1;
}
return fibonacci(n: n-1) + fibonacci(n: n-2)
}
@AnthonyBY
AnthonyBY / gist:9014c2b867dacfb5c5b4d4d68078e1af
Created March 1, 2017 15:22
HackerRank: Sorting: Bubble Sort (Swift 3)
import Foundation
// read the integer n
let n = Int(readLine()!)!
// read the array
var arr = readLine()!.components(separatedBy: " ").map{ Int($0)! }
var swapCount = 0