Created
July 10, 2017 09:55
-
-
Save Zedd0202/a15f5cb025df6b3305aa440778f04491 to your computer and use it in GitHub Desktop.
Pascal's triangle Mission
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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