Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More idiomatic K solution #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

More idiomatic K solution #5

wants to merge 1 commit into from

Conversation

jaredkrinke
Copy link
Owner

@JohnEarnest provided some suggestions for simplifying the K solution:

You can simplify the definition:

fact:{*/1+!x}

by observing that the lambda serves only to consume a single rightmost argument, and instead write it in tacit form, which some people find prettier:

fact:*/1+!:

You can also replace the lambda containing a conditional applied to each element of a list:

{$[x>1000000;1;0]}'

With applying the comparison operator to the entire input vector, yielding a vector of booleans:

1000000<

John also clarified the meaning of the colon at the end of the fact definition for me:

a colon suffix on a verb forces its monadic interpretation, especially in the context of an adverb. Otherwise, the terminal verb in a composition- and thus the composition itself- is "ambivalent" (i.e. "both valences"); adverbs prefer the dyadic interpretation, which can lead to surprises. It isn't strictly necessary for this application but it does clarify intent to a reader.

Thanks, John!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant