전체 글 261

<함수형 프로그래밍> 3.5편 클로저(Closure)

스위프트에서 클로져가 클로저를 감싸는 주변 콘텍스트?(변수,상수)를 캡쳐한다는데 캡쳐한다는게 항상 무슨 의미인지 정확히 이해가 안됬다. 함수가 스택에서 제거되도 지우지 않고 남겨논다는 건가? 원래 제거되면 제거되는거지 도대체 왜 남는거지?? 클로저 표현식 문법(Closure Expression Syntax) 클로저 표현식 문법의 일반 형식은 다음과 같음. { (parameters) -> return type in statements } 클로저의 내용은 in 키워드로 시작하며 이 키워드는 클로저 인자와 반환 타입의 정의가 끝났고 클로저 내용이 시작함을 가르킴. Capturing Values A closure can capture constants and variables from the surroundin..

<함수형 프로그래밍> 3편, 유틉 강의정리, composable,transducer,reducer

[https://www.youtube.com/watch?v=estNbh2TF3E] 이 강의 정리한다. function comporision - swift methods are not composable - we should do everthing to promote composition - curried functions are highly composable 왜 메소드가 not composable인가 말해본다. 음 근데 난 컴포저블이 뭔지 모르겠는데; import Foundation extension Int { func square () -> Int{ return self * self } func incr() -> Int{ return self + 1 } } 3.square().incr() let xs..

<스위프트&알고리즘> 백준 11720번

일단 이 에러는 이렇게 해결해야 하는거 같다. 근데 에러 의미가 이해가 안되네, initializer init이 이게 Int() 캐스팅 말하는거 같고 character가 그렇게 되려면 StringProtocol에 따라야 한다는 말같다. import Foundation readLine() let str = readLine()! //let arr = str?.split(separator: "") var arr : [Character] = [] for index in str.indices{ arr.append( str[index] ) } var sum : Int = arr.map{Int($0.asciiValue! - "0".first!.asciiValue!)}.reduce(0, { (result :Int, e..

카테고리 없음 2020.04.17

<스위프트&알고리즘> 프로그래머스 가장 긴 팰린드롬

[https://programmers.co.kr/learn/courses/30/lessons/12904?language=swift] 아 왜 틀리는거야 import Foundation func solution(_ s:String) -> Int { // [실행] 버튼을 누르면 출력 값을 볼 수 있습니다. //print("Hello Swift") var ans = 0 for x in 0...s.count{ var left=s.index(s.startIndex, offsetBy: x) var right = left var dis = 0 repeat{ dis += 1 left = s.index(s.startIndex, offsetBy: -dis) right = s.index(s.endIndex , offsetBy..

카테고리 없음 2020.04.16

<스위프트&알고리즘> 10818번 최소, 최대

둘다 정답 코드에서 갖고 온것이다. let N = readLine() let input = readLine()!.split(separator: " ").map() { Int(String($0))! } var min = 1000000 var max = -1000000 for i in input { if min > i { min = i } if max < i { max = i } } print("\(min) \(max)") this got correct while the beneth it got timed out , though its on the answer board;; readLine() let a=readLine()!.split{$0==" "}.map{Int($0)!} print("\(a.min()!..

<스위프트&알고리즘> 못풀음, 동전2 2294번

일단 2294번 한다. // // main.swift // algorithm_practice // // Created by 김동환 on 2020/04/16. // Copyright © 2020 김동환. All rights reserved. // import Foundation let line = readLine() let inputs = line?.split(separator : " ") ?? [] let n = Int(inputs.first ?? "") ?? 0 let k = Int(inputs.last ?? "" ) ?? 0 var coins: [Int] = [] var answer : [Int] = [0] for _ in 0..= coin, answer[o-coin] >= 0{ candidates...

<함수형 프로그래밍> 2편, Functional Thinking 함수형 사고지음 : 닐 포드

[https://www.youtube.com/watch?v=estNbh2TF3E&list=PLnVmIi3a0KsNhMHTImsGL75PpGS9sY5xj&index=21&t=0s] 스위프트 함수형 프로그래밍 강의인데 아직 안봄. 음 봤는데, 잘 모르겠음 리듀서 트랜듀서 컴포저블등.. 음 어느 맥락에서 이걸 소개하는지 모르겠다 그래도 일단 이런게 있구나 했음. [http://www.jangun.com/study/FunctionalThinking.html] 함수형 프로그래밍 전체적인 설명 , 글임. Functional Thinking 함수형 사고 지음 : 닐 포드 김재완 옮김 목차 요약 Chapter 1 왜 Chapter 2 전환 Chapter 3 양도하라 Chapter 4 열심히 보다는 현명하게 Chapte..

<함수형 프로그래밍> 1편,Swift 3 functional programming 책 정리 내용

책을 선택 했다. Swift 3 functional programming 일단 챕터 1 . Getting Started with Functional Programming in Swift - why functional programming matters? - what is functional programming? - swift language basics - immutability - first-class , higher-order, and pure functions - Optionals and pattern matching - closures - type aliasing why functional programming matters? 일단 첫페이지 보니까. 소프트웨어가 복잡해지고 그러니까 계층을 분리하..

<프로그래밍 언어> 함수형 프로그래밍 - 0편, es6로 하는 fp

[https://www.youtube.com/watch?v=4sO0aWTd3yc] 네이버 디투 강의다 책도 여기서 추천했다. 프로그램 디자인 어떻게 할것인가.[https://www.aladin.co.kr/shop/wproduct.aspx?ItemId=11329212] 컴퓨터 프로그램의 구조와 해석. [http://book.interpark.com/product/BookDisplay.do?_method=detail&sc.prdNo=249235302&gclid=Cj0KCQjwm9D0BRCMARIsAIfvfIamtTBghBnTsjsypgKK9uH0TZ41Ewpcw97ARq8st8swOoAl_ZWa2ngaAq3cEALw_wcB] 그렇게 안보이지만 둘다 함수형 프로그래밍 언어 책이라 한다. 필터는 반복문 내부의 ..