I solved Project Euler problems 1–100 entirely in Excel, using only one formula per problem, no VBA.
Our take
Project Euler is a programming challenge site, similar to LeetCode or HackerRank, but the problems are generally more pure math or number theory rather than typical computer science algorithms. Project Euler is less about improving programming skills than about solving the problems, you only submit the answer to the problem, not the code used to get the answer.
I originally started Project Euler about a year ago to get better at Python. After two dozen or so problems, I kept thinking "I can't get the Python to work right, but I know exactly how I'd do this in Excel". Eventually I decided to see how far I could get using only Excel.
At first Excel more as intended, with giant columns of numbers and operations occurring in every cell, but the file quickly ballooned in size and was incredibly messy. So I then started trying to keep the solutions contained in one formula in one cell. This was a terrible idea and I don't recommend it, Excel can only multi thread calculations across multiple cells, not within a single cell. Often the only way I could cancel a calculation was to force close and reopen the file.
Each solution is entirely self-contained within a single cell (with the exception of those that require a data input). Project Euler states that every problem is able to be solved in less than one minute, I only had three problems that take longer than that (60, 72, and 88; each take 5-10 minutes), and most are essentially instant.
Overall it was a really fun challenge. I definitely improved as I went along and I would probably approach a lot of the early problems in a different way after finishing.
File
You can download the final spreadsheet with all formulas here.
Stats
- The longest formula comes in at 2,647 characters and features 82 functions and 61 lines, used in problem 75.
- The shortest was 25 characters, using 2 functions, for problem 10.
REDUCEis used in 59 problems,LETandLAMBDAare used in 79,HSTACK/VSTACKis used in 45, however the most used function is probablySEQUENCE, used in a whopping 87 problems
Biggest Headaches
- Big numbers: Excel can't store more than 15 digits, and there are several problems with 50 or 100 digit numbers, or calculations like 99^99. I had to build custom digit-wise addition, multiplication, and exponentiation functions that store numbers as text to get around it.
- Recursion: Recursive
LAMBDAs have a limit of ~6400 recursions, and that number goes down as you add variables. Fortunately, this only applies to each pureLAMBDAcall, not to the built-in functions likeREDUCE. Several problems are very easy with rudimentary recursion but quickly go over the recursion limit, which made it very challenging. - Iteratively updating an array: There is no good way to do this, it requires rebuilding the array every single time. Essentially eliminates any dynamic programming approaches and makes for loops very slow
Interesting things I learned
- Excel is so bad at updating arrays that a lot of programming tips are just wrong when applied to Excel. For example, take the Sieve of Eratosthenes (explained below). I built a version of this in my file (sieve), and it works decently well for
n <= 10,000, but slows down a lot after that and is basically unusable forn > 50,000. Conversely, my naive prime generator function (primeGen) calculates and counts the divisors for every odd number from 3 toSQRT(n), and it is exponentially faster than the sieve and works forn <= 500,000in a reasonable time (possibly more, I didn't check higher n).
The Sieve of Eratosthenes efficiently finds all primes up to n by repeatedly marking multiples of each prime as non-prime, starting from 2. This avoids redundant checks and quickly filters out all composite numbers.
- The best way to do an
ORoperation on each element of 1D array is withMMULT. This vectorizes it and is much faster thanMAPorXMATCH. REDUCEis easily the most powerful formula currently available in Excel and I used it for a vast majority of problems. It is the only iterative function that lets you access and modify the accumulated value, and can pass arrays as it's argument. It replaces For loops very easily, it can replace Do loops but not quite as easily, and can even do some limited recursion tasks.REDUCEcan replace virtually anyLAMBDAthat doesn't use heavy recursion, you can useHSTACKto essentially pass arguments as different elements of a single array, including arguments of different dimensions.- Some problems were actually easier in Excel than they would have been in a traditional programming language. Like problem 19, which asked how many Sundays fell on the first of the month in the 20th century; or problem 89, which involved numbers written in Roman numerals.
Disclaimers:
- I made very liberal use of ChatGPT/Gemini while making many of the formulas. While it almost never produces a working formula from scratch (and often claims its impossible), It is very good at improving formatting and variable names, and identifying what is causing errors. Basically any formula with indents was at least partially re-written by AI. For some reason I can't figure out, all the LLMs are convinced you can add comments into an excel formula, and they do it constantly.
- I personally built every single formula and function used while solving the 100 problems, with the exceptions of the sudoku solver in problem 96, which I copied from a post in this subreddit by u/Verochio; and the permutations and combinations generator I modified from this comment by u/Anonymous1378.
- Some problems require using data stored in .txt files, for nearly all of these I was able to copy and paste into one cell, with no other pre-manipulations of the data. For three problems, the txt data was too long to fit in one cell and I was forced to paste the data into cells on another sheet but did not do any other pre-processing.
- I did not count named functions as violating the one formula per problem constraint.
[link] [comments]
Read on the original site
Open the publisher's page for the full experience
Related Articles
- I built a 2,257-formula workbook with zero VBA; here's what I learned about formula-only architecturejust finished a project that kind of got out of hand lol. started as a simple restaurant P&L tracker and ended up being 7 sheets, 2,257 formulas, conditional formatting everywhere, cross-sheet references, data validation dropdowns. no macros. no VBA. no power query. why formula-only? because the people using this are restaurant managers, not excel nerds. the file needs to open and just work in excel, google sheets, and libreoffice without enabling anything or trusting some macro they don't understand. some stuff i learned the hard way: SUMPRODUCT is the real MVP. when you can't use SUMIFS across sheets or you need multi-condition logic without helper columns, SUMPRODUCT handles it. i probably have 200+ SUMPRODUCT formulas in this thing. once you understand that (condition1)*(condition2)*values is just boolean multiplication it clicks and you start using it for everything named ranges will save your life. i ignored these for years and just used cell references like a caveman. when 50+ formulas reference the same range and you need to change it, one named range beats 50 find-and-replaces. also makes formulas actually readable when you come back 3 months later conditional formatting order matters and nobody tells you this. excel evaluates rules top-down and stops at the first match. had a situation where my "red alert" rule was below my "green good" rule. red never fired. spent 2 hours debugging something that should've taken 10 seconds IFERROR everything that faces the user. empty input cells create #DIV/0! cascades that look terrifying to non-excel people. one blank cell in a revenue row and suddenly the entire dashboard is a wall of errors. wrap every division in IFERROR and show clean zeros or dashes instead color-code your inputs religiously. blue = type here. black = don't touch, it's a formula. sounds obvious but the moment you stop being consistent about it someone types over a formula and breaks the whole sheet. data validation + sheet protection on formula cells is the belt and suspenders approach the biggest challenge was keeping it cross-platform compatible. some stuff that works fine in excel breaks in google sheets (looking at you, TEXTJOIN with arrays). had to test in all three platforms and rewrite a handful of formulas to use the lowest common denominator functions anyway curious if anyone else builds complex workbooks without VBA. what patterns have worked for you? what's the most formulas you've crammed into a single file? submitted by /u/Bitter_Ad_8378 [link] [comments]
- How to deal with a bulky spreadsheet that is starting to hit the limits of Excel?Hello all, I have been venturing on quite the Excel journey the past year or so. I made a corporate spreadsheet that is approaching 500k formulas and that is starting to get serious speed issues at this point. It is 2026, so I conversed with ChatGPT several times regarding the speed issue, but realized I am way better off asking the experts here anyways. What is the problem So, my spreadsheet imports flat databases with specific information regarding objects that need further analysing. The imported flat databases run from say A tot CC or something, from which I probably draw about 12-15 datafields that are used for further analysis. It 'may' be more in the future. Afterwards, said data gets 'enriched' (manually) by things that aren't in the database, also because said data needs a human eye that cannot be automated. So far, so good. Right now, each object gets analysed from several different angles. As it stands, my spreadsheet runs from A until NA or something on the Formula Page. Many columns receive data from preceding columns, that are in the turn the result of many (slightly complex) logical IF or IFS tests, many of which are nested 3 or 4 deep. Often, they work in conjunction with X.LOOKUP to retrieve values, as the columns on the formula page are not equal. For example: A until BC on the Formula Page may analyze 150 objects, BD until DD may analyse 100 objects (from the same dataset, so narrower), and so forths. Thus a lot of X.LOOKUP is required, also because the first 'block' comes up with values that need to be found with X.LOOKUP. Also, values need to be retrieved from the flat database 'import' page with X.LOOKUP. Finally, X.LOOKUP is an insurance compared to FILTER, as I am not fully convinced that empty values in the flat database always contain a space (" "). To get to the point I use many IF, IFS, AND, and if need be, OR, formulas. Thinks: tens of thousands, probably in excess of 100k. These are compounded with X.LOOKUP, or X.LOOKUP gets used copiously without those. Here too, think tens of thousands. These formulas are - as much as possible - in array format, even though I find it controversial to do that as I consider how it can create a chain of updates throughout the spreadsheet. 'Dependencies' is the name of the game, with one object receiving many possible alterations / adjustments due to manual input data, for which the spreadsheet needs to provide. Right now, when I update a value, it may take up to 4 seconds to update the spreadsheet, which is already beyond the annoyance point for me. This leads me to these (hopefully) simple questions: Is it smart to use array formulas, knowing that each thing I change should only impact that one object line (for example, row 488) and none other? It is important to mention that object 1 does not influence object 488, or any other. Any manual data field only effects the object in the row it is in. In my mind, array formulas do not make sense in that regard, as it can result in a cascade of updates, but apparantly array formulas are 'way more efficient'. Is use of a VBA library the way to go to reduce lag and create more of an instant spreadsheet again? I am not able to code in VBA yet, but I am in the slow process of learning it regardless. Alternatively: should I use LET whenever a repeated lookup is needed in the same formula? Really looking for to your answers! submitted by /u/EvolvedRevolution [link] [comments]