-
Notifications
You must be signed in to change notification settings - Fork 18
/
arrow.swift
40 lines (35 loc) · 981 Bytes
/
arrow.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// main.swift
// arrow.swift
//
// Created by Richard on 14.09.18.
// Copyright © 2018 epfl-dojo. All rights reserved.
//
import Foundation
print("Enter your values between 2 - 20 and press [Enter]:")
let nbr = readLine()
let width = Int(nbr!)!
func drawTail(nbr:Int) {
let s = String(repeating:" ", count:nbr-1)
for _ in 1...nbr {
print(s + "*")
}
}
func drawHead(nbr:Int) {
let s = String(repeating:" ", count:nbr-1)
print(s + "*")
}
func drawBody(nbr:Int) {
var number_of_spaces_between = 1
let bottom_part = String(repeating:"*", count:(nbr*2)-1)
for i in (1...nbr-2).reversed(){
let space_around = String(repeating:" ", count:i)
let space_between = String(repeating:" ", count:number_of_spaces_between)
print(space_around + "*" + space_between + "*" + space_around)
number_of_spaces_between += 2
}
print(bottom_part)
}
drawHead(nbr:width)
drawBody(nbr:width)
drawTail(nbr:width)