/mchain

functional language & interpreter

Primary LanguagePythonMIT LicenseMIT

mchain

mchain is a functional language that only uses method chaining and assigning.

Docs

Documentation

Usage

python main.py [path_to_file]

Example

Solution for ABC348-B
examples/abc348-b.mcn

N = nextIn~parseInt();
XY = newList<N, newList<2, 0>> ~map(FUNC<i, i ~map(FUNC<j, nextIn ~parseInt()>)>);
_ = newList<N,0> 
    ~iota(0, 1)
    ~map(FUNC<
        i,
        newList<N,0> 
            ~iota(N ~sub(1), -1) 
            ~reduce(
                newList<2,0>, // [idx, maValue]
                FUNC<
                    a, b, 
                    a ~ifElse(
                        a ~at(1) ~gt(XY ~at(i) ~at(0) ~sub(XY ~at(b) ~at(0)) ~pow(2) ~add(XY~at(i)~at(1) ~ sub(XY ~at(b) ~at(1)) ~pow(2))),
                        FUNC<tmp, tmp>,
                        FUNC<tmp, newList<2,b> ~set(1,XY ~at(i) ~at(0) ~sub(XY ~at(b) ~at(0)) ~pow(2) ~add(XY~at(i)~at(1) ~ sub(XY ~at(b) ~at(1)) ~pow(2)))>,
                    )
                >
            ) ~at(0) ~add(1)
            ~println()
    >);

View more on examples