A World Without Strings is Chaos

I developed these programming exercises while working at 1010data. Each summer we’d put a batch of half a dozen or so interns through a week-long intensive K training program, including this set of puzzles, and then set them loose on the real codebase.

These problems vary in difficulty from trivial to moderately difficult (in non-escalating order), and are suitable for beginners or anyone wishing to brush a little rust off. A solution is provided for each problem in k3- click and hold on the gray area beneath each IO sample to reveal it. Most problems have at least one elegant solution, but many have multiple valid approaches- see how many ways you can satisfy the requirements!

0 - Multiplicity

Characters are expensive, and the accountants tell me we can’t hand them out willy-nilly anymore. Given a string x and a character y , how many times does y occur in x ?

f["fhqwhgads";"h"] 2 f["mississippi";"s"] 4 f["life";"."] 0

+/=

1 - Trapeze Part

Sometimes I try reading sentences right-to-left to make my life more exciting. Results have been mixed. Given a string x , is it identical when read forwards and backwards?

f "racecar" 1 f "wasitaratisaw" 1 f "palindrome" 0

{x~|x}

2 - Duplicity

One is the loneliest number. Given a string x , produce a list of characters which appear more than once in x .

f "applause" "ap" f "foo" ,"o" f "baz" ""