lis05's blog

By lis05, 3 hours ago, In English

So for the last couple of months I've been busy making a simple (and unfortunately slow) interpreted programming language called Cotton. Today, I was able to compress its entire source code into a single file and solve an atcoder problem using a small program in Cotton written in a huge interpreter in C++.

Why you need this information? You don't. I just wanted to share my excitement with someone.

The program in Cotton:

arr = make(Array)
    .resize(read(Integer))
    .apply(function(x){x=read(Integer);});

target = arr.copy().sort(function(a,b){a>b;})[1];

// don't have a function that would return element's position yet
for i = 0; i < arr.size(); i++; {
    if arr[i] == target; {
        println(i + 1);
        return;
    }
}

If you want to look at the beautiful obfuscated code of the interpreter, it's available here

  • Vote: I like it
  • +42
  • Vote: I do not like it