Skip to content

Instantly share code, notes, and snippets.

View iporsut's full-sized avatar
🏠
Working from home

Weerasak Chongnguluam iporsut

🏠
Working from home
View GitHub Profile
@iporsut
iporsut / main.go
Created May 11, 2015 22:40
scan line
package main
import (
"bufio"
"flag"
"fmt"
"os"
"strings"
)
@iporsut
iporsut / replace.hs
Created May 11, 2015 02:18
replace character in string
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
@iporsut
iporsut / mylist.erl
Created May 10, 2015 13:20
mylist flatten
-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]).
type IO interface {
Read() string
Write(string)
}
@iporsut
iporsut / gist:2a6fad40c682f11d4e85
Created May 4, 2015 09:53
Account use Deposit Method
func main() {
acc := Account{Name: "Weerasak", Balance : 1000.00 }
acc.Deposit(500.00)
fmt.Println(acc)
}
@iporsut
iporsut / gist:91039c160abd863f5be6
Created May 4, 2015 09:52
Account Deposit Method
func (acc *Account) Deposit(amount float64) {
acc.Balance += amount
}
@iporsut
iporsut / gist:c572df037a573adf6700
Created May 4, 2015 09:51
Account use String Method
func main() {
acc := Account{Name: "Weerasak", Balance : 1000.00 }
fmt.Println(acc.String())
pacc := &acc
fmt.Println(pacc.String())
}
@iporsut
iporsut / gist:774c85c3858a0c8403bd
Created May 4, 2015 09:49
Account String Method
func (acc Account) String() string {
return fmt.Sprintf("Account %s have balance %0.2f", acc.Name, acc.Balance)
}
type Account struct {
Name string
Balance float64
}
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)
}