David,
I hope you’ll allow me to offer my own solution to this problem, and maybe to expand on yours. I appreciate your approach, because I think it helps to highlight some of the perceived differences between math and engineering. Also, I think brute force can be used as a bad word, like not doing the thinking work. But computers these days are so fast that I think brute force should be our go-to tool first.
I primarily studied number theory and algebras in my undergrad days, but now I am working with statistics and applied math. As a result, sometimes I am not worried if something is right as long as its fast. But when you can be fast and right, all the better.
I would guess before you wrote any code, you might have taken a quick check on how many operations you would need to perform to check all the solutions. There are 24 ways to write the digits [1,2,3,4], so at most we have 24*24*24*24 (331,776) possible additions to perform. Even for my $500 laptop this is “child’s play.” The code snippet below runs on my computer in about 3 seconds.
So with this brute force approach we have the option to introduce counting, which is the foundation of probability and statistics.
Now to the code… I chose to write this in R. I used the libraries gtools to do the heavy lifting for permutations.
library(gtools)# Get a list of permutations of the digits 1,2,3,4.
x <- permutations(4,4)# Convert the list of digits into a real number.
y <- c(1000,100,10,1)
numbers <- apply(x, 1, function(x) x%*%y)# A matrix of combinations for 24 choose 4.
possible_additions <- permutations(24, 4, repeats.allowed = TRUE)# Perform an addition for each column of numbers.
sum_of_columns <- apply(possible_additions, 1, function(x) sum(numbers[x]))# Check if the number 9000 is present.
sum_table <- table(sum_of_columns)
sum_table[names(sum_table)==9000]
I went a step further and plotted the distribution of the sums in a histogram.

No reason for this… I guess the whole point of the post is that people come to a love of math (STEM in general) through a variety of ways. But I think at the heart of it is the idea of solving problems. Even in this example, no solution to the problem exists, but coming to that answer. Either from analysis or from a theoretical proof can be deeply satisfying!
