-
Notifications
You must be signed in to change notification settings - Fork 13
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
hamed
committed
Jun 30, 2022
1 parent
4430901
commit 5544586
Showing
3 changed files
with
151 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,18 @@ | ||
package main | ||
|
||
func main() { | ||
|
||
for i := 1; i <= 100; i++ { | ||
if i%2 != 0 { | ||
continue | ||
} | ||
println(i) | ||
} | ||
|
||
for i := 1; i <= 100; i++ { | ||
if i == 50 { | ||
break | ||
} | ||
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,40 @@ | ||
package main | ||
|
||
import "math/rand" | ||
|
||
type CreditCard struct { | ||
CardNumber string | ||
ExpireDate string | ||
Cvv2 string | ||
BankName string | ||
} | ||
|
||
func main() { | ||
|
||
cards := []CreditCard{ | ||
{CardNumber: "6037991725253535", ExpireDate: "01/01", Cvv2: "123", BankName: "Melli"}, | ||
{CardNumber: "5892101245457878", ExpireDate: "03/03", Cvv2: "245", BankName: "Sepah"}, | ||
{CardNumber: "6104981247653214", ExpireDate: "02/04", Cvv2: "741", BankName: "Mellat"}, | ||
{CardNumber: "6219861047653214", ExpireDate: "01/02", Cvv2: "1023", BankName: "Saman"}, | ||
} | ||
|
||
for _, card := range cards { | ||
|
||
if card.ExpireDate < "01/03" { | ||
println("Your card", card.CardNumber, " is expired") | ||
continue | ||
} | ||
var remainAmount = getBankAccountRemainAmount(card.CardNumber, card.ExpireDate) | ||
println("Your card", card.CardNumber, " is valid, remain amount is ", remainAmount) | ||
} | ||
|
||
} | ||
|
||
func getBankAccountRemainAmount(cardNumber string, expireDate string) int { | ||
min := 1000000 | ||
max := 30000000 | ||
if expireDate < "01/03" { | ||
return 0 | ||
} | ||
return (rand.Intn(max-min) + min) | ||
} |
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,93 @@ | ||
package main | ||
|
||
func main() { | ||
i := 0 | ||
//lst := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} | ||
lst1 := []int{12, 15, 14, 13, 16, 17, 18, 19, 20, 21} | ||
for { | ||
println("Hello, world!") | ||
break | ||
} | ||
|
||
for i < 10 { | ||
println("Hello, world! ", i) | ||
i++ | ||
} | ||
|
||
for j := 0; j < 10; j++ { | ||
println("Hello, world! ", j) | ||
} | ||
|
||
for index, item := range lst1 { | ||
println("Hello, world! ", index, item) | ||
} | ||
} | ||
|
||
func twoSum(nums []int, target int) []int { | ||
|
||
for i, item := range nums { | ||
if item >= target { | ||
continue | ||
} | ||
compliment := target - item | ||
for j, itemJ := range nums { | ||
if itemJ == compliment && i != j { | ||
return []int{i, j} | ||
} | ||
} | ||
} | ||
return []int{0, 0} | ||
|
||
} | ||
|
||
// 11 * 11 = 121 | ||
// 10 * 11 / 2 = 55 | ||
|
||
// 110 * 110 = 12100 | ||
// 110 * 109 / 2 = 5995 | ||
|
||
func twoSum1(nums []int, target int) []int { | ||
|
||
// 7,11,15,45,22,10,2,8,10,12,14 | ||
// 3,00,00,00,00,00,8,2,00,00,00 | ||
|
||
for i, item := range nums { | ||
if item >= target { | ||
continue | ||
} | ||
compliment := target - item | ||
for j := i; j < len(nums); j++ { | ||
if nums[j] == compliment && i != j { | ||
return []int{i, j} | ||
} | ||
} | ||
} | ||
return []int{0, 0} | ||
|
||
} | ||
|
||
// [7,11,15,45,22,10,2,8,10,12,14] | ||
// 10 | ||
// [3,2,41,7,6,9,8,110,14,20,25,23] | ||
// 13 | ||
// [3,3] | ||
// 6 | ||
|
||
func twoSum2(nums []int, target int) []int { | ||
|
||
// 7,11,15,45,22,10,2,8,10,12,14 // 121 | ||
// 3,00,00,00,00,00,8,2,00,00,00 // 55 | ||
keys := map[int]int{} | ||
for i, item := range nums { | ||
|
||
complement := target - item | ||
if _, exist := keys[complement]; exist { | ||
return []int{keys[complement], i} | ||
} | ||
|
||
keys[item] = i | ||
|
||
} | ||
return []int{0, 0} | ||
|
||
} |