Skip to content

Commit

Permalink
Some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurwrls committed Oct 11, 2022
1 parent 2a25f50 commit 6f4f273
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ while num != 0 {
}

print(result)
// factorial using reppeat while
// factorial using repeat while

num = 5
result = 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
var text = ["h", "e", "l", "l", "o"]
var reversed = [String]()
var counter = text.count - 1

while counter >= 0 {
reversed.append(text[counter])
counter -= 1

}
if text == reversed {
print("We have a palindrome!")
} else {
print("We don’t have a palindrome")
}

/*
//with for in usage

var text = ["h", "e", "l", "l", "e", "h"]
var reversed = [String]()
var counter = text.count - 1

for x in 0 ..< text.count {
if x >= 0 {
reversed.append(text[counter])
counter -= 1
}
}
if text == reversed {
print("We have a palindrome!")
} else {
print("We don’t have a palindrome")
}


//with stride usage

var text = ["h", "e", "l", "l", "e"]
var reversed = [String]()
var counter = text.count - 1

for x in stride (from: 0, to: text.count, by: 1){
if x >= 0 {
reversed.append(text[counter])
counter -= 1
}
}
if text == reversed {
print("We have a palindrome!")
} else {
print("We don’t have a palindrome")
}



*/

0 comments on commit 6f4f273

Please sign in to comment.