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
class LeftAlignedCollectionViewFlowLayout: UICollectionViewFlowLayout { | |
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { | |
let attributes = super.layoutAttributesForElements(in: rect) | |
var leftMargin = sectionInset.left | |
var maxY: CGFloat = -1.0 | |
attributes?.forEach { layoutAttribute in | |
if layoutAttribute.frame.origin.y >= maxY { | |
leftMargin = sectionInset.left |
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 | |
func validateSudoku(array : [Int]) -> Bool { | |
let width = 9 | |
func valueAtPos(x: Int, y: Int, array: [Int]) -> Int { | |
return array[y * width + x] | |
} | |
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
// | |
// Anagram finder. | |
// | |
// Description: takes a list of anagrams and outputs the words in the same order as they appear in original string. | |
// Also outputs all the matched words after that in the order they appear after that. | |
// | |
// Language: Swift 5 | |
// Author: Paul Ossenbruggen | |
// Date: Dec 4, 2015 | |
// |
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
// | |
// Description: RandomArrays: pick randomly to build new array in two different ways. One a shuffle the other | |
// picking from the array. Shuffle uses Fischer-Yates algorithm to generate uniform randomness. Allthough it | |
// might be better to use Apple's Game kit function GKRandomSource.sharedRandom().arrayByShufflingObjectsInArray(array) | |
// if available in the OS release. Also this only works on arrays, if you want to shuffle any colletion type | |
// it is possible to extend MutableCollectionType. | |
// | |
// Author: Paul Ossenbruggen | |
// | |
// Date: Nov 20, 2015 |
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
// | |
// Description: Shortest distance graph. Calculates the distances from a start node to any node in the graph. | |
// Date: Nov 18, 2015 | |
// | |
// Language: Swift | |
// | |
// Author: Paul Ossenbruggen | |
// | |
struct Edge : Equatable, Hashable, CustomStringConvertible { | |
let weight : Int |
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
// | |
// Description: Finds the sum of all elements that add up to the target value using dynamic programming. | |
// Note: input array must be non negative and constrained to a reasonable ranage because it uses target+1 memory | |
// | |
// Language: Swift | |
// | |
// Author: Paul Ossenbruggen | |
// Date: Nov 10, 2015 | |
// |
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 | |
// | |
// Description; Various solutions for finding number change possibilities and minimum number of change possibilitis. | |
// | |
// Author: Paul Ossenbruggen | |
// Date: Nov 8, 2015 | |
// Updated: June 8, 2020 | |
// Language: Swift 5.3 | |
// See comments below for problem statement. |
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
// | |
// Description Silly Hat village in Swift solution | |
// | |
// Author: Paul Ossenbruggen | |
// Date: Nov 8, 2015 | |
// Language: Swift 2.1 | |
// See comment below for problem statement. | |
// | |
import Foundation |
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
// | |
// Description Switch problem in Swift solution | |
// | |
// Author: Paul Ossenbruggen | |
// Date: Nov 8, 2015 | |
// Language: Swift 2.1 | |
// See comment below for problem statement. This solves the second version where we don't know the state | |
// of the switch at the beginning. | |
// |
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
// Description: Implementation of a Trie | |
// | |
// Language: Swift 2.1 | |
// Author: Paul Ossenbruggen | |
// Nov 7, 2015 | |
import Foundation | |
class Trie { | |
var last : Bool = false |
NewerOlder