Project Euler / programming problems

Now halfway to my goal of 100 problems solved :smiley:
image

Quick comment on problem 52

Didn’t even need pen and paper for this one :grin:
#52 Permuted multiples - Project Euler

Do we want to continue discussing one problem at a time? The next one is:

image

4 Likes

I almost feel like we had this one before :smiley:

Just

whip out the n*(sqrt(n)/ln(n)) algorithm again, and sum out the array with the primes in the end

A much more interesting question about this would be how accurately we can predict that sum, without counting anything.

Another comment on problem 52

The very first post about that problem in the forums is from someone else in Sweden making that same sort of remark:

77 of the first 100
image
and also have 205 and 719 solved.

2 Likes
new language for me

Any Go(lang) enthusiasts? Still trying to get the hang of it, feedback welcome :slight_smile:

func sumPrimes(max int) (sum int) {
	var primes = make([]bool, max)
	for i := range primes {
		primes[i] = true
	}

	primes[0], primes[1] = false, false

	for i := range primes {
		if primes[i] {
			for j := i + i; j < len(primes); j += i {
				primes[j] = false
			}
		}
	}

	for i := range primes {
		if primes[i] {
			sum += i
		}
	}
	return sum
}
4 Likes

Probably off topic (of topic?) and not Eulerian, but I am not a mathematician.
Question about Pi or π:

Is 2π > 1π?

Just curious.

What do you really mean by this question?

At face value, with the typical interpretation, yes, it is true. Pi is a mathematical constant that is approximately 3.14, and the double of that value is strictly larger than one times that value.

However, maybe you are trying imply something different or unconventional with this seemingly obvious question? There’s no hard rule that the Greek letter π must be used to refer to the constant rather than something else. One could always redefine the usage of that symbol when establishing one’s own notation. If one says “let π denote zero” (note that this is not claiming that the fundamental ratio is zero, but just redefining what we mean by this symbol), then the above statement is false.

One could also redefine other parts of the statement, such as giving a different meaning to the > symbol, or departing from the convention that placing a digit directly adjacent to another non-digital symbol denoting a value as implying multiplication.

3 Likes

No, π is better than τ.

:stuck_out_tongue_closed_eyes:

2 Likes

2 Likes

Sorry, I am rather absentminded lately. My thoughts fly into a million directions :frowning:

It was meant as an introduction to another question (which I forgot to add).
Can’t even exactly reconstruct my line of thinking, but it was leading up to:

Is 2 times infinite larger than 1 time infinity?

Is 2∞ > ∞?

I was curious what mathematical minds would think of this.
(But you already answered the question in your previous post. Thx for that.)

2 Likes

There are several concepts in mathematics that are like a notion of infinites of different sizes.

For example, there are an infinite number of natural numbers, but those are a rather tame set to deal with, and I believe are considered to be an example of the smallest class of infinite set, since they are “countable” (in the sense that one could list them out in their natural order, not that it would be practical to actually do so). Any other infinite set that can be put in one-to-one correspondence with the natural numbers are considered to be essentially the same size (and also called countable). On the other hand, an infinite set that is not countable, such as the real numbers, is essentially a larger type of infinite set.

There’s an entire area of mathematics that explores and generalizes this concept. @Vsotvep would know a lot more about this.

Another sense of different sizes of infinity is the asymptotic approximation of how functions or sequences grow toward infinity. These are useful for roughly comparing the fundamental efficiency of algorithms as the size of the problem scales.

3 Likes

To answer how mathematical minds think about this: mathematics is all about definitions. So this question highly depends on how you define “infinity”, how you define “times”, how you define “larger than”.

However, in general the most important thing one learns up to early university, is that “infinity” is not a number. This is of course a lie that is only introduced to erase confusion from students (similar to how you learn that x2 = -1 has no solution at first, but later might learn about imaginary numbers). The nuanced perspective is that “infinity” can be defined as a number, but that it won’t behave in the same way as real numbers for most reasonable definitions. In particular, when someone figures that “infinity” is the same as “infinity + 1”, and then subtracts “infinity” from both sides to prove that 0 = 1, that is invalid, because they implicitly assumed that the same rules of arithmetic apply to infinity as they do to finite numbers (and it turns out, they don’t).

I could give some examples of interpretations of “infinity”, “times” and “larger than” that either show your assertion to be true or false, if you’re interested.

4 Likes

I’m a sucker for pop math… this vsauce video is a great introduction to the cardinal and ordinal numbers.

1 Like

I thought you were referring to the debate of whether pi or 2pi should be denoted and used in formulae as a constant :sweat_smile:

