Problem 239
Posted: Sat Apr 04, 2009 6:59 am
Is it any 22 of prime-number disks are not on their place, and others are on place,
or 22 specific ones?
or 22 specific ones?
A website dedicated to the puzzling world of mathematics and programming
https://projecteuler.chat/
I just realized how that way of thinking about the problem is incorrect. I'd wondered why such a high-numbered problem should turn out to be a one-liner (answer: it didn't). Fixing my algorithm now...Given that there are 100 disks, calculate the number of ways to permute the disks' positions such that exactly 22 of them are deranged.
There are definitely "high-numbered" problems that allow one-liners in certain high level languages. Which ones, you'll have to find out for yourselfestanford wrote:I'd wondered why such a high-numbered problem should turn out to be a one-liner (answer: it didn't)
Nah, that's one that takes a little bit of work, but it's completely straight up algorithmic in nature -- no hidden math or crazy stuff involved. Actually, come to think of it, both of your unsolved are completely straight-forward; I'd have thought they were some of the first to go. Good luck!zwuupeape wrote:It would certainly cause me serious mental issues if it turns out problem 212 is solvable in one line
Well, I don't know if it's possible in Python, but in C or Java or Haskell, you can put the entire programme on one line.zwuupeape wrote:It would certainly cause me serious mental issues if it turns out problem 212 is solvable in one line
Unless you managed to figure out a way to write a program without any nested while/for loops, if statements, try blocks or function definitions, then it can't be done in one line in Python. You can append many statements together with ';', but any time there's a second ':' it's gotta be on a new line. Kind of a shame, I'd love to be able to write:daniel.is.fischer wrote:Well, I don't know if it's possible in Python, but in C or Java or Haskell, you can put the entire programme on one line.zwuupeape wrote:It would certainly cause me serious mental issues if it turns out problem 212 is solvable in one line
I would revoke your coding licence if you did, but you could
Code: Select all
for i,j in (((i,j) for i in range(10) for j in range(i))): print(i,j)
Well, in Haskell you can use layout to structure your code, and that's what's normally done, because the code is far more readable. But you can also use explicit {braces; and semicolons;}. You can even mix both styles (but usually people who try that run into a lot of fiendish parse errors). Using explicit braces and semicolons, you can cram your whole module on one line, but it's even worse than doing that in C.quilan wrote:I thought Haskell had some restrictions on whitespace too? I seemed to end up running into those a few times while writing some Haskell code once. Ideas?
Cool beans. At my workplace, they're showing a series of lectures on Haskell, so I've been re-catching up on my own time (sadly the interpreter still isn't working for me in Eclipse == no Haskell writing for me). The only difficulty is that the language is being presented in The. Most. Boring. Manner. Ever. Hardly no mentions of why Haskell is fun (corecursion, lazy-evaluation, beautiful language, etc). I'm glad I've written some small stuff for it in the past or else I wouldn't approach it with a 20-foot stick as it's presented.daniel.is.fischer wrote:Well, in Haskell you can use layout to structure your code, and that's what's normally done, because the code is far more readable. But you can also use explicit {braces; and semicolons;}. You can even mix both styles (but usually people who try that run into a lot of fiendish parse errors). Using explicit braces and semicolons, you can cram your whole module on one line, but it's even worse than doing that in C.quilan wrote:I thought Haskell had some restrictions on whitespace too? I seemed to end up running into those a few times while writing some Haskell code once. Ideas?
a) Why would you need an IDE?quilan wrote:Cool beans. At my workplace, they're showing a series of lectures on Haskell, so I've been re-catching up on my own time (sadly the interpreter still isn't working for me in Eclipse == no Haskell writing for me).daniel.is.fischer wrote:Well, in Haskell you can use layout to structure your code, and that's what's normally done, because the code is far more readable. But you can also use explicit {braces; and semicolons;}. You can even mix both styles (but usually people who try that run into a lot of fiendish parse errors). Using explicit braces and semicolons, you can cram your whole module on one line, but it's even worse than doing that in C.quilan wrote:I thought Haskell had some restrictions on whitespace too? I seemed to end up running into those a few times while writing some Haskell code once. Ideas?
Ugh. What a waste.The only difficulty is that the language is being presented in The. Most. Boring. Manner. Ever.
Read some papers by Simon Peyton Jones, Philip Wadler, John Hughes, Oleg Kiselyov, Jerzy Karczmarczuk, …. Fascinating stuff. And [many are] astonishingly accessible, even if one has no formal CS education. And of course the wikibook and RWH.Hardly no mentions of why Haskell is fun (corecursion, lazy-evaluation, beautiful language, etc). I'm glad I've written some small stuff for it in the past or else I wouldn't approach it with a 20-foot stick as it's presented.
Just spent too much time reading itzwuupeape wrote:Hey daniel. what do you think about Learn You a Haskell for Great Good? I don't know how high quality it is from a 'professional' perspective but it was certainly fun to read. I don't really remember at what part I stopped reading it, or why, though =\
I don't think it does. The problem should be the same for any 25-element subset of {1, ... 100}.I'm having trouble understanding why it matters that the 22 disks in question are labeled with prime numbers.
The first 2 significant digits are correct: 0.00010. After that you're wrong.szymczak wrote:If the problem was 'partial derangement such that exactly 21 prime number discs are away from their natural positions' I get 0.000105014085. Can anyone tell me if this is correct?
Thanks for the reply. I'm confused as to why I'm getting the wrong answer. I'm almost certain my solution is correct. I've even torn my code apart, and I don't think it is a precision error. If I make a nice write up of my solution (formula and explanation) will you, or anyone else who has solved the problem take a PM and look at it? At least to tell me where (and not how) my reasoning went wrong.The first 2 significant digits are correct: 0.00010. After that you're wrong.
I agree that there's nothing special about the prime subset.