본문 바로가기

분류 전체보기

(465)
[EP0062] 같은 숫자로 이루어진 세제곱이 다섯개 #!/usr/bin/env python # Project Euler 62 # http://projecteuler.net/index.php?section=problems&id=62 # Problem 62 # # The cube, 41063625 (3453), can be permuted to produce two other cubes: # 56623104 (3843) and 66430125 (4053). In fact, 41063625 is the smallest # cube which has exactly three permutations of its digits which are also # cube. # # Find the smallest cube for which exactly five permut..
[C] 4x4 수도쿠 코드 // sudoku4x4.cpp : Defines the entry point for the console application. // // #include "stdafx.h" #include #include int g_num_solutions = 0; void find_sudoku_pan(int *pan); // // 최초의 판 모양은 // // 01-- // 23-- // ---- // ---- void init_pan(int *pan) { for (int i = 0; i < 16; i++) *(pan + i) = -1; *(pan + 4 * 0 + 0) = 0; // [0][0] *(pan + 4 * 0 + 1) = 1; // [0][1] *(pan + 4 * 1 + 0) = 2; // [1][0] ..
[Python] 2117658/8642334 와 연분수표현 2117658/8642334 각 디지트의 연분수꼴의 값이 같다는 신기한 글을 봐서 파이썬으로 계산을 해 봤다. >>> from fractions import Fraction >>> l1 = list(map(int, "2117658")) >>> l2 = list(map(int, "8642334")) >>> def frac(l1, l2): if len(l1) == 1: return Fraction(l1[0], l2[0]) return l1[0]/(l2[0] + frac(l1[1:], l2[1:])) >>> frac(l1, l2) Fraction(37, 151) >>> Fraction(2117658, 8642334) Fraction(37, 151) 이런 꼴의 결과를 주는 다른 숫자도 찾아보고 싶네.
[SwiftUI] @State, struct, class https://www.hackingwithswift.com/books/ios-swiftui/why-state-only-works-with-structs why state only works with structs 라는 제목의 강의. swiftui 에서 변경될 수 있는 변수에 @State 를 붙이는 것에 익숙해졌다. 이 @State 변수에는 스위프트의 기본 형 뿐만 아니라, 사용자형도 사용할 수 있다. 다음과 같다. struct User { var firstName = "Bilbo" var lastName = "Baggins" } struct ContentView: View { @State private var user = User() var body: some View { VStack { VStack {..
[Swift] publishing changes from background threads is not allowed; make sure to publish values from the main thread swiftui 에서 async 콘텍스트에서 UI 와 관련된 변수를 업데이트할 때 발생한다. xcode에서 보라색으로 나타나는 워닝이다. UI 관련 변수를 업데이트할 때에는 main 쓰레드에서 업데이트 될 수 있도록, await MainActor.run { } 블록으로 감싸주어야 한다. 이 방법은 이전에 사용하던 DispatchQueue.main 을 대체하는 방식이다. 이 방법도 가능하지만, 더 아름다운 방식은, @MainActor 어노테이션을 사용하는 것. 해당 변수를 업데이트하는 코드가 들어있는 함수 선언에 어노테이션을 더해준다. @MainActor func uiUpdateFunc() - ref : Modern Concurrency in Swift Chapter 1, 2
[Python초보] ValueError: invalid literal for int() with base 10: '' invalid literal for int() with base 10: '' 10진수 int() 로 변환할 수 없는 문자열: '' 이라는 뜻입니다. 한번 이 에러를 만들어 봅시다. >>> num = int("1000") >>> num 1000 "1000" 이라는 문자열을 숫자형으로 변환하여 num 이란 변수에 넣는 코드입니다. "1000"이라는 문자열은 정수를 나타내는 문자열이기 때문에, 문제없이 변환됩니다. >>> s = "abc" >>> num = int(s) Traceback (most recent call last): File "", line 1, in num = int(s) ValueError: invalid literal for int() with base 10: 'abc' "abc" 라는 문..
[SWIFT] dump() 함수 출력을 문자열로 바꾸는 방법 dump 함수는 클래스 인스턴스의 내부 속성까지 간단히 출력해 주기 때문에 디버깅시에 편리하다. 그런데, 출력 내용을 문자열로 저장하여, stdout, stderr 가 아닌 곳으로도 출력/저장하고 싶었다. 스택오버플로우에 간단한 답변이 있었다. https://stackoverflow.com/a/42094841/100093 let myClass = MyClass() var myClassDumped = String() dump(myClass, to: &myClassDumped) https://github.com/apple/swift/blob/master/stdlib/public/core/OutputStream.swift 위 링크를 인용하고 있는데, 직접 영문설명을 읽어보는 게 좋겠지만, 요약하면, print..
Xcode 프로젝트 안의 타겟들 한꺼번에 빌드하기 https://stackoverflow.com/a/69228719/100093 Xcode - Building for Multiple Targets Simultaneously I have one Xcode project with multiple targets. During development, it is becoming laborious to compile and install each separately. Is there a way, through scripting or otherwise; that I can auto... stackoverflow.com Xcode 메뉴 중 Product > Scheme > Manage Schemes 을 보면 자동으로 만들어진 스킴들을 볼 수 있음. 액티브 스킴 편집으..