Skip to content

Instantly share code, notes, and snippets.

Eric Normand ericnormand

Block or report user

Report or block ericnormand

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View 00 Maximum

Largest integer from concatenation

If I have a list of integers, I can concatenate their base-10 strings to get one large integer. However, if I reorder them, then concatenate them, I could get a larger integer. The task here is to find the largest integer you can create by concatenating a given set of integers.

Here are some test cases:

(maxcat [1 2 3 4 5 6 7 8 9]) ;=> 987654321
(maxcat [12 34 56 199])      ;=> 563419912
View 00 Game of

Conway's Game of Life

Conway's Game of Life is a famous cellular automaton. The rules are simple:

Cells are arranged in a square grid. A cell is either alive (black) or dead (white). Cells have eight neighbors that surround it. A dead cell comes to life if it has exactly three live neighbors. A live cell dies if it has four or more neighbors. A live cell dies if it has one or zero neighbors.

ericnormand / 00 Langton's
Last active May 8, 2019
324 - Newsletter - Puzzle solutions
View 00 Langton's

Langton's ant (from Rosetta Code)

Langton's ant is a cellular automaton that models an ant sitting on a plane of cells, all of which are white initially, the ant facing in one of four directions.

Each cell can either be black or white.

The ant moves according to the color of the cell it is currently sitting in, with the following rules:

  1. If the cell is black, it changes to white and the ant turns left; If the cell is white, it changes to black and the ant turns right;
View 00 Consolidate

range consolidation (from Rosetta Code)

We can represent a range of numbers as a tuple, like this [1 4]. That means all real numbers between 1 and 4, including 1 and 4. The task is to write a function that takes a collection of ranges and consolidates them so that there are no overlapping ranges.

For example, [1 4] and [3 5] overlap, so they would be consolidated to [1 5]. [10.2 15] does not overlap, so it doesn't change.

(consolidate [[1 4] [3 5] [10.2 15]]) ;=> [[1 5] [10.2 15]]
View 00 Coin

coin sums

(This one is from Project Euler).

In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation:

1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).

It is possible to make £2 in the following way:

View 00 Binary

binary divisible by 3

Write a function that takes a string of binary numbers, separated by commas. It will look like this:


Take that string, parse out the numbers, and return a string, in the same format, that only includes numbers divisible by 3.

ericnormand / 00
Last active Apr 7, 2019
320 - Newsletter - Puzzle - Remove nth element
View 00

remove the nth element from a list

Clojure's two main sequences, lists and vectors, do not easily let you remove an item from the collection when that item is in the middle of the sequence. Sometimes we need to do that. Write a function remove-at that removes the element at position n from a sequence.

(remove-at 3 [1 2 3 4 5 6])
; => (1 2 3 5 6)

Make this robust. You'll have to make some hard design decisions like how to handle the empty sequence, how to handle out-of-bounds n, and more.

View 00

list of digits

Write a function that takes a number and returns a sequence of digits. Here's an example:

(digits 3452)
;=> [3 4 5 2]

For extra credit, let digit take another parameter, which is the base of the number in which to represent digits. The default will be 10, but it should work for any number >= 2.

ericnormand / 00
Last active Mar 24, 2019
318 - Newsletter - Puzzle - Combinations
View 00

generate combinations

If I have 4 flowers to choose from (#{:rose :lily :daisy :tulip}), I can generate 4 different combinations of 3 flowers.

(#{:rose :lily :daisy}, #{:rose :lily :tulip}, #{:rose :daisy :tulip}, #{:lily 
:daisy :tulip})

Write a function combinations that takes a collection of values and a number of items to choose and generates all combinations of that size.

View 00 Run-length encoding

Run-length encode a sequence

Run-length encoding is a way to represent a sequence in a more compact form. Instead of saying :p :p :p, you say “3 :ps”. Write a function that takes a sequence and returns that sequence with run-length encoding.

For example:

(rle [:a :a :a :b :c :d :d :d :d])
;=> ([3 :a] [1 :b] [1 :c] [4 :d])
You can’t perform that action at this time.