Skip to content

Instantly share code, notes, and snippets.

View koogawa's full-sized avatar
🏠
Working from home

Kosuke Ogawa koogawa

🏠
Working from home
View GitHub Profile
import Foundation
let n = Int(readLine()!)!
let aa = readLine()!.split(separator:" ").map { Int(String($0))! }
var nodes: [Int?] = .init(repeating: nil, count: n)
func dp(_ i: Int) -> Int {
if let r = nodes[i] { return r }
if i == 0 { return 0 }
import Foundation
let input = readLine()!.split(separator:" ").map { Int(String($0))! }
var (N, X, Y) = (input[0], input[1], input[2])
var ans = 0
for _ in 2..<N {
ans = (X + Y) % 100
X = Y
Y = ans
@koogawa
koogawa / swiftzoomin3.md
Last active July 11, 2020 15:10
Swift Zoomin' #3 質問まとめ

Swift Zoomin' #3 - connpass 質問まとめ

@koogawa
koogawa / ViewController.swift
Created March 13, 2017 09:06
Get category id from category name
class Category: CustomStringConvertible {
var id: String
var name: String
init(id: String, name: String) {
self.id = id
self.name = name
}
var description: String {
if CMPedometer.isStepCountingAvailable() {
self.pedometer.startUpdates(from: NSDate() as Date) {
(data: CMPedometerData?, error) -> Void in
// アクティビティが変化するたびに呼ばれる
DispatchQueue.main.async(execute: { () -> Void in
if (error == nil) {
let steps = data!.numberOfSteps
self.stepLabel.text = "steps: \(steps)"
}
})
@koogawa
koogawa / CodePiece.swift
Created May 15, 2016 03:32
ベニューを取ってきてTableViewに表示するだけなら30行ぐらいで実装できそう #4sqdevjp #CodePiece
import UIKit
import RxSwift
import RxCocoa
class ViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
var viewModel = ViewModel()
var dataSource = DataSource()
@koogawa
koogawa / CodePiece.swift
Created July 28, 2015 13:11
CodePiece build: 8 テスト #CodePiece
import Realm
class Book : RLMObject {
dynamic var isbn = ""
dynamic var name = ""
dynamic var price = 0
}
@koogawa
koogawa / CodePiece.swift
Created July 28, 2015 01:26
ソースコードのキャプチャ付きツイートテスト #CodePiece
private func buildQueryString(fromDictionary parameters: [String: String]) -> String {
var urlVars = [String]()
for (key, var val) in parameters {
val = val.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!
urlVars += [key + "=" + "\(val)"]
}
return (!urlVars.isEmpty ? "?" : "") + join("&", urlVars)
}
@koogawa
koogawa / CodePiece.swift
Created July 25, 2015 04:08
テスト:DictionaryからAPIに投げるSTRINGを作るメソッド #cswift #CodePiece
func buildQueryString(fromDictionary parameters: [String: String]) -> String {
var urlVars = [String]()
for (key, var val) in parameters {
val = val.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!
urlVars += [key + "=" + "\(val)"]
}
return (!urlVars.isEmpty ? "?" : "") + join("&", urlVars)
}
import UIKit
import MapKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var mapRect: CGRect = CGRect(x:0, y:0,
width:self.view.frame.size.width, height:self.view.frame.size.height)