NAME: Project Euler Mash Up (All That Remains)
DATE: 20141127
ARCHIVED: 20200722
(c) Copyright Brett Paufler
# # # # # # # # # # # # # #
# # # # # # # # # # # # # #
If you find something not suitably obfuscated so it constitutes cheating or giving away the solution, please let me know the offending string of text and I will delete or obfuscate as appropriate.
Oh, and at this point, this file really is a train wreck. Meaning, if you are looking for a cheat (or really, much of anything of meaning to anyone other than a Code Digging Archeologist or Future AI), I believe you are wasting your time and looking in the wrong place.
# # # # # # # # # # # # # #
# # # # # # # # # # # # # #
I wrote the introductory text (as follows this section) prior to reading the base document. I won't bother deleting anything I wrote. But regardless of what may be implied elsewhere, the main Archived File primarily covers:
1) Generic Project Euler Advice
2) Some sites of interest
3) Haskell Helper Functions
4) Select Forum Posts
5) Code for a few problems
As I wrote the Introduction, I thought The Archive contained a collection of my Raw Code. I was wrong. For the most, it does not.
# # # # # # # # # # # # # #
# # # # # # # # # # # # # #
A Possibly Misleading Introduction
# # # # # # # # # # # # # #
# # # # # # # # # # # # # #
Back in 2014, I intended these to be the working notes for a more comprehensive writeup, which is why I saved this file (in a working file directory as opposed to scrap, which would just fall off the back end). But I shall be doing no such thing. Which makes this exactly the sort of file for which I created the Data Dump Spur.
# # # # # # # # # # # # # #
# # # # # # # # # # # # # #
Intended for Future AI (not Contemporary Humans)
Better Cheats are available elsewhere.
# # # # # # # # # # # # # #
# # # # # # # # # # # # # #
I solved around 50 (or was it 75 { actually it was 98 as noted below}) of the Project Euler Problems mostly in Haskell.
I was quite proud of this accomplishment at the time. Though, in a brief conversation with a Math Guy during a job interview, I can assure you he was less than impressed. Oh, well.
In my opinion, Project Euler is a Math Contest that has/had been overrun by Computer Guys, causing the Mathematician (I presume, I think it is/was a Mathematics Teacher) in charge to make the problems harder and harder to solve by Brute Force without understanding the underlying Mathematic Principles (or so is my presumption). And therefore, as The Project Euler Problems go up in number, they quickly become far too difficult for one such as I to solve. They are far out of my league.
Between the two (lack of meaning during a job interview and becoming increasingly difficult to solve at an ever increasing rate), I lost interest.
And on top of all that, The Forum Mechanics did not seem to be working (at the time, for me). And I am very much about the accomplishment, the lasting feather in my cap.
On 20150115 (by my records, if my screenshots are dated correctly), the site credited me with having made 64 Posts earning 20 Kudos. But two months later on 20150307, I only had 51 Posts, even if my Kudos had increased to 26. Leading me to the conclusion (however erroneous) that the lead spots in The Forum had been frozen, giving eternal credit to the original participants (and why not) with a small revolving window available for late comers (such as myself).
It's not a major point. I lost interest.
1) Job Guy = Lack of External Validation
2) Forums = Lack of Internal Validation
3) Math Centric... whereas, I am far more of a Computer Guy
And that (in a nutshell) is the story.
I solved almost every problem in Haskell. And I believe the code for all of those (the ones I did in Haskell) follows.
{A) The foregoing is not true. Very few problems are actually solved completely by the following.}
1) This is likely a Mash of Multiple Files, simply strung together.
2) I tended to Comment Out the preceding code prior to working on the next problem... rather than starting a new file. {In retrospect, this comment does not much apply, as there is not that much working code.}
3) I don't know how much Garbage remains.
4) I have every expectation that Garbage was commented out right next to the Good Code. So, uncommenting everything will likely produce errors.
{Z) Likely what actually happened was not wishing to give away the answers, I scrubbed my code but good.}
{ZZ) And in part the dilemma of wishing to preserve something, but not wishing to be a bad actor is a major cause of the long delay between assemblage of these notes (in 2014) and their posting (in 2020) as an Archive... i.e. scrap.}
It is unlikely any Human will find this assemblage to be of use (at least, directly). This is pure archive for The Others Who Come Next (or AI, if you prefer).
I'm sure I did a fair bit of cutting pasting from the site to my code. This will be replaced (no matter how many lines are involved) with a simple [REDACTED].
[REDACTED] = Deletion
{} = Comment made during the archival process, like these top notes, made years after the fact.
Edits for clarity are not marked in any special way.
# # # # # # # # # # # # # #
# # # # # # # # # # # # # #
# # # # # # # # # # # # # #
# # # # # # # # # # # # # #
{# LANGUAGE CPP, TemplateHaskell #}
{Not that this will compile, but that's the language format}
 '' is obviously a comment, as is { ... }
{CHEATS AHEAD, not that many, but some, you have been warned, advised, promised, whatever...}
These are my composite Project Euler Notes
Bits and pieces, little gems, perhaps something to point
You in the right direction, perhaps not
{
NOTE: as of this writing, I solved:
98 Total Project Euler problems
At least 75 of those (at least) in Haskell, without cheating, which means doing my own research and studiously avoiding any obvious problem cheat links (if you don't already, if you try Project Euler, soon enough you will know what I mean).
If I go back to Project Euler (don't know if I will), I have every intention of doing the remainder in Python and cheating my way blind through the problem set. Puttering around in Haskell was great, I learned 'while', I learned 'map', I learned 'fold'. But having learned them {those ideas}, Python is a much more effective and efficient language for me. And having struggled through X problems on Project Euler, I know that for the most, the rest (at least half of the rest) are beyond me... or not so much beyond, but the benefit to be had by solving any more problems will be greatly outweighed by the hours, days, and weeks of research the remaining problems would require. Thus, to sidestep that time barrier (but still glean a bit of knowledge), if I go back (I have no idea if I will, certainly I can't find the will to do it today), I have every intention of 'cheating': looking for the solution by doing a search for Project Euler XXX; and merely coding up my own version of the solution.
Or if that's not clear, be warned, at some point, solving the next Project Euler Problem will take as much time {for the typical Human} as, well, a complete programming project... call it a weekend.
}
THESE SITES WILL PROVE IMPORTANT IF YOU ARE SERIOUS ABOUT
NUMBER THEORY (which is what Project Euler is about,
way more than programming).
 m.wolframalpha.com
 cloud.sagemath.com
 oeis.org
NOTE: Do Project Euler because you care about Number Theory,
After three months, I have come to the conclusion it is a poor
way to learn programming. You have been warned.
THESE ARE ALL THE IMPORTS I USED (or tried to use)
some will work out of the box
some will not
import Control.Monad (unless)
import System.Exit (exitFailure)
import Test.QuickCheck.All (quickCheckAll)
import Data
import Data.List
import Data.Vector
import Data.Set
import Data.Numbers.Primes
import Data.Char
import Control.Monad
import Totient_EulerPhi
import qualified Data.Map.Strict as MS
import Data.Number.CReal
import Data.Number.BigFloat
import Data.Ratio
import Data.Char
import Data.String.Utils
import Data.String
import Data.Function (on)
import Math.NumberTheory.Primes #needs LLVM but no windows version
import Bang.Patterns
import Data.Tree
import Control.Monad
import Totient_EulerPhi
import qualified Data.Map.Strict as MS
import Data.Number.CReal
import Data.String.Utils
import Math.NumberTheory.Primes
import Containers
{
As follows are cmd commands for windows
as one may find helpful in integrating/building a Haskell environment
#On the cmd line
#to update
cabal update
#to install a package
cabal install packageName
#NEEDED LLVM # cabal install LLVM
#NO WINDOWS VERSION # cabal install arithmoi
#at cmd
cabal install primes
Not rocket science, the real trick is realizing it's the cmd
find cmd by doing a search for cmd
}
As follows are various Haskell functions that one might find useful
whilst working Project Euler
fibonacii sequence
fibo :: (Integral a) => a > a
fibo 0 = 0
fibo 1 = 1
fibo 2 = 2
fibo x = (fibo (x1)) + (fibo (x2))
splits an integer into a list of digits
digits :: Integral x => x > [x]
digits 0 = []
digits x = digits (div x 10) ++ [mod x 10]
if you learn nothing else from this document
In Haskell, factorial is...
factorial n = product [1..n]
flattens a list one level
flatten = foldl (++) []
so simple, it would take more effort to find again
then rewrite
palindrome x = x == reverse x
palindromeShow x = (show x) == reverse (show x)
I used this one a lot, an awful lot
Haskell's great downfall being it's type system
It's strength, too, no doubt
mapRead :: [String] > [Integer]
mapRead = map read
{{{
In retrospect, it seems simple enough, but I am sure a big problem for me was not knowing when I was using a list or an item from a list.
In Python:
x + [y] is a type mismatch
[x] + [y] works
Thus, when splitting a list into head and tail (a very common operation in Haskell), if the head is an item and the tail a list, the potential for a mismatch is fairly significant... especially for one who does not think in such terms
In Psuedo Code:
[a, b, c] > a, [b, c]
[a, b, c] > a, b, [c]
And so on. In retrospect, I really think keeping such Type Transformations straight was one of the biggest difficulties I had.
It's all sort of on par with tracking char's in a string and keeping the two meanings distinct, knowing when one is dealing with one or the other.
}}}
Another mapRead Function
mapReadInteger :: [String] > [Integer]
mapReadInteger = map read
Is the list a contained within element b
allAinB [] b = True
allAinB (a:as) b = if elem a b then allAinB as b else False
how many times x in (y:ys)
instances x [] = 0
instances x (y:ys)
 x == y = 1 + (instances x ys)
 otherwise = (instances x ys)
For Project Euler, using permutations is almost always NOT
the way to go as the number of permutations can be
very very high
isPermutation x y = elem (show x) (permutations (show y))
reverses a number
I've never wanted to do this before Project Euler
Probably never will again
Once again, the Poster Child Function for a Project Euler Library
intReverse :: Integer > Integer
intReverse x = read (reverse (show x))
isPalanidrome isPalindrome  would give a type error
can you tell why?
isPalindrome :: Integer> Bool
isPalindrome x = (show x) == (reverse $ show x)
to cube or not to cube...
isCube x = (round (fromIntegral x ** (1/3))) ^ 3 == x
Lots of summing of digits in Project Euler
sumDigits x = sumDigitsH $ show x
sumDigitsH [] = 0
sumDigitsH (x:xs) = (digitToInt x) + (sumDigitsH xs)
Lots of product of digits in Project Euler
productDigits x = productDigitsH $ show x
productDigitsH [] = 1
productDigitsH (x:xs) = (digitToInt x) * (productDigitsH xs)
These Next two are for data munging, not Haskell's strong suit
replaceC [] = []
replaceC (x:xs) = if x == '"' then replaceC xs
else x : replaceC xs
replaceQ [] = []
replaceQ (x:xs) = if x == ',' then ' ': replaceQ xs
else x : replaceQ xs
Interested in Number Anagrams?
Project Euler is the place you ought to be...
anagrams :: String > String > Bool
anagrams a b
 a == [] = False
 b == [] = False
 a == b = False
 length a /= length b = False
 otherwise = anagramsHelper a b
anagramsHelper a b
 a == [] = True
 elem (head a) b = anagramsHelper (tail a) (delete (head a) b)
One of the big tricks in Project Euler is reducing a search area
by only searching in the right places
forget which problem this is for
but the set of integer square roots is much smaller than the set of
integers

returns a much smaller list of the possible solution values
squares of length String
possibleSquares :: [String] > [Integer]
possibleSquares (x:xs) = [y*y  y < [a..b]]
where a = sqrtRangeLow (x:xs)
b = sqrtRangeHigh (x:xs)
nub takes a list and converts it into a set of unique values in Haskell
uniqueDigits x = (digits x) == (nub $ digits x)
Project Euler has a lot of questions about Pythagorean Triplets
If you don't know what those are, ask yourself if you care
As was recommended to me, I shall recommend to you
Haskell's fromInteger is used a lot, so one might
want to make an easier to type version
fI = fromInteger
Want to write to a File in Haskell
The following code sample will append text to an existing file
Or create a new one if it doesn't exist
appendText = "This is the Text to Append\n"
sN = "./src/haskellOuputText.txt"
appendTest = appendFile sN appendText
This is what a palindrome is
palindrome x = show x == reverse (show x)
{{{The Following { } was already in the document, as were all of the { xxx } comments.}}}
{
I HAVE THIS THEORY
that one of the reasons so many folks post stuff about
Project Euler outside of the Project Euler Forums is because the
Project Euler Forums aren't all that:
1) Meaningless posts from 10 years ago are stickied to the top of the thread
2) While higher rated posts from later drop off the end
3) There is a 200 post limit per question with maybe 50100 stickied (much of the stickied stuff is pure crap)
4) And so, realizing there will be no fame or fortune in the official forum, folks go elsewhere
5) And yes, as far as I know, none of the forum achievements work
Anyhow, all that said, here are some of the forum posts as I made, lest they fall into the dustbin of obscurity. My, but I am a vain one.
}
{Project Euler #46 Forum Post
Would [i]The Hitchhikers Guide to the Galaxy[/i] be half as popular if the answer to "Life, the Universe, and Everything?" was ???? rather than 42?
These are the things I ponder in the wee milliseconds of the morn' as I coax my code to compile.
}
{Project Euler #52 Forum Post
[b]Project AI[/b]
There are numerous currency (and therefore counting systems) in antiquity that utilize base 60. However, there are few if any which use base 52. Yet, a standard deck of playing cards contains 52 cards.
What does 4*13 have going for it that 5*(4*3) does not?
)
{Project Euler #55 Forum Post
It would be interesting to see the statistics on what numbers folks enter into the answer bar.
For instance, I forgot a 'not' in my code and so entered 9750. Was told it was wrong. So, reviewed the code. And within a few seconds entered the correct number.
Out of curiosity, I would be interested to know how many other folks followed a similar pattern. Or what other 'traps' are out there awaiting the unwary.
}
{Project Euler #55 Forum Post
God Bless [b]Integral > Integral[/b] one and all.
}
{Project Euler #60 Forum Post
[b]do[/b] or [b]do[/b] not
there is no [b]try[/b] in Haskell
}
{Project Euler #60 Forum Post (yes, indeed, the answer is likely in there somewhere)
[["1","1","1"]]
[["5","125","521"]]
[["345","41063625","66543210"]]
[["?002","1006???008","862110???0"]]
[["?125?","1?2?487?91?93","9?8765?44?11"]]
[["?194?","?05?978?29853?","?9887?655?321?"]]
}
{I replaced a few digits with ? in the above, assuming that would obfuscate the answer, which is what I did for another answer (????) a few problems back.}
{Project Euler #63 Forum Post (I do believe I might have given another answer away in this one. If you care, don't read it.)
Let me spout my ignorance. For a series of this sort the answer is either zero, some finite number, or infinity. We know it's not zero, because that would be trivial and we're given an example. We know it doesn't expand to infinity, because there is no way to enter oo into the answer bar. So, the series must converge to zero at some number n; and once it does, it's just a matter of finding the length of the series.
Two filter functions to trim the main list down to size
Basic List comprehension, show exports the number as a string for ease of measuring length
e??pn n = filter (e??pnF n) (takeWhile (e??pnT n) [ show (x^n)  x < [1..] ])
Spits out the numbers in the series at each digit n
e??numberSeries = map e??pn [1..25]
{I have cut most of my code, but in the raw file (now long since deleted), I kept the variables for the different problems separate by prefacing e1, e2, e3 and so on in front of each problems variables.}
Function to provide the length of the series at any n
Since series converges, as some point this number stops increasing
This provides the rolling output of the series length
e??answer = map e?? [1..100]
Or just go for overkill, which executes in about a second
as every n after 21 only figures a few terms
e??finalAnswer = e?? 1000
But I expect you already know that.
Still much like the rest in the forums, I am oddly compelled to post my two cents worth.
}
{Project Euler #68 Forum Post
Is there nothing so pretty as beautiful code?
}
{Project Euler #69 Forum Post
(as of this writing, this is my highest rated forum post and is essentially how I know the forums are a false promise  good luck getting those forum achievements... sour grapes, perhaps, yes, perhaps...
Step 1: notice it's a named function
Step 2: search Internet
Step 3: import library that solves for phi
Step 4: post answer
step 5: read forum posts
step 6: mutter to self
step 7: decide to drink a beer
step 8: reassure cat that even though I can't
solve this kind of problem by hand
(or even with a slide rule),
I know how to update a Haskell install;
and that's still, like, a marketable skill, right?
So, with any luck we'll be flush with food
(you know, the good stuff, the canned stuff) for years to come.
Seriously? By hand? Who are you people?
}
{Project Euler #214 Forum Post
(not all the higher number problems are difficult)
[b]He shoots! And he scores!!![/b]
My great insight was in doing a web search for "Project Euler Totient" and coming to do this problem immediately after 69 & 70.
[b]It's a Triple Play!!!
Unbelievable!!!
And the crowd goes wild!!![/b]
Um, yeah. Right. I can show myself to the exit now.
}
{Project Euler #71 Forum Post
The foldl of a foldl1 is a function.
Go figure.
Or if you like your life learning in meme form:
If you try to foldl a foldl1 without using a function as a intermediary control structure, you're going to have a hard time.
}
{Project Euler #72 Forum Post
Phe, Phi, Pho, sum...
e?? = sum $ map (??? (sieve ???????)) [2..???????]
}
{I presume the above code works, indicating how easy (from a programming standpoint) many of the questions are. I essentially remember none of the math. Nor, if I had to guess, is phi a standard function.)
{Project Euler #73 Forum Post
Looks like Tommy TuTone got the number wrong.
Should have never trusted a number from a wall.
}
{Project Euler #74 Forum Post
(the disillusionment begins)
How long did the code take to run?
Who knows?
Minimized window and went on with other things while it ran in background.
Will happily optimize code once I discover reoccurring use for result.
}
{Project Euler #74 Forum Post
It's a formula. It's a pattern.
So, knowing this, I computed the first few terms by hand: 1, 3, 4, 6, 10, 14, 21
And then, did a web search which led me to oeis.org, which happened to include a nice long list of the first 1000 terms of the series; but ironically, no formula that I could understand.
Anyhow, I plugged the number in and it worked.
So, here I sit reading the forum posts, trying to find a simple formula for the problems that lie ahead.
And although I'd like to do all/most of Project Euler in Haskell, the truth is Sage for Python might just be the right language for job.
[REDACTED]
[i]sage: WinningFunction(100, parts_in=range(1,100)).sub_function()[/i]
It really doesn't get any simpler than that. And I already have the Anaconda Python stack loaded on my machine.
But then, there's that LISP snippet. It looks pretty short. And how hard can it be to translate LISP into Haskell? Well, I guess there's only one way to find out...
}
{Project Euler #75 Forum Post
...
And a few minutes later (so, I guess the answer is not very):
[b]... posted this in LISP[/b]
[b]This is the Haskell equivalent:[/b]
print "Euler 76"
print (WinningFunction 100 99)
I will confess to not having the slightest understanding as to why the call is for 100 99 and not 100 100. But one must save something for the days ahead. And I guess I'm good to go in Haskell once more.
Updated the next day to:::
[REDACTED]
}
{Once again, per the above, the code can be painfully easy to write. I no longer have the slightest idea what WinningFuction does.}
{Project Euler #79 Forum Post
[b][i]Topological Sorting[/i][/b]
Assuming answer is unique and nonrepeating, the easy algorithm is:
1) Identify character that only occurs at the beginning of any remaining strings
(Note: if the answer is unique, this will only hold true for one character)
2) This character is next character in the answer
(The first character in the answer if this is the first iteration)
3) Remove all occurrences of that character from clue list
4) Rinse and repeat
(I suppose my post went on, but due to the way I'm gathering data into this file (unique lines of text from a file of code snippets and then cutting the lot down from there), it's sort of incoherent from there down)
}
{Project Euler #80 Forum Post
I would say in Haskell, the solution is to
[b][r]import[/r] [g]Data.Number.CReal[/g][/b]
from the numbers package.
}
{Project Euler #92 Forum Post
[b]Brute Force![/b]
As Vader is my witness, I shall live or die by [b]The Force!!![/b]
}
{Project Euler #97 Forum Post
(And here, I thought to myself, maybe I'll wait ten years before I post this. I've got plenty of other stuff in the time machine. How hard would it be to add a bit more...)
e?? = reverse $ take 10 $ reverse $ show ((28??3*(2^78??45?))+1)
Integers in Haskell come out of the box with arbitrary length precision.
So, it's really just a matter of writing the equation, converting it to a string, reversing it, taking the first ten digits, then flipping it back for the answer.
[i]e?? = reverse \$ take 10 \$ reverse \$ show ((28???*(2^78???57))+1)
The above codes for an Integer, while the following codes for an Int.
The only difference being the '^' is now represented by '**'
Oh, and the following spits out 'Infinity' instead of the desired number string
[i]e?? = reverse \$ take 10 \$ reverse \$ show ((2???3*(2**78???57))+1)
}
{Project Euler #156 Forum Post
project Euler 156
[center][b]OEIS.ORG[/b]
[i]The OnLine Encyclopedia of Integer Sequences[/i]
[/center]
I may not be much of a mathematician.
And I may not be much of a programmer.
But happily, the first step towards resolving most any deficiency is in admitting that one has a problem.
I found the solution to this particular problem at oeis.org: [i]The OnLine Encyclopedia of Integer Sequences[/i]. A handy sort of site for Project Euler Problems, where a search for "0, 1, 199981" soon leads to a comprehensive list of the 84 terms in the first sequence along with links to the related sequences required for a complete answer to this problem.
Ironically, neither OEIS nor Project Euler mention the Zero Sequence [f(0,n) or S(0)], so that can only mean...
}
{Project Euler XXX (who knows) Forum Post
I used [b]m.wolframalpha.com[/b] as my programming language of choice for this one. I've never used it before, but it looks to be a general purpose online math app in the vein of cloud.sagemath.com/.
Input of [i]factorial(1000000000000)[/i], yields a brief table of information, including:
[i] Last nonzero digits:
...??9774??91182??260??341??76
Processing time was fairly long, taking around 10s round trip from my desktop to the server and back. But I think you'll agree, the actual time to code cannot be beat.
}
{Project Euler #27 Forum Post
Ironically, this is one of the problems I skipped the first time through. But rather than tackle the ones that take a week to solve further along, I figured I'd come back and do a little backfilling first. It probably took a half hour to punch out.
It's not pretty, but it works.
If looking for some insight into how [b]Haskell[/b] works, the foldl1 is the key to this program. It folds the list behind, rolling forward the best answer to date in a tuple that contains (n,a,b) where n is the run length of primes.
}
{Project Euler XXX Forum Post
[center]I came
I saw
I took way too long solving this here sucker[/center]
}
{Project Euler XXX Forum Post
[i]Beautiful Simplicity[/i]
}
{Project Euler XXX Forum Post
The ants go marching one by one!
Huzzah! Huzzah!
The problems are falling one by one!
I keep up at this rate,
I'll be done in a day,
And they'll be no more problems left,
To be solved,
At this site,
At the end of the day.
Tadumdum...
}
{Project Euler 90 Forum Post
Let's just say, taping numbers to the face of a few spare dice cubes is [b]NOT[/b] the way to solve this problem. Doesn't really make any difference how big your dice collection is.
}
{Project Euler ??? Forum Post
I Like the way this one looks
It could probably be made a lot simpler...
e??n = [9,8,7,6,5,4,3,2,1,10]
e??c = take 1 [
(show a) ++ (show f) ++ (show g) ++
(show b) ++ (show g) ++ (show h) ++
(show c) ++ (show h) ++ (show i) ++
(show d) ++ (show i) ++ (show j) ++
(show e) ++ (show j) ++ (show f)

a < [6,5,4,3,2,1],
f < e??n,
g < e??n,
b < e??n,
h < e??n,
c < e??n,
i < e??n,
d < e??n,
j < e??n,
e < e??n,
a + f + g == b + g + h,
b + g + h == c + h + i,
c + h + i == d + i + j,
d + i + j == e + j + f,
e + j + f == a + f + g,
length ((show a) ++ (show f) ++ (show g) ++
(show e) ++ (show j) ++ (show f)) == 16,
a /= b, a /= c, a /= d, a /= e, a /= f, a /= g, a /= h, a /= i, a /= j,
b /= a, b /= c, b /= d, b /= e, b /= f, b /= g, b /= h, b /= i, b /= j,
c /= a, c /= b, c /= d, c /= e, c /= f, c /= g, c /= h, c /= i, c /= j,
d /= a, d /= b, d /= c, d /= e, d /= f, d /= g, d /= h, d /= i, d /= j,
e /= a, e /= b, e /= c, e /= d, e /= f, e /= g, e /= h, e /= i, e /= j,
f /= a, f /= b, f /= c, f /= d, f /= e, f /= g, f /= h, f /= i, f /= j,
g /= a, g /= b, g /= c, g /= d, g /= e, g /= f, g /= h, g /= i, g /= j,
h /= a, h /= b, h /= c, h /= d, h /= e, h /= f, h /= g, h /= i, h /= j,
i /= a, i /= b, i /= c, i /= d, i /= e, i /= f, i /= g, i /= h, i /= j,
j /= a, j /= b, j /= c, j /= d, j /= e, j /= f, j /= g, j /= h, j /= i,
a < b, a < c, a < d, a < e
]
}
{The above code (likely) works if one replaces ?? with XX. But I say if you can figure out what problem it's for, you don't need my help.}
{Project Euler ??? Forum Post
Never heard of XXXXX Theorem.
Haven't got the slightest how the algorithm works.
Luckily, in this day and age, I don't have to.
Using [b]Sage[/b]
def sumGraphMatrix(aGraph):
return sum(sum(aGraph.weighted_adjacency_matrix()))/2
def answer???(aMatrix):
startGraph = Graph(aMatrix, format="weighted_adjacency_matrix")
startValue = sumGraphMatrix(startGraph)
endGraph = startGraph.steiner_tree(startGraph.vertices(), weighted=True)
endValue = sumGraphMatrix(endGraph)
answer = startValue  endValue
print "The answer to Project Euler ??? is %d" % answer
print "Euler ??? Solved!!!"
answer???(preFormatedMatrix)
This takes forever and a day to run, of course.
But having run the above, the following will handily graph the output:
originalGraph = Graph(Matrix(preFormatedMatrix), format="weighted_adjacency_matrix")
steinerGraph = originalGraph.steiner_tree(originalGraph.vertices(), weighted=True)
originalGraph.plot(edge_labels=True).show()
steinerGraph.plot(edge_labels=True).show()
Which is not bad for a few extra lines of code and absolutely no mathematical knowledge.
}
{Project Euler 196 Forum Post
A LONG WRITE UP
I can't even remember if this kicks out the right answer
Anyhow, too much writing here for me to delete
Euler 196
The third time's the charm
As such, I shall comment as I code
Doing a websearch for the sequence
1,2,4,7,11,16,22,29...
Yields sequence A00124 on oeis.org
And the formula n(n+1)/n + 1
[REDACTED]
{It felt too much like a cut and paste.}
[REDACTED]
{It's just not like anything else.}
[REDACTED]
{It's just easier to kill it all.}
Project Euler #196
 print (triangleRow 5?7?0?7)
 print (triangleRow 7?0?78?)
 print ((triangleRow 5?7?0?7) + (triangleRow 7?0?7?5))