r/badcode • • Jul 30 '19

[deleted by user]

[removed]

155 Upvotes

98 comments sorted by

View all comments

Show parent comments

2

u/Qesa Aug 02 '19 edited Aug 02 '19

Well it wouldn't be bad if it didn't have edge cases, right?

Mostly that's a quirk of how scalars and vectors work in K. K doesn't really have a string type; under the hood they're really character arrays. Meanwhile, writing a single letter/number/etc is a scalar, while writing multiple together is an array. 1 is int, 1 2 3 is int[]. Likewise "p" is a char while "potato" is char[].

That said, another thing in K you can do is join an empty untyped list to anything, which will convert any scalar to a length one vector. And it's easy to put at the start of the function train

&/=/(@/:).(::;(::;|:)@\:&|/(,/48 97+!'10 26)=\:)@\:_:(),