-
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.
- Loading branch information
Showing
14 changed files
with
217 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main(){ | ||
sum := 1 | ||
|
||
for ; sum < 1000; { | ||
sum +=sum | ||
} | ||
|
||
fmt.Println(sum) | ||
} |
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,20 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
) | ||
|
||
|
||
func pow(x, n, lim float64) float64{ | ||
if v := math.Pow(x,n); v < lim { | ||
return v | ||
} | ||
return lim | ||
} | ||
|
||
func main(){ | ||
|
||
fmt.Println(pow(3,2,10)) | ||
fmt.Println(pow(3,3,10)) | ||
} |
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,13 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main(){ | ||
fmt.Println("Starting Program") | ||
|
||
for i:=0;i<10;i++{ | ||
defer fmt.Println(i) | ||
fmt.Println(i) | ||
} | ||
|
||
} |
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,19 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
|
||
|
||
func sumUp(n int) (sum int){ | ||
sum = 0 | ||
for i:=0;i<1+i;i++{ | ||
sum += i | ||
} | ||
|
||
return | ||
} | ||
|
||
|
||
func main(){ | ||
fmt.Println(sumUp(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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
import( | ||
"fmt" | ||
"math" | ||
) | ||
|
||
func sqrt(x float64) string{ | ||
if x<0{ | ||
return sqrt(-x) + "i" | ||
} | ||
|
||
return fmt.Sprint(math.Sqrt(x)) | ||
} | ||
|
||
func main(){ | ||
fmt.Println(sqrt(2), sqrt(-4) ) | ||
} |
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,23 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
) | ||
|
||
func pow(x, n, lim float64) float64{ | ||
if v:= math.Pow(x,n);v<lim{ | ||
return v | ||
}else{ | ||
fmt.Printf("%g =< %g", lim, v) | ||
} | ||
|
||
return lim | ||
|
||
} | ||
|
||
|
||
func main(){ | ||
fmt.Println(pow(3,2,10)) | ||
fmt.Println(pow(3,3,20)) | ||
} |
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,18 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
|
||
// For is Golang's while loop | ||
|
||
func main(){ | ||
sum := 0 | ||
|
||
for sum < 1000 { | ||
sum += sum | ||
} | ||
|
||
fmt.Println(sum) | ||
} | ||
|
||
// infinite for loop with for{} |
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,19 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"math/cmplx" | ||
) | ||
|
||
var ( | ||
ToBe bool = false | ||
MaxInt uint64 = 1<<64 - 1 | ||
z complex128 = cmplx.Sqrt(-5 + 12i) | ||
) | ||
|
||
|
||
func main(){ | ||
fmt.Printf("Type: %T Value: %v\n", ToBe,ToBe) | ||
fmt.Printf("Type: %T Value: %v\n", MaxInt, MaxInt) | ||
fmt.Printf("Type: %T Value: %v\n", z,z) | ||
} |
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,20 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
const ( | ||
// Create a huge number by shifting a 1 bit left 100 places. | ||
// In other words, the binary number that is 1 followed by 100 zeroes. | ||
Big = 1 << 100 | ||
// Shift it right again 99 places, so we end up with 1<<1, or 2. | ||
Small = Big >> 99 | ||
) | ||
|
||
func needInt(x int) int { return x*10 + 1 } | ||
func needFloat(x float64) float64 { | ||
return x * 0.1 | ||
} | ||
|
||
func main() { | ||
fmt.Printf(Big) | ||
} |
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,8 @@ | ||
package main | ||
import( | ||
"fmt" | ||
"math/rand" | ||
) | ||
func main(){ | ||
fmt.Println("My favorite Number is", rand.Intn(20)) | ||
} |
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,17 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
|
||
|
||
func split(sum int) (x,y,z int){ | ||
x = sum * 4/9 | ||
y = x * 5/8 | ||
z = x - y | ||
return | ||
} | ||
|
||
func main(){ | ||
fmt.Println(split(40)) | ||
} | ||
|
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,8 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main(){ | ||
x := 42 | ||
fmt.Printf("v is of Type %T", v) | ||
} |
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,7 @@ | ||
package main | ||
import "fmt" | ||
|
||
func main(){ | ||
v := 40 | ||
fmt.Printf("V has value %v and type %T\n",v,v) | ||
} |
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,14 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
var a, b, c bool | ||
|
||
var k,x int = 1,2 | ||
|
||
func main(){ | ||
|
||
a := 4 | ||
fmt.Println(a) | ||
|
||
} |