Jump to content

requinix

Administrators
  • Posts

    15,066
  • Joined

  • Last visited

  • Days Won

    414

Posts posted by requinix

  1. That answer also got shut down :(

    I gave up and found the answer somewhere else and there is no trickery in the question after all.

    Nested hints:

    Spoiler

    #1 The answer has the structure # _ (# _ (# _ #))

    Spoiler

    #2 If you made a list of the four operators in order of how likely you think they are to be used, you would be completely wrong

    Spoiler

    #3 The inner parenthesized result is not a whole number

  2. Nope, a decimal point counts as an operator (apparently). Supposedly it really is just the problem at face value: those four numbers, each used once, and as many add/subtract/multiply/divide operations (and parentheses) as you want.

    The way that latter point is phrased is unusual. "Unlimited supply", but you'd only ever need three... So you'd think there's a trick there, but it specifically states you have to use them as binary operators.

  3. Could swear I had a book with these sorts of puzzles but I can't find it.

    So I'm looking through the internet for a good source to post - not original, but it is something - and I find this one:

    Quote

    Young Saul, a budding mathematician and printer, is making himself a fake ID. He needs it to say he’s 21. The problem is he’s not using a computer, but rather he has some symbols he’s bought from the store, and that’s it. He has one 1, one 5, one 6, one 7, and an unlimited supply of + – * / (the operations addition, subtraction, multiplication and division). Using each number exactly once (but you can use any number of +, any number of -, …) how can he get 21 from 1, 5, 6, 7?

    Note: you can’t do things like 15+6 = 21. You have to use the four operations as ‘binary’ operations: ((1+5)*6)+7.

    I can't solve it. Even ran a quick script to try every possible combination of ((# _ #) _ #) _ # and nothing works. So I'm figuring there must be some trick in the phrasing, except I'm not seeing a loophole in there: "each number exactly once" using the "binary operations" of "addition, subtraction, multiplication, and division". (And in fact, creating operators like negation and exponent still isn't enough to get a solution.)

    Non-answer: if the goal is to be legally an adult then coming up with 22 would be fine too.

  4. Is that missing one? The version I know has 11 "had"s. Though 10 works too, it's just changing which boy was correct.

    There's also the classic "buffalo buffalo buffalo buffalo buffalo buffalo buffalo buffalo" (needs punctuation and capitalization), but that can totally be stretched out further - like pretty easily to "buffalo buffalo buffalo buffalo buffalo buffalo buffalo buffalo buffalo buffalo buffalo".

    I should go looking for some puzzles too...

  5. 10 hours ago, Barand said:

    That wasn't thinking outside the box, that was a cop-out. :)

    That wasn't the answer? No way, that totally was the answer

    Spoiler

    because it's a mid-winter party and woodchucks hibernate during the winter.

    10 hours ago, Barand said:

    The  woodchuck was just slower than the others collecting his twigs. There is a (none-zero) solution.

    Then I'm thinking 11 twigs.

  6. Speaking of thinking outside the box,

    56 minutes ago, Barand said:

    Some animals are gathered in the forest having a midwinter party, all seated around a fire.  When the fire starts to die down they all move off to gather more wood.
    The walrus manages to gather 7 twigs and throw them on the fire, the widgeon throws on 21 twigs, the wombat 11 twigs, the weasel 20 twigs and the wolverine throws on 28 twigs.
    How much wood would a woodchuck chuck if a woodchuck would chuck wood?

    Spoiler

    Trick question: there is no woodchuck at the party.

     

  7. 4 hours ago, Barand said:

    I took the integration / volume of rotation route and came up with the solution.

      Hide contents

    When I passed the question to my friend (who, incidentally, has a PhD in Mathematics) he thought for a few seconds then said "36 pi. Consider the case where the diameter of the hole is zero".

    In that case it simply becomes the volume of a 6cm diameter sphere. Doh!

    I love shortcuts too but damn, that one is just plain annoying 😆

    Ah, I envy that ability to think outside the box...

  8. Yay added the spoiler button.

    Been a long time since I've done integrals, so I first tried the brute-force solution to make sure I had the right answer.

    Spoiler

    Volume by parts: need the volume of the sphere, the volume of the cylinder, and also the volume of the bits on top and bottom that were completely drilled away.

    Sphere: 4/3 pi R^3 - where R is the radius of the sphere
    Cylinder: pi r^2 h - where r is the radius of the cylinder/drill bit and h is the height
    Top and bottom: 1/6 pi X (3r^2 + X^2) - where X is the height of the removed bit; this shape is called a "spherical cap" and yes, I did have to Google it

    First problem is that X, but it's simple: the height of the whole sphere is 2R and is also 2X + 6. So X = R - 3.
    Which gives 1/6 pi (R - 3) [3r^2 + (R - 3)^2]
    -> 1/6 pi (R - 3) (3r^2 + R^2 - 6R + 9)
    -> 1/6 pi [ (3R r^2 + R^3 - 6R^2 + 9R) - (9r^2 + 3R^2 - 18R + 27) ]
    -> 1/6 pi (3R r^2 + R^3 - 9R^2 + 27R - 9r^2 - 27)
    which could be simplified more but hold on.

    So the volume of all the removed stuff is the cylinder's plus two of the cap's:
    -> pi r^2 h + 2/6 pi (3R r^2 + R^3 - 9R^2 + 27R - 9r^2 - 27)
    then substitute h = 6 and simplify,
    -> 6 pi r^2 + pi (R r^2 - 3R^2 + 9R - 3r^2 - 9) + 1/3 pi R^3
    -> pi (R r^2 - 3R^2 + 9R + 3r^2 - 9 + 1/3 R^3)

    Scary. Take that volume away from the sphere to get what is remaining.
    4/3 pi R^3 - pi (R r^2 - 3R^2 + 9R + 3r^2 - 9 + 1/3 R^3)
    -> pi (R^3 - R r^2 + 3R^2 - 9R - 3r^2 + 9)

    Now at this point I look at the parts and realize that it can be factored. I don't know how to explain that thought process, but there is a pattern to how factored groups get expanded that you learn to recognize. Red is factored, green is not.
    -> pi [ (R + 3)(R^2 - r^2) - 9R + 9 ]

    Not as scary as before, but still not the most fun thing ever.

    But wait! Next, simplify even more by adding in the relationship between R and r: looking at the cylinder side-on, there's a triangle with R as the diagonal, r as one side, and 3 as another. Thus
    r^2 + 9 = R^2
    which you can also get if you see the triangle as 2R, 2r, and 6 instead. Rearranged,
    R^2 - r^2 = 9

    Oh hey, that term looks familiar, and it totally collapses the equation into something far more manageable:
    -> pi [ (R + 3)(9) - 9R + 9 ]
    -> pi (9R + 27 - 9R + 9)
    -> 36 pi

    That's the answer and it doesn't even have any variables in it. Which was subtly hinted at by the fact that the problem doesn't tell you R or r but does ask for the volume remaining - something you theoretically wouldn't have been able to know without those.
    36 pi suggests it's 6^2 pi, but if you remember that the units are 6 cm then doing that would end up with a volume of 36 pi cm^2 which isn't right. So my guess is that "6 cm" was a convenient number (something math problems love to do) and the actual formula is closer to 1/6 h^3 pi (which would give the proper units of cm^3); the "1/6" is weird but sphere-math has lots of division by 3s so it's not an unreasonable guess.

    With that out of the way, the integral. It's actually much easier regarding the sheer math work, but requires a little more thinking to get it.

    Spoiler

    Two reason why integrals:

    1. So, so often, when dealing with a regular 3D object, you can do the math in 2D and then integrate it into the third dimension. A sphere and a cylinder are very much two regular objects.
    2. Any time you have an equation based on a single variable which represents an "axis", an integral could be useful. It's basically the act of repeating that equation for all points along the axis, and it translates an X-dimensional system into an (X+1)-dimensional system.

    The choice of axis is obvious: the Y/vertical axis. It suggests itself when you consider that the act of drilling down through the sphere is basically equivalent to "slice a horizontal piece of the sphere and put a hole into it" repeatedly.

    What's the equation to be repeated? If I had a graphic it would be easier to explain, but I'm lazy. Using the above sentence as inspiration, the equation can be that of a horizontal slice of the sphere.
    So forget "volume" for a second and focus on "area". The desired result for a slice of the sphere is the remaining area after the hole was drilled through. Which is actually really easy: the area of the whole slice minus the area of the drilled-out portion.
    Which is pi S^2 - pi r^2 (where S=radius of the slice and r=radius of the drill bit/removed portion).

    r is an unknown value, but it's a fixed value so leave it alone. However S is not a fixed value as it depends on which slice of the sphere you're taking: S=0 at the top, grows to some value (the radius of the sphere) in the middle, then back down to 0 at the bottom.
    That's not going to be useable with an integral so it has to be expressed differently. And there's only one way to do that so it's useful: by expressing it in terms of the Y axis. Because the Y axis is the only other variable the integral can make use of. It is the variable it will use, even.

    Insert another lack of graphic here.
    Look at the sphere from the side (again), pick a slice to cut through it, and imagine a triangle with three points: the center of the sphere, the outer tip of the slice, and the "corner" between the two (which could be along the sphere's central line or its equator, same thing either way).
    One edge of that triangle is the width of the slice (S) and another edge is the distance down into the sphere that you've drilled (call it "h"), and the diagonal is the radius of the sphere (R).
    Thus R^2 = S^2 + h^2.

    That makes the area of the remaining portion of the slice, after drilling, pi (R^2 - h^2) - pi r^2.

    As in the other solution, R and r have a relationship of R^2 = r^2 + 9. Rearrange the area equation a little and suddenly things fall into place:
    pi (R^2 - h^2) - pi r^2
    -> pi (R^2 - r^2) - pi h^2
    -> pi (9) - pi h^2

    Integral along the Y axis, aka the "h" variable, gives 9 pi h - 1/3 pi h^3. Yeah, yeah, "plus C" but nobody cares about that (and besides, it'll cancel out later). This equation could be simplified a little but meh.

    So now what? To actually get volume from this, you have to evaluate the integral along the "length" of the axis, which just means evaluating the integral at the beginning and end and taking the difference. And the beginning is the top and the end is the bottom, right?
    Actually no. Remember that slice and triangle earlier that introduced "h"? That was based on the center of the sphere, which means the axis has to be defined according to that in order for everything to be consistent. Violate that - the coordinate system - and the various equations aren't compatible anymore.
    Which means the top of the sphere (the beginning) has to be at h = 3 and the bottom of the sphere (the end) at h = -3.

    The beginning of the integral is 9 pi 3 - 1/3 pi 3^3 = 27 pi - 9 pi = 18 pi.
    The end of the integral is 9 pi (-3) - 1/3 pi (-3)^3 = -27 pi + 9 pi = -18 pi.

    And the total is beginning minus end, which is 18 pi - (-18 pi) = 36 pi.

    Fun fact: there were some shortcuts I didn't use here, and I'm horribly glossing over some details in mentioning them:
    1. The sphere is two hemispheres on top of each other, and they are identical to each other. Could calculate the volume for just one and then double it.
    2. Dealing with hemispheres means the "triangle was based on the center of the sphere" issue goes away and you can go back to saying that the center is h=3 again.
    3. The remaining volume at the top and bottom is 0 so those parts of the integral work don't matter.

    Thus you can do just 9 pi 3 - 1/3 pi 3^3 = 18 pi, then double it to get the final answer of 36 pi.

    That's more interesting math than I've ever had to do as a (web) developer. Actually, with maybe one exception... but I don't remember quite what it was so whatever.

  9. Alright, this one took me a while to remember how to do. It's part of a class of problems of manipulating one number's digits to come up with another number, and the work to solve it tends to have a common pattern.

    Spoiler

    Say the first number is A and made up of the digits a0a1a2...an (so it's n+1 digits long).
    The second number is B and would thus be made up of the digits a1a2a3...ana0 (with the first digit of A moved to the end).

    They share a common portion of a1a2a3...an (without that first/last digit that got moved around). Call the number that those digits creates C.
    Now rephrase A to be a0 * 10^n + C (which puts a0 in the most-significant place and then adds C).
    And similarly rephrase B to be C * 10 + a0 (moving C's digits over one position and then adding a0).

    B = 1.5 * A, or without that annoying decimal, 2B = 3A.
    Substituting the earlier equations, 2(10C + a0) = 3(a0 * 10^n + C),
    or 20C + 2a0 = 3a0 * 10^n + 3C.

    You can simplify a little by eliminating the 3C to get 17C + 2a0 = 3a0 * 10^n (that's the 17 I saw coming).
    Rearrange to get C = (3a0 * 10^n - 2a0) / 17.

    The smallest A is going to be where a0 = 1, thus simplify a little more to C = (3 * 10^n - 2) / 17.
    (I don't remember why this is valid; n is pretty much fixed, just unknown, regardless of the value of a0. But you can try this with other a0s too.)

    C must be a whole number, so the question is where to find a 3 * 10^n - 2 that is divisible by 17.
    The simplest method is to just keep trying: 28/17, 298/17, 2998/17, 29998/17... but I think there's a shortcut here by recognizing that 17 is prime?

    Eventually you find n=15 and 2999999999999998 / 17 = 176470588235294.

    Thus A = 1176470588235294 and B = 1764705882352941.

    • Like 1
  10. What "fallback"? It doesn't make sense to have a "fallback". What you're doing is altering the data being passed to your script. You're saying "yes, you did type one thing, but I'm going to change it and pretend you typed something else".

    There are two basic parts to things like HTML and SQL and JSON and the like: you have the bits with values that you want to fill in (data), and you have the bits that are not data but fundamentally define how the HTML/SQL/JSON works (structure). Sanitization is about making sure that the data stays "data" and never crosses over into "structure".

  11. 1. Never modify $_GET and $_POST.
    2. Never sanitize values ahead of time.
    3. Always work with pure, unaltered values, and reserve sanitizing values until the very last step according to what you're doing with those values.

    So yes, there is a problem with that there. Don't do it. You should only ever be doing two(ish) things: use prepared statements for your SQL, and use htmlspecialchars when outputting an unknown value into HTML. More than that is probably wrong and going to create problems for yourself in the present and/or future.

  12. You want to encrypt a stream using functionality that encrypts files? That doesn't sound right...

    "No such file or directory" sounds relevant. Does the $messageData file exist, and is it readable by PHP? Does the $encryptedMessage file exist, or at least its parent directory, and is it writable by PHP?

  13. That response doesn't look like the data you need. In the earlier code, you had three arrays: one of Region, one of McTotal, and one of McAssigned. Now you have one single array with all of the Branch (not Region?), McTotal, and McAssigned values.

    If you make your PHP return the three arrays separately from each other (such as in an object) then your Javascript can take the three arrays and use them with the graph.

  14. What part are you having a problem with?

    Is it the Javascript? Can you change your Javascript so that the graph can update when one of those variables changes? Make a function to do this, make its arguments be those three values, then call that function when the page loads.

    Is it the PHP? Can you change the code so that it filters in the way you want, getting whatever values it needs to do so from $_POST?

  15. You're throwing a lot of CSS at this problem. If you have a problem, adding more CSS rarely ever makes things any better.

    Rethink how your different blocks of content are arranged.

    If you want the border to span the width of the input as well as the button, don't put the border on the container.
    If you want the button to sit next to the input, don't use absolute positioning.
    If you want a gap between the input and the button, don't add padding to the inside of the input.

    Learn about margins vs. padding, about inline-block, and if you want bonus points, about flexbox.

  16. I would first check the VS PHP extension to see what support it has; probably not PHP_CodeSniffer, but quite possibly Xdebug.

    If not then there's a good chance you're out of luck - because nobody uses Visual Studio for PHP. And, frankly, you should take that as a hint, and go for a PHP IDE (like PhpStorm) or switch to VS Code (at least for this).

    Don't get me wrong, I like Visual Studio. I think it's a great platform. But software development is about using the right tool for the job.

  17. Why would you use Javascript for this?

    It's okay to have the regex be multiple patterns. You don't, not necessarily, have to use a single capture group to get the one value you care about.

    youtube.com/shorts/(\w+)|youtube.com/watch\?v=(\w+)|youtu.be/whatever else

    Only one of $1 or $2 (or what you put in the "whatever else") will ever have a value.

    And do remember that "." matches anything, so "youtubexcom/short/blah" will match the above too.

    • Like 1
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.