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 / Replicate.java
Created August 18, 2016 15:33
Java 8 Replicate String
import java.util.stream.LongStream;
public class Replicate {
public static void replicate(String s, long max) {
LongStream.iterate(0, n -> n + 1).limit(max).forEach(n -> System.out.print("A"));
System.out.println();
}
public static void main(String []args) {
int n = 11;
@iporsut
iporsut / statuses_no_recursion.go
Created August 18, 2016 09:07
statuses no recursion
package main
import (
"bufio"
"fmt"
"io"
"os"
"strconv"
"strings"
)
@iporsut
iporsut / group_numbers.hs
Last active August 14, 2016 04:41
Group Numbers
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.Tree as Tree
import qualified Data.Graph as Graph
points :: [[Int]] -> Int -> Int -> [((Int,Int), Int)]
points area width height = zip keys (concat area)
where
keys = [(r,c) | r <- [0..(height-1)], c <- [0..(width-1)]]
@iporsut
iporsut / pkgvars.go
Created November 29, 2015 15:49
List variable decralation in package
package main
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
"os"
"strings"
)
@iporsut
iporsut / alienlanguage.go
Created May 16, 2015 12:02
Alien Language Go
package main
import (
"bytes"
"fmt"
"strings"
)
func main() {
// Read first line
@iporsut
iporsut / AlienLanguage.hs
Created May 16, 2015 11:54
Alien Language Haskell
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
@iporsut
iporsut / rotate.hs
Last active August 29, 2015 14:21
rotate cycle
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)))
rotate xs n | n >= 0 = drop n xs ++ take n xs
| otherwise = drop (length xs + n) xs ++ take (length xs + n) xs
@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