4 ms·
StupidStackLanguage is by far my favorite: https://esolangs.org/wiki/StupidStackLanguage https://esolangs.org/wiki/StupidStackLanguage
by optimalsolver 10mo ago
StupidStackLanguage is by far my favorite:
https://esolangs.org/wiki/StupidStackLanguage https://esolangs.org/wiki/StupidStackLanguage
- Izkata 10mo agoPiet is mine - the programs are 2D images: https://esolangs.org/wiki/Piet https://esolangs.org/wiki/Piet Primarily because of the note on the "calculating pi" example program: > Richard Mitton supplies this amazing program which calculates an approximation of pi... literally by dividing a circular area by the radius twice. > Naturally, a more accurate value can be obtained by using a bigger program. https://www.dangermouse.net/esoteric/piet/samples.html https://www.dangermouse.net/esoteric/piet/samples.html
- somat 10mo agoOne of my favorite calculations of pi is to pick random coordinates in a unit square and count how many of them are in a circle. it's so stupid and so clever at the same time. This was recreated from memory. I think it is close but I may have a bounding bug. import random def pi(count): inside = 0 for i in range(count): test_x = random.random() test_y = random.random() if test_x ** 2 + test_y ** 2 < 1: inside += 1 return inside / count * 4 #above is a quarter circle print(pi(2 ** 30) )
- oneeyedpigeon 10mo agoI'm not sure about a bounding bug, but there's definitely an indent error on the return line (good old Python!)
- hanemile 10mo agoWith the metatopic of this thread being obscure languages, I had some fun squeezing this into some list comprehensions (maybe someone's got an idea of how to keep track of the state within the list): ``` $ cat << EOF > pi.py state = [0, 0, 2*8, 2*12]; _ = [print(f'\rRun {state.__setitem__(0, state[0] + 1) or state[0]}/{state[3]} | Last \u03c0: {current_pi:.6f} | *Average \u03c0: {(state.__setitem__(1, state[1] + current_pi) or state[1]) / state[0]:.6f}*', end='', flush=True) for current_pi in [(4 * sum([1 for _ in range(state[2]) if __import__("random").random()*2 + __import__("random").random()*2 < 1]) / state[2]) for _ in range(state[3])]]; print() EOF $ time python3 pi.py Run 4096/4096 | Last π: 3.140625 | *Average π: 3.143051* python3 pi.py 0.41s user 0.01s system 99% cpu 0.429 total ``` Play around with the `2*8` and `2*10` values in the state, they control the amount of rounds and the range in which the random values get generated respectively.
- __del__ 10mo agohttps://en.wikipedia.org/wiki/Monte_Carlo_method https://en.wikipedia.org/wiki/Monte_Carlo_method