@JoKing brain isn't working too well rn, but could you possibly overshoot by 1 iteration -> undo the computation of last iteration? whether you can undo will depend on the language ofc
a lot. but i didn't ping you for the ones you missed
oh huh. i was thinking of starting pattern matching with different numbers of arguments. could you give an example of *foo args? (since that would probably trip overloads up a bit)
@ConorO'Brien wait, nvm. the rest of the questions are on c9 probably
like... what should empty curries/lambdas look like (how many spaces inside)
Hmm. I wonder what priority overloads should have. Literal match > condition (f[x] if condition) > isinstance? Maybe isinstance > condition? And what if there are multiple args
Oh also I won't be on C9 for like the next 3-4 hours but I've stashed the changes do you can do whatever you want on c9
Re: multiple args: match as many conditions of any kind as possible? Or as many literals as possible, then as many conditions as possible, then as many subclass as possible?
@MilkyWay90 requiring a program to specify a limit on how much memory it can use means the language isn't TC; being TC means you can solve any solvable problem, even the ones where you don't know in advance how much memory you'll need
@JoKing BF where [] loops always run at least once is Turing-complete but not I/O-complete
I had a look at that language a while ago (after implementing it by mistake while trying to learn Python)
there are several possible proofs, one of the simplest is to give a compiler from a TC language to do-while BF code, e.g. this one produces code in which loops always run at least one iteration
I wrote a mandelbrot set renderer in 245 characters of C code!
int main(){double x,y,u,v,u2,v2;int i,j,k;for(j=0;j<33;j ++){y=1.0-j*(2.0/33);for(i=0;i<80;i++){u=0.0;v=0.0;u2=u* u;v2=v*v;x=-2.0+i*0.0375;for(k=1;k<2e3&&(u2+v2<4.0);k++) {v=2*u*v+y;u=u2-v2+x;u2=u*u;v2=v*v;};putchar(k>=27?32:97 +k/3);}putchar(10);}}/*Fin's C Mandelbrot Set Renderer*/
"This question has more than 500 answers already. Did you read through the existing answers first to make sure your answer will be contributing something new?" Admittedly no, but I did use the site's search feature to verify that my new answer wasn't a duplicate.
that message seems somewhat patronising when the question already has that many answers
@Fatalize Not entirely. The array model is slightly different (actually, dzaima/APL mostly adopts it), and it has some generalisations that no APL has adopted yet, while ridding itself of some (admittedly convenient) syntaxes that are anomalous.
@ASCII-only You can also quite easily give ASCII names to most non-ASCII symbols.
Another problem from our internal golfing...this one around the holidays last year.
PROBLEM
Andy, Barb, Carl, Didi, Earl, and Fran are buying gifts for each other. Draw names for a gift exchange.
Each person buys one gift and receives one gift.
Nobody buys their own gift.
Running the solution...
I suggest you "The Flat Belly Fix".It is really great! This is the only 21-day rapid weight loss system that allows you to easily lose an average of 1 lb a day for 21 days without feeling hungry or deprived. The unique and brand new techniques used in this System are proven SAFE. And they do not...
@JoKing hm, regarding BF where [ is only a marker and not a command, maybe you can somehow store the state of the previous iteration in some other place in the tape (the way to do that would differ depending on the code in the loop, of course), and, at the end, replace the current state with the previous state and then clear the area where the previous state used to reside on (don't count the last iteration, which is subtracting one iteration, converting the do-while loop to a while loop)
I haven't been on PP&CG for a while, so I thought I would post something!
Your task is to find how "smooth" a number is. Your method is to:
1: Convert a number to binary
2: Find the number of changes / switches
3: Find the length of the string (in binary)
4: Divide length by changes
So, an...
@DJMcMayhem i was fixing to ask for an algorithm, because i'm lazy, thanks for the readable solution, will do a x86-64 answer for @Adám when i get home
@moonheart08 I know the layout by heart, and I can teach it to you in an hour or so too. I personally find Dyalog's own keyboards a bit too mushy. Dyalog got me a Unicomp Model M with IBM APL layout to try it out, so that's what I use. Since then, Unicomp's APL sets was updated to be Dyalog keyboards too. Can highly recommend if you don't have people around you, as they will go deaf…
@dzaima @moonheart08 Actually, if you want to give out packaged executables (i.e. fold your code and the interpreter into a single exe), you can get a commercial license with 2% royalty, so then you pay Dyalog 2% of the income your exe earns you. If that's 0, so be it.
@moonheart08 The co-worker right behind me has hearing aids (and also uses has Model M connected to one of his PCs)…
Code you write using Dyalog's IDE is of course yours to do with what you want, and you can even compile it using the free co-dfns compiler, and distribute the generated executable.
i imagine the JIT performs better than compiled, but at the same time i dont know because APL has a much less complex type system, making some JIT tricks less effective
@Adám is it possible to use APL with, say, Rust or C, via a interface?
@moonheart08 not necessarily, what it succeeds on is that it, being APL, can specialize different algorithms for all the built-ins and their combinations on various input data live
@moonheart08 if your code is ¨-free, it should perform pretty well as the interpreting overhead is a constant based on the length of the code, and the specific characters are all very fast
@moonheart08 The Stormwind Boating simulator models realistic physics, and APL certainly provides adequate performance for a full motion simulator, even on a plain laptop.
@moonheart08 i have no idea what's there to be heavily calculated about chemistry, but if there's a big input set I'm pretty sure you can make APL perform well
@moonheart08 I don't think Stormwind uses multiple threads to compute, but Dyalog does provide facilities to use multiple processes on the fly, and if the interpreter judges it as likely to save time, it will use multiple processors in parallel. Problem is that memory speed lags behind processor speed these days, so it most often doesn't pay of to do multi-processor array computations.
Quinanagram
You're goal for this challenge is to write a quine which outputs all characters used in your programs source-code, but in a different order. The output must contain each and every character that your original program had, however the main twist is that you will be scored on the Leven...
@dzaima In the old days, APLers were masters of working with "segmented arrays", where a Boolean mask would indicate the cutting points of a large array.
@Adám oh god right.. doesn't make it much easier to do parallel calculation on everything though, as each subarray might need a different amount of operations
i mean maybe if the subarrays aren't that long and each needs operations done linearly one could do them step-by-step on all, but that'd probably perform worse than an ¨
CMC Given a Boolean list and an integer list, Return the cumulative sum, resetting the accumulator to 0 whenever indicated by the Boolean. E.g. [1,0,0,1,0,0,0,1,0,1,1,0,0] and [9,12,7,9,11,1,4,5,5,3,1,11,11] gives [9,21,28,9,20,21,25,5,10,3,1,12,23]
(unrelatedly, i find it weird how incredibly ¨y is dyadic reduce. i'd imagine it'd be much more useful having it execute ⍺⍺ for each sublist instead of having it force an implicit second reduce; it'd make 2-/ longer but i'd think it'd be worth it)
@dzaima That's what J does for both prefix f\B and infix A f\B, so APL's +\ is +/\ in J, and 3+/ in APL is 3+/\ in J.
@dzaima The reason for this is obvious. APL didn't originally have nested arrays, and so it would be impossible to return the partitions. You had to reduce them to make the results "fit".
@dzaima OK, they are completely equivalent now. The only difference is the old solution using a variable and shifting to get the deltas instead of ¯2-/
@Adám some time in the future, maybe. When, who knows ¯\_(ツ)_/¯
I was hoping to have working code an hour after writing this. I got very distracted :P
then again, that hour of doing that challenge was probably the most fun with APL I've had (excluding when i found APL and spent forever doing simple things like 1 2 3+4 5 6 lol)
Imagine this short function to clamp a number between 0 and 255:
c = n => n > 0 ? n < 255 ? n : 255 : 0
Is this the shortest possible version of a clamp function with JavaScript?
P.S: Not sure if it's relevant but, the 0 and 255 are not random, the idea is to clamp a number as an 8-bit unsign...
Sort according to cyclic order
Cyclic order on a set is a function f taking three distinct elements of a set, returning bool and having following properties:
f(a, b, c) = f(b, c, a)
f(a, b, c) = !f(c, b, a)
f(a, b, c) && f(a, c, d) = f(a, b, d)
Values of f when arguments are not distinct don...
Would anyone here help me implement a Binary Lambda Calculus interpreter in Python? I'm kind of stuck with the fact that all the resources I've found online for it are really math-heavy and have completely unreadable implementations in PHP or Haskell
Alteratively if anyone knows a simple, readable implementation online, I'd appreciate it.
I'm a Python, Kotlin, and C person, so the PHP, Haskell, Lisp, and Scheme of all the implementations I've read so far are impossible to understand