Skip to content

Commit 56279e6

Browse files
committed
Implementa Isogram em Golang
1 parent 5a6dfa3 commit 56279e6

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

README.md

+58
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,64 @@ Com o objetivo de alcançar uma abrangência maior e encorajar mais pessoas a co
15141514
</a>
15151515
</td>
15161516
</tr>
1517+
<tr>
1518+
<td><a href="https://www.geeksforgeeks.org/check-if-all-given-strings-are-isograms-or-not/">Algoritmo Isogram</a></td>
1519+
<td> <!-- C -->
1520+
<a href="./CONTRIBUTING.md">
1521+
<img align="center" height="25" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/github/github-original.svg" />
1522+
</a>
1523+
</td>
1524+
<td> <!-- C++ -->
1525+
<a href="./CONTRIBUTING.md">
1526+
<img align="center" height="25" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/github/github-original.svg" />
1527+
</a>
1528+
</td>
1529+
<td> <!-- Java -->
1530+
<a href="./CONTRIBUTING.md">
1531+
<img align="center" height="25" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/github/github-original.svg" />
1532+
</a>
1533+
</td>
1534+
<td> <!-- Python -->
1535+
<a href="./CONTRIBUTING.md">
1536+
<img align="center" height="25" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/github/github-original.svg" />
1537+
</a>
1538+
</td>
1539+
<td> <!-- Go -->
1540+
<a href="./src/go/isogram.go">
1541+
<img align="center" height="25" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/go/go-original.svg" />
1542+
</a>
1543+
</td>
1544+
<td> <!-- Ruby -->
1545+
<a href="./CONTRIBUTING.md">
1546+
<img align="center" height="25" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/github/github-original.svg" />
1547+
</a>
1548+
</td>
1549+
<td> <!-- JavaScript -->
1550+
<a href="./CONTRIBUTING.md">
1551+
<img align="center" height="25" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/github/github-original.svg" />
1552+
</a>
1553+
</td>
1554+
<td> <!-- Swift -->
1555+
<a href="./CONTRIBUTING.md">
1556+
<img align="center" height="25" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/github/github-original.svg" />
1557+
</a>
1558+
</td>
1559+
<td> <!-- Rust -->
1560+
<a href="./CONTRIBUTING.md">
1561+
<img align="center" height="25" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/github/github-original.svg" />
1562+
</a>
1563+
</td>
1564+
<td> <!-- Scala -->
1565+
<a href="./CONTRIBUTING.md">
1566+
<img align="center" height="25" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/github/github-original.svg" />
1567+
</a>
1568+
</td>
1569+
<td> <!-- Kotlin -->
1570+
<a href="./CONTRIBUTING.md">
1571+
<img align="center" height="25" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/github/github-original.svg" />
1572+
</a>
1573+
</td>
1574+
</tr>
15171575
</table>
15181576
<table align="center">
15191577
<tr>

src/go/isogram.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
"unicode"
7+
)
8+
9+
/*
10+
Instructions
11+
12+
Determine if a word or phrase is an isogram.
13+
14+
An isogram (also known as a "non-pattern word") is a word or phrase without a repeating letter,
15+
however spaces and hyphens are allowed to appear multiple times.
16+
17+
Examples of isograms:
18+
19+
>> lumberjacks
20+
>> background
21+
>> downstream
22+
>> six-year-old
23+
24+
The word isograms, however, is not an isogram, because the s repeats.
25+
*/
26+
func main() {
27+
fmt.Println(IsIsogram("isograms"))
28+
fmt.Println(IsIsogram("isogram"))
29+
}
30+
31+
// IsIsogram returns true if the input s is an isogram
32+
func IsIsogram(word string) bool {
33+
word = strings.ToLower(word)
34+
for i, c := range word {
35+
if unicode.IsLetter(c) && strings.ContainsRune(word[i+1:], c) {
36+
return false
37+
}
38+
}
39+
return true
40+
}

0 commit comments

Comments
 (0)