-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
228 additions
and
217 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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func BinarySearch(seq []int, element, start, end int) int { | ||
index := (start + end) / 2 | ||
|
||
if index < len(seq) && seq[index] == element { | ||
return index | ||
} | ||
|
||
if start != end { | ||
if seq[index] < element { | ||
return BinarySearch(seq, element, index+1, end) | ||
} | ||
|
||
return BinarySearch(seq, element, start, index-1) | ||
} | ||
|
||
return -1 | ||
} | ||
|
||
func main() { | ||
value := 7 | ||
slice := []int{1, 2, 3, 4, 5, 6, 7, 8, 9} | ||
fmt.Println("Slice:", slice) | ||
index := BinarySearch(slice, value, 0, len(slice)) | ||
fmt.Println("Value", value, "found in index:", index) | ||
} |
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
|
@@ -36,9 +36,7 @@ | |
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
import "fmt" | ||
|
||
var nroVertices = 5 | ||
|
||
|
8 changes: 7 additions & 1 deletion
8
src/go/exponenciacao/exponenciacao.go → src/go/exponenciacao.go
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,8 +1,14 @@ | ||
package exponenciacao | ||
package main | ||
|
||
import "fmt" | ||
|
||
func Exponenciacao(base int, expoente int) int { | ||
for index := 0; index < (expoente - 1); index++ { | ||
base *= expoente | ||
} | ||
return base | ||
} | ||
|
||
func main() { | ||
fmt.Println("Exponenciacao:", Exponenciacao(5, 5)) | ||
} |
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,8 +1,14 @@ | ||
package fatorial | ||
package main | ||
|
||
import "fmt" | ||
|
||
func Fatorial(value int) int { | ||
if value == 1 { | ||
return 1 | ||
} | ||
return value * Fatorial(value-1) | ||
} | ||
|
||
func main() { | ||
fmt.Println("Fatorial:", Fatorial(6)) | ||
} |
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,8 +1,14 @@ | ||
package fibonacci | ||
package main | ||
|
||
import "fmt" | ||
|
||
func Fibonacci(value int) int { | ||
if value <= 1 { | ||
return 1 | ||
} | ||
return Fibonacci(value-1) + Fibonacci(value-2) | ||
} | ||
|
||
func main() { | ||
fmt.Println("Fibonacci:", Fibonacci(9)) | ||
} |
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
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
File renamed without changes.
File renamed without changes.
Oops, something went wrong.