Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
mekkanare
Sep 12, 2008
We have detected you are using ad blocking software.

Please add us to your whitelist to view this content.
I've been trying to go through Project Euler using K as it seemed like a good way to practice this language.
However, I'm on problem 2 and have already run into a wall.

I'm trying to separate the evens so that I can add them up, as the problem states, but I'm not quite sure how to go about the conditionals for K despite reading the reference manual.
Here's what I've got so far:
code:
fib:{1,|/+x(|+\)\1 1}
~(fib 5)!/:2           / returns 0 0 1 0 0 1 0 i.e. the evens
Any nudges would be nice. As it stands though, besides this hiccup I'm rather enjoying this language.

Adbot
ADBOT LOVES YOU

mekkanare
Sep 12, 2008
We have detected you are using ad blocking software.

Please add us to your whitelist to view this content.

Internet Janitor posted:

I think the operator you're looking for is &- "where".

code:
  &1 0 0 1 0
0 3
Given a boolean list, it gives you a list of the indices of the 1s. Let me know if that's enough or if you'd like any additional hints.

In unrelated news, I published a paper about iKe in Vector.

Ah I had forgotten about where, but I read through your documentation again and saw the overload for # was what I was going for.
Unfortunately I'm testing this using kona, so the version of K is a bit older. As a result this is what I have now:
code:
fib:{1,|/+x(|+\)\1 1}
(fib 5)@&{0=x!2}(fib 5)   / returns 2 8
Now my question is, how would I go about transforming this so it doesn't involve building the list twice?
Because while the above works, it feels very ugly to do.

Also, one of the first things I did when looking at this language was go through your sample codes and tried to figure out how they worked.
Although I wasn't sure how draw looped until I read the paper you wrote, so thanks for that!

mekkanare
Sep 12, 2008
We have detected you are using ad blocking software.

Please add us to your whitelist to view this content.
At your suggestion, I've got another question. Today I tried to define this function:
code:
{x%/:1+/:!_x^.5}
However I get a "reserved error" in Kona.
When I put it in oK, it will take the assignment, but calling the function will give "n is undefined".

Running the above with ints in the cli works just fine, so I think it's something to do with how variable
definitions are handled when declaring a function? This error wasn't one I could find in the reference
book, nor on the google groups suggested on the kona github.

mekkanare fucked around with this message at 17:55 on Jan 24, 2016

  • Locked thread