This file contains hidden or 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
| package main | |
| import ( | |
| "bufio" | |
| "flag" | |
| "fmt" | |
| "os" | |
| "strings" | |
| ) |
This file contains hidden or 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
| replace xs a b = replace' [] xs | |
| where | |
| replace' acc [] = acc | |
| replace' acc (x:xs) | x == a = replace' (acc ++ [b]) xs | |
| | otherwise = replace' (acc ++ [x]) xs |
This file contains hidden or 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
| -module(mylist). | |
| -export([flatten/1]). | |
| flatten(L) -> flatten(L, []). | |
| flatten([], Acc) -> Acc; | |
| flatten([H|T], Acc) when is_list(H) -> flatten(T, Acc ++ flatten(H)); | |
| flatten([H|T], Acc) -> flatten(T, Acc ++ [H]). |
This file contains hidden or 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
| type IO interface { | |
| Read() string | |
| Write(string) | |
| } |
This file contains hidden or 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
| func main() { | |
| acc := Account{Name: "Weerasak", Balance : 1000.00 } | |
| acc.Deposit(500.00) | |
| fmt.Println(acc) | |
| } | |
This file contains hidden or 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
| func (acc *Account) Deposit(amount float64) { | |
| acc.Balance += amount | |
| } |
This file contains hidden or 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
| func main() { | |
| acc := Account{Name: "Weerasak", Balance : 1000.00 } | |
| fmt.Println(acc.String()) | |
| pacc := &acc | |
| fmt.Println(pacc.String()) | |
| } |
This file contains hidden or 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
| func (acc Account) String() string { | |
| return fmt.Sprintf("Account %s have balance %0.2f", acc.Name, acc.Balance) | |
| } |
This file contains hidden or 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
| type Account struct { | |
| Name string | |
| Balance float64 | |
| } |
This file contains hidden or 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
| package main | |
| import "fmt" | |
| func space(ch rune, end rune) (side int, in int) { | |
| if ch == 'A' { | |
| in = 0 | |
| } else { | |
| in = int((ch-'A')*2 - 1) | |
| } |