forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request JuliaLang#26 from andrej-makarov-skrt/master
Fix indentation to follow guide rules
- Loading branch information
Showing
15 changed files
with
190 additions
and
196 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,42 @@ | ||
# Anagrams are two or more words that composed of the same characters but in a different order | ||
|
||
function is_anagram(s1::AbstractString, s2::AbstractString) | ||
# Disable case sensitivity | ||
s1 = lowercase(s1) | ||
s2 = lowercase(s2) | ||
# Disable case sensitivity | ||
s1 = lowercase(s1) | ||
s2 = lowercase(s2) | ||
|
||
# Similar and different-length strings are not anagrams | ||
if length(s1) != length(s2) || s1 == s2 | ||
return false | ||
end | ||
# Similar and different-length strings are not anagrams | ||
if length(s1) != length(s2) || s1 == s2 | ||
return false | ||
end | ||
|
||
# Calculate count of every character in the first string | ||
chr_count = Dict() | ||
for c in s1 | ||
chr_count[c] = get(chr_count, c, 0) + 1 | ||
end | ||
# Calculate count of every character in the first string | ||
chr_count = Dict() | ||
for c in s1 | ||
chr_count[c] = get(chr_count, c, 0) + 1 | ||
end | ||
|
||
# Reduce the count by every character from the second string | ||
for c in s2 | ||
t = get(chr_count, c, 0) - 1 | ||
if t < 0 | ||
# Got character that not exist in the first string | ||
return false | ||
else | ||
chr_count[c] = t | ||
# Reduce the count by every character from the second string | ||
for c in s2 | ||
t = get(chr_count, c, 0) - 1 | ||
if t < 0 | ||
# Got character that not exist in the first string | ||
return false | ||
else | ||
chr_count[c] = t | ||
end | ||
end | ||
end | ||
|
||
# Check all counts to be zeroes | ||
return all(i->(i==0), values(chr_count)) | ||
# Check all counts to be zeroes | ||
return all(i->(i==0), values(chr_count)) | ||
end | ||
|
||
function detect_anagrams(subject::AbstractString, candidates::AbstractArray) | ||
result = [] | ||
for candidate = candidates | ||
if is_anagram(subject, candidate) | ||
push!(result, candidate) | ||
result = [] | ||
for candidate = candidates | ||
if is_anagram(subject, candidate) | ||
push!(result, candidate) | ||
end | ||
end | ||
end | ||
result | ||
result | ||
end | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,6 @@ function isshouting(stimulus::AbstractString) | |
return false | ||
end | ||
end | ||
|
||
return true | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
function distance(s1::AbstractString, s2::AbstractString) | ||
length(s1) != length(s2) && throw(ArgumentError("Sequences must have the same length")) | ||
|
||
reduce(+, 0, a != b for (a, b) in zip(s1, s2)) | ||
end |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
# Given a DNA strand, its transcribed RNA strand is formed by replacing each nucleotide with its complement: | ||
# G -> C, C -> G, T -> A, A -> U | ||
function to_rna(dna::AbstractString) | ||
typeof(match(r"^[GCTA]+$", dna)) == Void && error("Invalid RNA strand") | ||
# Define character associations | ||
a_nucleotides = Dict('G'=>'C', 'C'=>'G', 'T'=>'A', 'A'=>'U') | ||
# Replace characters using dictionary | ||
map((x)->a_nucleotides[x], dna) | ||
typeof(match(r"^[GCTA]+$", dna)) == Void && error("Invalid RNA strand") | ||
# Define character associations | ||
a_nucleotides = Dict('G'=>'C', 'C'=>'G', 'T'=>'A', 'A'=>'U') | ||
# Replace characters using dictionary | ||
map((x)->a_nucleotides[x], dna) | ||
end | ||
|
Oops, something went wrong.