Right so I am a 1000% Noob at Jelly, but it intrigues me and I want to grasp the basics. To do so I wanted to figure out the sum of every number that is a multiple of 3 or 5 under some limit
My first attempt is here Try it online! I later figured i could drop the 3 and 4. Hower, I can not for the life of me seem to input a list (R) as the second argument
@cairdcoinheringaahing No hurries =) Just driving me up the walls that I am this close but no bueno. Feel free to leave me a ping ifno one else replies
@N3buchadnezzar Ok, so what should the expected output for that be?
By my understanding, you're calculating the sum of the elements of the second argument that are divisible by either 3 or 5, so the output should be 60?
Or should the second input just be 15, and you want to convert that to a range in the code itself?
Correct me if I'm wrong @N3buchadnezzar, but is this an attempt to solve this CMC: Given a list of integers a and an integer b, calculate the sum of all integers 1 ≤ b that are divisible by at least one integer in a. Answer with MD5 hashes
Never mind. So, your current solution works by × multiplying the corresponding elements in the input array. Keeping with this approach with the input changing to an integer will either result in a complicated chaining strategy, or a lot of nilads based on ⁴.
Using the superscript nilads to refer to the arguments sort of goes against the whole point in tacitness and often restructuring is both shorter and easier
So € turns 16 into [1,2,3,4,...,15,16], then runs the previous link as a dyad on each. The left argument to the dyad is the element and the right element is the second argument (⁴) passed to the program
For example, that pairs each element with the input list
That then means that you can work with each element, determining if it should be part of the sum or not
Ok, that's no problem - ¤ is one of the more complicated quicks
Essentially, ¤ scans backwards, looking for a nilad followed by monads, dyad-nilad pairs and nilad-dyad pairs. Here, we only care about a nilad followed by a monad
Kind of. So an important think to know about Jelly is that a dyadic link (what we have here, as it has 2 command line arguments) has a left and a right argument
So, there's a quick specifically designed to make ⁸<monad>¤ into 2 bytes (as <monad><quick>), so we can turn ⁸R¤ into R<quick>. You can find it on the quicks page, but the description isn't 100% helpful. Take a look through to see if you can find anything, let me know if not :)
Not quite, because it can change the parsing of the link in some cases. Here, it doesn't matter tho
The parsing of Jelly programs is dependent on the arities of each link in the program. { turns a monad (arity 1) into a dyad (arity 2), which can affect the parsing in certain cases
We're using ç to group the commands on the first line into a single dyad, so that we can run that dyad over each element. But there's a way to group 2 links into a dyad without needing a newline
I like to use multiple lines and Ç/ç when I'm running a large link with a quick (e.g. €), then I try to turn it into a single line after getting a program that works
For example, my first version of this was this because I could group everything together on the first line, then call it
After getting a working version, I then golfed it to be a single line
Ok, so %Ȧ¥€ is exactly the same as %Ȧ¶ç€ (using ¶ instead of a newline). ¥ groups the previous 2 commands into a single command (kind of like function composition). € then runs this composed command over each integer 1,2,3,...,n (n is the left argument)
¥ groups these two into a function f(k, l) (k is an element in the range, l is the list passed as the second argument). % calculates \$k \bmod l_i\$ for each element \$l_i \in l\$, then Ȧ asserts that all of those are non-zero. This is only true if k is not divisible by any element in \$l\$
I remember you saying you have a masters in Maths (?) so I hope the LaTeX isn't too much
Yes. Now, this will change 2 characters in the code - 1 to add in a negation condition, and 1 because ¥ only groups 2 characters, so we'll need to use a different quick instead of ¥