2 Likes

A few days ago, I reached level 4 (100 problems solved) on Project Euler. However, I still have a few left to solve in the first 100.

image

Some subsets of these problems are quite beautifully connected, like a nicely curated collection of tsumego that builds off of earlier developments, in order to illustrate a broader theme. However, these sets are a bit dispersed among others.

Very mild hints pointing out which problems are connected

I just solved #100 Arranged probability - Project Euler with a quick solution that makes use of the techniques that I used for #66 Diophantine equation - Project Euler, which in turn built off of the code that I wrote for #64 Odd period square roots - Project Euler and #57 Square root convergents - Project Euler.

Looking back, it seems that some of these techniques could also be used to get fast solutions for #44 Pentagon numbers - Project Euler and #45 Triangular, pentagonal, and hexagonal - Project Euler.

5 Likes

So, there’s a month-old PE thread that I missed. I must be really slacking off hehe :thinking:

I think it was @shinuito (and others) who brought up the topic of “cheating”. I’d like to fill in the gap with the bit of gossip that is missing (which I’ve gathered from little pieces here and there):

Long Version

There was a particular user—I’ll call them WC—who apparently got banned several times. I think WC was a “perfect solver” (meaning they were up-to-date with all the solutions) some number of years ago. I won’t speculate on their motivations, but at some point WC created a forum containing lists with all the answers (not algorithms, just plain numbers), which some people started using to boost their ranking or whatever.

Be it as it may, the nature of said forum seemed to be that a handful of people would work on getting the answer of the latest problem, post it (again, just the number), and then other members of the forum would rush to enter it into their own accounts in order to appear as the “fastest solvers”. Predictably, all of this got WC on the bad side of PE’s moderators.

By the way, I just checked and WC’s forum appears to have been inactive for at least a year. This is most likely due to WC moving on to something else rather than a ban from the service provider, as there’s really very little PE’s mods can actually do about it :woman_shrugging:t4:.

TL:DR Someone annoyingly tried to spoil every single answer, rendering the record tables meaningless.

Anyway, all that story seems kinda funny to me. In my opinion, there was some level of bad faith in some of this actions, as it at least spoiled it for the people who took it as a competition. I don’t think there is a better or worse approach to learning, whether individually or collectively. However, in some sense PE is just a game. People play for different reasons, the whole point would be not to ruin the fun for others.

Even though I’m a bit late on this, I also agree that not discussing the problems beyond #100 is a fair enough compromise.


P.S. I’ve already added a @Chinitsu and @yebellz, I don’t know if I missed someone else. In case somebody wants it, this is my friend key: 143520_ZMJKGQ8lgnq5hzGBNYK0NpPZKoAA9bIj

4 Likes

Somehow I missed this thread as well until I was tagged by @yebellz two weeks ago.

I should try to solve some more of these, I haven’t programmed in ages. My current progress:

I also solved 262 and 504, probably because they were homework for some programming course?

4 Likes

Here’s my friend key

223131_BkWlWOSSFDYhQy35ojrqWpQx6fiZIDzl

for @Vsotvep and others that might want to add

My key:

648734_pTTgypPoQGHCNbzF2pL4tZm4w7EJOsob

Screenshot 2022-04-12 214710

HOLY COWS 348 SOLVED! Is this you @Leira ?

Also, my key: 1682596_77PAA3iS7ehWOOH8CFjOg4sICwzL18qV :sweat_smile:


P/S: I was really really annoyed when the later questions always use a dataset of 1e14+. I was trying to 100% the 10% difficulty range, but when faced with those problem urgh… I mean javascript can only safely handle numbers below 1e16, and array can’t even hold more than 1e6 items.

So had to switch to C++ which I haven’t touched since university time. Progress was sooo slow.

Maybe it’s high time I should learn some Python, or Rust…

Congrats!, you’re so close to the C for Commitment. I gotta say that #96 (Sudoku) and #84 (Monopoly) were the bane of me back in the day. It turned out they weren’t as unfeasible as I initially thought, but I had chosen rather convoluted approaches.

My hint for both of those

Don’t try for an exact solution. Sometimes bruteforceish is good enough.

Hehe yeah, that’s me :sweat_smile:. It’s been several years in the making to be totally honest… I think I joined OGS and PE at about the same time :thinking:.

Sometimes I feel I’ve reached my limit, but then go on a 10 problem streak six months later. It’s been a grind, for sure, but pretty fun.

I’ll happily share (spoiler free) mathematical theories and/or insights that have been useful to me on several of these problems, if you all want.

5 Likes