« first day (131 days earlier)      last day (1111 days later) » 

07:04
# @DrMcMoylex This should work
primes = [] # list of the 4-digit prime numbers
numbers = ["()" * i for i in range(10000)]
for i in range(2, 10000):
    for j in range(1, 8):
        try(i, "numbers[i + j]\[numbers[j]]")
    try(i + 1, "%s()" % numbers[i])
    try(i * 2, "(%s){}" % numbers[i])
    try(i * 3, "((%s)){}{}" % numbers[i])
    try(i * 3 + 2, "((%s)()){}{}" % numbers[i])
    for l in range(1, int(i**.5) + 1):
        if not i % l:
            for (j = 0; (k = ((i + j + j) * i / l + i) / 2) < 10000; j++):
Whoops didn't port inner loop
            j = 0
            k = ((i + j + j) * i / l + i) / 2
            while k < 10000:
                try(k, "(%s){%s({}[%s])}{}" % (numbers[i], numbers[j], numbers[l]))
                j += 1
                k = ((i + j + j) * i / l + i) / 2
 
3 hours later…
09:48
Hmm, can't improve on Neil's (also fixed all the bugs):
#!/usr/bin/python3
N=10000
a=[1]*N
for i in range(2,3936):
    if a[i]:
        for j in range(i*i,N,i):a[j]=0
primes = list(filter(lambda x: x > 1000, [i for i in range(len(a))if a[i]==1]))
numbers = ["()" * i for i in range(N)]

def tryi(n, s):
    if n < N and len(numbers[n]) > len(s):
        numbers[n] = s

for i in range(2, N):
    for j in range(1, 8):
        if i + j >= N:
            break
        tryi(i, "%s[%s]" % (numbers[i + j], numbers[j]))
    tryi(i + 1, "%s()" % numbers[i])
    tryi(i * 2, "(%s){}" % numbers[i])
Feel free to delete the other two codeblocks
@DrMcMoylex BTW IMO it's just better pregenerate and have like a static website with 1. 1000 files with 1000 numbers each or 2. have a really nested folder structure, maybe two digits (00-99) per level, or 3. (probably the best idea) just have it run once and keep it in memory
 
2 hours later…
11:58
gist: a4b4ba61b9fdeaa98d40151d7e777a19, 2016-11-03 11:58:08Z
#!/usr/bin/python3
import http.server
from time import sleep

N=25001
numbers = ["()" * i for i in range(N)]

def tryi(n, s):
    if n < N and len(numbers[n]) > len(s):
        numbers[n] = s

for i in range(2, N):
    for j in range(1, 8):
        if i + j >= N:
            break
        tryi(i, "%s[%s]" % (numbers[i + j], numbers[j]))
    tryi(i + 1, "%s()" % numbers[i])
    tryi(i * 2, "(%s){}" % numbers[i])
    tryi(i * 3, "((%s)){}{}" % numbers[i])
    tryi(i * 3 + 2, "((%s)()){}{}" % numbers[i])
    for l in range(1, int(i**.5) + 1):
        if not i % l:
            j = 0
            k = ((i + j + j) * i / l + i) / 2
            if k % 1:
                continue
            k = int(k)
            while k < N:
                tryi(k, "(%s){%s({}[%s])}{}" % (numbers[i], numbers[j], numbers[l]))
                j += 1
                k = ((i + j + j) * i / l + i) / 2
                if k % 1:
                    continue
                k = int(k)

length = 0

# for prime in primes:
    # print("(%s)" % numbers[prime])
    # length += 2 + len(numbers[prime])

# print("Total length primes 1 to %s:" % N, length)
print("Total length 1 to %s:" % N, sum(len(n) for n in numbers))

def tryint(s):
    try:
        return int(s)
    except:
        return None

def reverse(n):
    s = "(%s)"
    while n >= N:
        if not (n - 2) % 3:
            s = s % "((%s)()){}{}"
            n = (n - 2) // 3
        elif not n % 3:
            s = s % "((%s)){}{}"
            n //= 3
        elif not n % 2:
            s = s % "(%s){}"
            n //= 2
        else:
            s = s % "%s()"
            n -= 1
    return s % numbers[n]

class Handler(http.server.BaseHTTPRequestHandler):
    def do_HEAD(s):
        s.send_response(200)
        s.send_header("Content-type", "text/html")
        s.end_headers()

    def do_GET(s):
        s.send_response(200)
        s.send_header("Content-type", "text/html")
        s.end_headers()
        s.wfile.write(bytes(
            "<pre>%s</pre>" % reverse(int(s.path[1:]))
            if tryint(s.path[1:]) is not None else
            "Invalid path",
            "ascii"
        ))

httpd = http.server.HTTPServer(("", 8000), Handler)
httpd.serve_forever()
Enter the number after the domain name (and port) (marsultor.ddns.net:8000/numbertogolf), for numbers above 25k it does it the non-golfy way since it already takes ~481MB for the shortest forms from 1-25k
 
1 hour later…
13:21
:D some bugs fixed, now works pretty well for e.g. 1048576
works well for way larger numbers too, 1e100 should work fine but it would take too long on TIO to test that out I think
BTW it's slightly better than Neil's implementation I think, posted comment on his answer
13:44
@ASCII-only Wow that's incredible. Why does everyone always beat me to implementing these kinds of things?
Anyway, for whatever reason, it's not responding for me
I was thinking of porting it to JS so that you don't need to worry about having a server
 
6 hours later…
20:08
@MegaTom I just implemented a Minsky machine without the stack swap!
20:29
@DrMcMoylex IDK, I don't think everyone has 500 MB of spare RAM
@DrMcMoylex Sorry when I lock my laptop half the time it disconnects from the internet after a while, should work now
@DrMcMoylex BTW JS has no big integer support, and any libraries that do are really slow
20:43
I mean, sure, you don't need 500MB since you can reduce N, but JS bug number arithmetic is a PITA
20:57
@WheatWizard I knew it was possible!
You also use no [] nilad.
Brain-Flak is now proven Turing complete without [], <...> and <>
Can you exclude all three simultaneously?
yes
<...> can always be replaced with [(...)]{}
That works.
I do not think it possible to reduce it any more.
I don't think so either
but hey I didn't think it was possible without the <>
21:04
Yes. You normally need two stacks. But unbounded ints can do cool stuff.
@DrMcMoylex Working on JS port, will be able to push to GH when I have internet again in like 7 hours
21:40
@WheatWizard I was looking at your code but don't quite get the language you are translating from. Could you explain it and write an example program in it?
@MegaTom I wrote it based on this reference
The three operations are:
I takes a register and a location in the program.
Increments the register and jumps to the location
D takes a register and two locations in the program
@WheatWizard is 0 a valid register?
It decrements the register and jumps to the first location if that register is zero
@MegaTom yes
the second location otherwise
H halts the program
Thank you. I got the purpose of the two D registers mixed up.

« first day (131 days earlier)      last day (1111 days later) »