├── README.md
├── 364-easy
├── README.md
└── 364-easy.playground
│ ├── playground.xcworkspace
│ ├── contents.xcworkspacedata
│ ├── xcuserdata
│ │ └── cor.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ └── xcshareddata
│ │ └── IDEWorkspaceChecks.plist
│ ├── timeline.xctimeline
│ ├── contents.xcplayground
│ └── Contents.swift
├── 263-easy
└── 263-easy.playground
│ ├── contents.xcplayground
│ ├── playground.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcuserdata
│ │ └── cor.xcuserdatad
│ │ └── UserInterfaceState.xcuserstate
│ └── Contents.swift
├── 312-easy
└── 312-easy.playground
│ ├── contents.xcplayground
│ ├── playground.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcuserdata
│ │ └── cor.xcuserdatad
│ │ └── UserInterfaceState.xcuserstate
│ └── Contents.swift
└── 312-intermediate
└── 312-intermediate.playground
├── contents.xcplayground
├── playground.xcworkspace
├── contents.xcworkspacedata
└── xcuserdata
│ └── cor.xcuserdatad
│ └── UserInterfaceState.xcuserstate
├── timeline.xctimeline
└── Contents.swift
/README.md:
--------------------------------------------------------------------------------
1 | # daily-programmer
2 | /r/dailyprogrammer
3 |
--------------------------------------------------------------------------------
/364-easy/README.md:
--------------------------------------------------------------------------------
1 | I have no idea what this is. It probably is not the actual 364-easy challange
2 |
--------------------------------------------------------------------------------
/364-easy/364-easy.playground/playground.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/364-easy/364-easy.playground/timeline.xctimeline:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/263-easy/263-easy.playground/contents.xcplayground:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/312-easy/312-easy.playground/contents.xcplayground:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/263-easy/263-easy.playground/playground.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/312-easy/312-easy.playground/playground.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/312-intermediate/312-intermediate.playground/contents.xcplayground:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/312-intermediate/312-intermediate.playground/playground.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/364-easy/364-easy.playground/contents.xcplayground:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/263-easy/263-easy.playground/playground.xcworkspace/xcuserdata/cor.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoR/daily-programmer/master/263-easy/263-easy.playground/playground.xcworkspace/xcuserdata/cor.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/312-easy/312-easy.playground/playground.xcworkspace/xcuserdata/cor.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoR/daily-programmer/master/312-easy/312-easy.playground/playground.xcworkspace/xcuserdata/cor.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/364-easy/364-easy.playground/playground.xcworkspace/xcuserdata/cor.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoR/daily-programmer/master/364-easy/364-easy.playground/playground.xcworkspace/xcuserdata/cor.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/312-intermediate/312-intermediate.playground/playground.xcworkspace/xcuserdata/cor.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoR/daily-programmer/master/312-intermediate/312-intermediate.playground/playground.xcworkspace/xcuserdata/cor.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/364-easy/364-easy.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/312-intermediate/312-intermediate.playground/timeline.xctimeline:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
9 |
10 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/263-easy/263-easy.playground/Contents.swift:
--------------------------------------------------------------------------------
1 | //
2 | // 263-easy
3 | //
4 | // https://www.reddit.com/r/dailyprogrammer/comments/4fc896/20160418_challenge_263_easy_calculating_shannon/
5 | //
6 |
7 | import Foundation
8 |
9 | func shanonEntropy(sequence: String) -> Double {
10 |
11 | let n = Double(sequence.characters.count)
12 |
13 | return -Set(sequence.characters).map {
14 |
15 | (character) -> Double in
16 |
17 | let occurranceCount = Double(sequence.characters.reduce(0) {
18 | (accumulator: Int, currentCharacter: Character) -> Int in
19 | return currentCharacter == character ? accumulator + 1 : accumulator
20 | })
21 |
22 | return (occurranceCount / n) * log2(occurranceCount / n)
23 | }.reduce(0, combine: +)
24 | }
25 |
26 | shanonEntropy("122333444455555666666777777788888888")
27 | shanonEntropy("563881467447538846567288767728553786")
28 | shanonEntropy("https://www.reddit.com/r/dailyprogrammer")
29 | shanonEntropy("int main(int argc, char *argv[])")
30 |
--------------------------------------------------------------------------------
/312-easy/312-easy.playground/Contents.swift:
--------------------------------------------------------------------------------
1 | import UIKit
2 |
3 | let substitituions: [Character: String] = [
4 | "A": "4",
5 | "B": "6",
6 | "E": "3",
7 | "I": "1",
8 | "L": "|",
9 | "M": "(V)",
10 | "N": "(\\)",
11 | "O": "0",
12 | "S": "5",
13 | "T": "7",
14 | "V": "\\/",
15 | "W": "`//"
16 | ]
17 |
18 |
19 | extension Character {
20 | // Using String's uppercased method since Character doesn't have it
21 | func uppercased() -> Character {
22 | return Character(String(self).uppercased())
23 | }
24 | }
25 |
26 | func substituteCharacter(character: Character) -> String {
27 | // If the Character is in the substitions dictionary, substitute it, else return the Character itself as a String
28 | if let substititution = substitituions[character.uppercased()] {
29 | return substititution
30 | } else {
31 | return String(character)
32 | }
33 | }
34 |
35 | func convertTo1337(input: String) -> String {
36 | return input.characters.map(substituteCharacter).joined()
37 | }
38 |
39 | func convertFrom1337(input: String) -> String {
40 | var result = input
41 | for (normal, leetSubstititon) in substitituions {
42 | result = result.replacingOccurrences(of: leetSubstititon, with: String(normal))
43 | }
44 | return result
45 | }
46 |
47 | print(convertTo1337(input: "Elitemom"))
48 | print(convertFrom1337(input: "3|173(V)0(V)"))
49 |
50 |
--------------------------------------------------------------------------------
/312-intermediate/312-intermediate.playground/Contents.swift:
--------------------------------------------------------------------------------
1 | import UIKit
2 |
3 |
4 | // Heap's permutation algorithm as a String extension
5 | extension String {
6 |
7 | var permutations: [String] {
8 | get {
9 | func perm(n: Int, a: inout [Character], result: inout [String]) {
10 | if n == 1 {result.append(String(a)); return}
11 | for i in 0.. Int {
30 |
31 | // 1. Convert Input to a String
32 | // 2. Use String's permutation extension to get all permutations
33 | // 3. Remove Duplicates by converting to Set and back to Array
34 | // 4. Cast all String's to Int's
35 | // 5. Sort
36 | let permutations = Array(Set(String(input).permutations))
37 | .flatMap{Int($0)}
38 | .sorted()
39 |
40 | // Force unwrap because input is always in permutations
41 | let indexOfInput = permutations.index(of: input)!
42 |
43 | // If the input is already the largest possible permutation, return input
44 | if indexOfInput == permutations.count - 1 {
45 | return input
46 | } else {
47 | return permutations[indexOfInput + 1]
48 | }
49 | }
50 |
51 |
52 | let challangeInput = [1234, 1243, 234765, 19000]
53 |
54 | print(challangeInput.map(nextLargestInt))
55 |
--------------------------------------------------------------------------------
/364-easy/364-easy.playground/Contents.swift:
--------------------------------------------------------------------------------
1 | //: A UIKit based Playground for presenting user interface
2 |
3 | import UIKit
4 | import PlaygroundSupport
5 |
6 | class MyViewController : UIViewController {
7 | override func loadView() {
8 | let view = UIView()
9 | view.backgroundColor = .white
10 |
11 | let margins = view.safeAreaLayoutGuide
12 |
13 | let label = UILabel()
14 | label.frame = CGRect(x: 0, y: 200, width: 200, height: 20)
15 | label.text = "Vrienden"
16 | label.textColor = .darkGray
17 | label.font = UIFont.systemFont(ofSize: 24, weight: .bold)
18 |
19 |
20 | view.addSubview(label)
21 |
22 | label.topAnchor.constraint(equalTo: margins.topAnchor, constant: 8).isActive = true
23 | label.leadingAnchor.constraint(equalTo: margins.leadingAnchor, constant: 8).isActive = true
24 |
25 | self.view = view
26 | }
27 |
28 | override func touchesEnded(_ touches: Set, with event: UIEvent?) {
29 | for touch in touches {
30 | let cv = circleView(location: touch.location(in: self.view), radius: 25)
31 | view.addSubview(cv)
32 | }
33 | }
34 |
35 | override func touchesMoved(_ touches: Set, with event: UIEvent?) {
36 | for touch in touches {
37 | print(touch.force)
38 | let cv = circleView(location: touch.location(in: self.view), radius: 25)
39 | view.addSubview(cv)
40 | }
41 | }
42 |
43 | private func circleView(location: CGPoint, radius r: CGFloat) -> UIView {
44 | let backgroundColors = [#colorLiteral(red: 0.5725490451, green: 0, blue: 0.2313725501, alpha: 1), #colorLiteral(red: 0.3411764801, green: 0.6235294342, blue: 0.1686274558, alpha: 1), #colorLiteral(red: 0.5568627715, green: 0.3529411852, blue: 0.9686274529, alpha: 1)]
45 | let view = UIView(frame: CGRect(x: location.x - r, y: location.y - r, width: r*2, height: r*2))
46 | view.backgroundColor = backgroundColors.randomElement()
47 | view.layer.cornerRadius = r
48 | return view
49 | }
50 | }
51 | // Present the view controller in the Live View window
52 | PlaygroundPage.current.liveView = MyViewController()
53 |
--------------------------------------------------------------------------------