Skip to content

Instantly share code, notes, and snippets.

@Zedd0202
Created July 10, 2017 09:55
Show Gist options
  • Save Zedd0202/a15f5cb025df6b3305aa440778f04491 to your computer and use it in GitHub Desktop.
Save Zedd0202/a15f5cb025df6b3305aa440778f04491 to your computer and use it in GitHub Desktop.
Pascal's triangle Mission
//
// main.swift
// Misson
//
// Created by woowabrothers on 2017. 7. 10..
// Copyright © 2017년 woowabrothers. All rights reserved.
//
import Foundation
print("Hello, World!")
func makePascalTriangle(numOfRows : Int) -> ([[Int]]) {
if numOfRows == 0 {
return []
}
var wholeArray = [[1]]
for i in 1..<numOfRows {
wholeArray.append([1])
for j in 1..<i {
wholeArray[i].append(wholeArray[i-1][j-1] + wholeArray[i-1][j])
}
wholeArray[i].append(1)
}
return wholeArray
}
for arg in CommandLine.arguments {
if let num = Int(arg) {
let resultValue = makePascalTriangle(numOfRows: num)
for value in resultValue {
print(value, terminator : " ")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment