Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module com.github/honestit/homework

go 1.16

require github.com/kyokomi/emoji v2.2.4+incompatible
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/kyokomi/emoji v2.2.4+incompatible h1:np0woGKwx9LiHAQmwZx79Oc0rHpNw3o+3evou4BEPv4=
github.com/kyokomi/emoji v2.2.4+incompatible/go.mod h1:mZ6aGCD7yk8j6QY6KICwnZ2pxoszVseX1DNoGtU2tBA=
6 changes: 3 additions & 3 deletions ls_0/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Introduction task

The purpose of this task is to figure out with basic tooling of the Golang as well as check your IDE setup.
The purpose of this task is to figure out how to use basic tooling of the Golang as well as check your IDE setup.

Task:
* Initialize project with Go modules
* Add dependency "github.com/kyokomi/emoji" to add emojy into the string
* Using Sprint function from this package build a message "Hello from 🇵🇱!"

To run tests for run cmd "cmd test -v ."
Tasks considered as completed in case tests are not failed
To run tests for run cmd "go test -v ."
Tasks considered as completed in case test is not failed
53 changes: 53 additions & 0 deletions module-2/task1/fibonacci/fibonacci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package fibonacci

func Fibonacci(n interface{}) interface{} {
switch v := n.(type) {
case uint:
return fibonnaciUint(v)
case int:
return fibonnaciInt(v)
case float64:
return fibonnaciFloat(v)
}
return nil

}

func fibonnaciUint(n uint) uint {
if n == 0 {
return 0
}
if n == 1 {
return 1
}
if n == 2 {
return 1
}
return fibonnaciUint(n-1) + fibonnaciUint(n-2)
}

func fibonnaciInt(n int) int {
if n == 0 {
return 0
}
if n == 1 {
return 1
}
if n == 2 {
return 1
}
return fibonnaciInt(n-1) + fibonnaciInt(n-2)
}

func fibonnaciFloat(n float64) float64 {
if n == 0 {
return 0
}
if n == 1 {
return 1
}
if n == 2 {
return 1
}
return fibonnaciFloat(n-1) + fibonnaciFloat(n-2)
}
3 changes: 3 additions & 0 deletions module-2/task1/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module honestit/computator

go 1.16
35 changes: 35 additions & 0 deletions module-2/task1/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"fmt"
"honestit/computator/fibonacci"
"strconv"
)

func main() {
var input string

fmt.Print("Provide a number for fibonnaci function: ")
fmt.Scanf("%s", &input)

n, err := cast(input)
if err == nil {
fib := fibonacci.Fibonacci(n)
fmt.Printf("Fibonacci for %v = %v", n, fib)
} else {
fmt.Printf("Something wrong with your input: %q", input)
}

}

func cast(input string) (interface{}, error) {
if v, err := strconv.ParseInt(input, 0, 0); err == nil {
return int(v), nil
} else if v, err := strconv.ParseUint(input, 0, 0); err == nil {
return uint(v), nil
} else if v, err := strconv.ParseFloat(input, 64); err == nil {
return float64(v), nil
} else {
return nil, fmt.Errorf("not a number")
}
}