Skip to content

Instantly share code, notes, and snippets.

@JuneBuug
Created July 10, 2017 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JuneBuug/ea5650104be8f58a8affc96d48fd7d5a to your computer and use it in GitHub Desktop.
Save JuneBuug/ea5650104be8f58a8affc96d48fd7d5a to your computer and use it in GitHub Desktop.
PascalTriangle
//
// main.swift
// swift-sample
//
// Created by woowabrothers on 2017. 7. 10..
// Copyright © 2017년 woowabrothers. All rights reserved.
//
import Foundation
func makePascalTriangle(numofRows : Int) -> [[Int]]{
var result = [[Int]]()
for i in 1...numofRows{
var rowArray = [Int]()
for j in 1...i{
rowArray.append(recurPascal(row: i, column: j))
}
result.append(rowArray)
}
return result
}
func recurPascal(row: Int ,column :Int) -> Int {
if(column == 1){
return 1 ;
}else if( row == column){
return 1 ;
}else{
return recurPascal(row: row - 1 , column : column - 1) + recurPascal(row: row - 1 , column: column)
}
}
for argument in CommandLine.arguments {
switch argument {
default:
let arg = Int(argument)
if( arg != nil ){
print(makePascalTriangle(numofRows: arg!))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment