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 } | |
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
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
-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
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
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
rotate xs n | n >= 0 = drop n xs ++ take n xs | |
| otherwise = drop (length xs + n) xs ++ take (length xs + n) 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
rotate xs n | n >= 0 = zipWith (\_ x -> x) xs $ drop n $ cycle xs | |
| otherwise = take len $ drop dropLen $ (cycle xs) | |
where | |
len = length xs | |
dropLen = (len + (n `mod` (-len))) |
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
import Control.Monad (replicateM) | |
parseTokens:: String -> [String] | |
parseTokens tokenStr = parseTokens' [] "" False tokenStr | |
where | |
parseTokens' acc word isGroup "" = acc | |
parseTokens' acc word isGroup (x:xs) | |
| not isGroup && x == '(' = parseTokens' acc "" True xs | |
| not isGroup && x /= '(' = parseTokens' (acc++[[x]]) "" False 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
package main | |
import ( | |
"bytes" | |
"fmt" | |
"strings" | |
) | |
func main() { | |
// Read first line |