Skip to content

Commit b202187

Browse files
authored
Merge branch 'master' into master
2 parents 7362bdf + bba4954 commit b202187

File tree

4 files changed

+424
-368
lines changed

4 files changed

+424
-368
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ If you fixed or added something useful to the project, you can send pull-request
1515
Bugs
1616
----
1717

18-
If you found an error, mistype or any other flawback in the project, please report about it using [issues](https://github.com/Thuva4/Algorithms_Example/issues).
18+
If you found an error, mistype or any other flaw in the project, please report about it using [issues](https://github.com/Thuva4/Algorithms_Example/issues).
1919
The more details you provide, the easier it can be reproduced and the faster can be fixed.
2020
Unfortunately, sometimes the bug can be only reproduced in your project or in your environment, so maintainers cannot reproduce it. In this case we believe you can fix the bug and send us the fix.
2121

@@ -24,13 +24,13 @@ Unfortunately, sometimes the bug can be only reproduced in your project or in yo
2424

2525
1. Fork this repository.
2626

27-
2. Check the table in README.md file weather the algorithm is added. If not add a new row with the name of algorithm and create a new folder with a name of the algorithm.
27+
2. Check the table in the README.md file to see if the algorithm has already been added. If not, add a new row with the name of algorithm and create a new folder with a name of the algorithm.
2828

29-
3. Inside the folder create the folder for language you want to share. and add your code.
29+
3. Inside the folder create the folder for language you want to share and add your code.
3030

3131
5. Commit
3232

33-
6. Update the README.md. check the language you have used in the table. (check emoji is ``:+1:`` )
33+
6. Update the README.md. Check the language you have used in the table (check emoji is ``:+1:`` )
3434

3535
7. Commit, Push
3636

Doomsday/Swift/Doomsday.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
func dow(year: Int, month: Int, day: Int) -> Int {
2+
var year = year
3+
let t = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]
4+
year -= month < 3 ? 1 : 0
5+
return (year + year / 4 - year / 100 + year / 400 + t[month - 1] + day) % 7
6+
}
7+
8+
func dowS(year: Int, month: Int, day: Int) -> String {
9+
switch (dow(year: year, month: month, day: day)) {
10+
case 0: return "Sunday"
11+
case 1: return "Monday"
12+
case 2: return "Tuesday"
13+
case 3: return "Wednesday"
14+
case 4: return "Thursday"
15+
case 5: return "Friday"
16+
case 6: return "Saturday"
17+
default: return "Invalid ordinal"
18+
}
19+
}
20+
21+
print("\(dow(year: 1886, month: 5, day: 1)): \(dowS(year: 1886, month: 5, day: 1))")
22+
print("\(dow(year: 1948, month: 12, day: 10)): \(dowS(year: 1948, month: 12, day: 10))")
23+
print("\(dow(year: 2001, month: 1, day: 15)): \(dowS(year: 2001, month: 1, day: 15))")
24+
print("\(dow(year: 2017, month: 10, day: 10)): \(dowS(year: 2017, month: 10, day: 10))")
25+
print("\(dow(year: 2018, month: 1, day: 1)): \(dowS(year: 2018, month: 1, day: 1))")
26+
print("\(dow(year: 2018, month: 2, day: 16)): \(dowS(year: 2018, month: 2, day: 16))")
27+
print("\(dow(year: 2018, month: 5, day: 17)): \(dowS(year: 2018, month: 5, day: 17))")
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Hamming distance between two strings of equal length:
2+
// sum the number of positions where the two strings are different
3+
function hammingDistance (s1, s2) {
4+
if(s1.length !== s2.length) throw 'The two strings must have equal length'
5+
let distance = 0
6+
for (let i = 0; i < s1.length; i++) {
7+
if (s1.charAt(i) !== s2.charAt(i)) {
8+
distance++
9+
}
10+
}
11+
return distance
12+
}
13+
14+
// EXAMPLE:
15+
const s1 = 'bend'
16+
const s2 = 'bond'
17+
console.log(hammingDistance(s1,s2))

0 commit comments

Comments
 (0)