Unfriendly neighors
Let's say we have a sequence of integers:
[1 3 2 4 1]
There are 4 spots between numbers where we could insert a new number (represented by commas):
Unfriendly neighors
Let's say we have a sequence of integers:
[1 3 2 4 1]
There are 4 spots between numbers where we could insert a new number (represented by commas):
Custom sort order
The sort
function sorts a collection based on its "natural ordering." sort-by
allows you to sort a collection based on the natural ordering of the result of some function applied to the elements. Your task is to write a function sort-with
which takes a sequence of elements that define the sort order.
Example
; define ordering ; collection to sort
(sort-with [:breakfast :lunch :dinner] #{:lunch :breakfast :dinner}) ;=> (:breakfast :lunch :dinner)
(sort-with [2 3 4 :jack :queen :king :ace] [4 2 4 :king 2]) ;=> [2 2 4 4 :king]
Single letter swaps
Write a function that takes a sequence of strings and a target string. For each string in the sequence, determine if it is equal to the target string after exactly one letter swap. Return the sequence of letter pairs that are swapped, or nil if it doesn't exist.
Example
(letter-swaps ["bacd" "abdc" "abcde" "abcc" "abcd"] "abcd")
;=> [#{\a \b} #{\c \d} nil nil nil]
Word search
I'm fond of search that is forgiving of small mistakes. If you type a few letters from the word, even if you miss a letter, you should get the word.
Here's a simple, forgiving search function.
Write a function that takes two strings, a needle and a haystack. The function should return true if the needle is found in the haystack, with a few forgiving features:
Odd One Out
Write a function that takes a list of words (Strings). The function should return true if exactly 1 word differs in length from the others. It should return false in all other cases.
Examples
(odd-one? ["a" "b" "c"]) ;=> false
(odd-one? ["a" "b" "cc"]) ;=> true
(odd-one? ["abc" "aa" "xyz" "jj"]) ;=> false
Primes in a number
Another contrived math problem. This one I think is actually pretty hard. It's got detecting primes, string manipulation, and combinations.
Your task is to write a function that takes an integer and finds all primes that are substrings of the decimal digits of that integer.
Examples
(find-primes 2) ;=> [2]
NOTE: If you're looking for issue 461 (Primes in a number), please go here: https://gist.github.com/ericnormand/d52d1fe0e80f06e4b517d45a082765a0
Rearrange sentence
Here's a neat, yet contrived, text processing problem. The words in your sentence have been mixed up. Luckily, there's a number embedded in each word that says its position in the sentence. Write a function that puts the words in the right order and removes the position digits.
Examples
(rearrange "World2! He1llo,") ;=> "Hello, World!"
Paul Cipher
Here's an interesting cipher.
Your task is to write an encoder and decoder for this cipher
String difference
Imagine two strings, A and B. B is generated by shuffling the letters in A and adding a new random letter to it at a random position. Write a function that takes A and B and returns the new letter.
Examples
(diff "" "j") ;=> \j
(diff "a" "ab") ;=> \b
(diff "abc" "xcab") ;=> \x
Chess moves
Write a function that determines if a chess piece, on an empty board, can move from one space to another in one move.
Examples
(can-move? :pawn "A2" "A3") ;=> true
(can-move? :queen "H1" "A8") ;=> true
(can-move? :knight "A4" "A5") ;=> false ;; (that's not how knights move)