![]() |
[QUOTE=axn;497534]We could tell you, but it is better that you "troubleshoot" this one yourself.[/QUOTE]
If I use my function on the list [1,2,3], the result is 7. But if I take the [C]subsequences[/C] of the list, I get 8 results. The first element is an empty list, so I guess that's what we exclude in [C]estSubsets[/C]... |
Exactly right.
Have you come across Pascal's Triangle? [CODE] 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 etc. [/CODE]Each number is the sum of the two numbers directly above it (with blank space counting as 0). We number the rows starting with row 0 at the top. On each row, we number the positions, starting with position 0 on the left. Then for all non-negative integers r & n with r≤n, the number at position r on row n gives the number of subsets with precisely r elements that can be made from a set with precisely n elements. And the sum of all the numbers in row n is \(2^n\), which is another way of finding the total number of subsets of an n-element set. |
1 Attachment(s)
[QUOTE=Nick;497614]Exactly right.
Have you come across Pascal's Triangle? Each number is the sum of the two numbers directly above it (with blank space counting as 0). We number the rows starting with row 0 at the top. On each row, we number the positions, starting with position 0 on the left. Then for all non-negative integers r & n with r≤n, the number at position r on row n gives the number of subsets with precisely r elements that can be made from a set with precisely n elements. And the sum of all the numbers in row n is \(2^n\), which is another way of finding the total number of subsets of an n-element set.[/QUOTE] We encountered that in Algebra 2, as the [URL="https://en.wikipedia.org/wiki/Binomial_theorem"]binomial theorem[/URL], which states that the expansion of a binomial raised to a power (such as [$](x+y)^2[/$]) yields a sum of terms of the form [$]ax^b y^c[/$], with [$]a[/$] being a specific constant based on the corresponding row of Pascal's Triangle, [$]b[/$] being the initial exponent counting down from the left, and [$]c[/$] being the initial exponent counting up from 0. The value of the initial exponent ([$]n[/$]) corresponds to the row of that number on Pascal's Triangle. For [$](x+y)^2[/$], this is the row [$]1 \ 2 \ 1[/$]. We expand the binomial as such:[$$]1*x^2*y^0+2*x^1*y^1+1*x^0*y^2[/$$]Removing all of the 1's...[$$]x^2+xy+y^2[/$$]It's pretty neat, although I usually forget about it. Normally the polynomials I work with are simple to expand, and are products of different polynomials rather than a polynomial raised to a power. The Wikipedia article was interesting, and included this very nice graphic: [ATTACH]19121[/ATTACH] Is there a straightforward way to begin to understand how objects work in higher dimensions? I still can't figure out the basics of a tesseract... Also, a mention of a general case of Pascal's Triangle in more dimensions, [URL="https://en.wikipedia.org/wiki/Pascal%27s_simplex"]Pascal's Simplex[/URL], which doesn't look simple at all :ermm: |
[QUOTE=jvang;497657]Is there a straightforward way to begin to understand how objects work in higher dimensions? I still can't figure out the basics of a tesseract...[/QUOTE]
Another good question! For 4 dimensions, we can use time as the extra one. For example, to visualize a 4-dimensional cone, start with any 3-dimensional object and imagine it shrinking to a point. Apart from that, all we can do is map the higher dimensional object into three (or fewer) dimensions in a way that preserves the properties we are interested in. This may sound disappointing, but it is still quite a powerful tool. A map of the world on a sheet of paper, for example, can be very useful in spite of the distortions it introduces. And each of the photos you have posted is a projection on to 2 dimensions of a 3-dimensional scene, but still gives us all a good idea of what you saw. Sometimes this process of projection itself gives us new insights. If you take a photo of a railway track, for example, there is a point in the plane of the photo where the two long lines meet, but no point in the real world corresponding with it. By adding such imaginary points "at infinity" to 3-dimensional space, we can make a lot of problems become much easier to solve. That is the start of Projective Geometry. |
[QUOTE=Nick;497688]Another good question! For 4 dimensions, we can use time as the extra one.
For example, to visualize a 4-dimensional cone, start with any 3-dimensional object and imagine it shrinking to a point. Apart from that, all we can do is map the higher dimensional object into three (or fewer) dimensions in a way that preserves the properties we are interested in. This may sound disappointing, but it is still quite a powerful tool. A map of the world on a sheet of paper, for example, can be very useful in spite of the distortions it introduces. And each of the photos you have posted is a projection on to 2 dimensions of a 3-dimensional scene, but still gives us all a good idea of what you saw. Sometimes this process of projection itself gives us new insights. If you take a photo of a railway track, for example, there is a point in the plane of the photo where the two long lines meet, but no point in the real world corresponding with it. By adding such imaginary points "at infinity" to 3-dimensional space, we can make a lot of problems become much easier to solve. That is the start of Projective Geometry.[/QUOTE] Now I'm even more confused :max: Before I saw the graphic I thought I had a basic idea of how a 4 dimensional cube worked, but the projection looks much different than what I thought... I'm having trouble with the [C]all[/C] function in Haskell. [URL="https://www.codewars.com/kata/detect-pangram/"]Detect Pangram[/URL] would have been much easier if I could figure out how it works, but it makes no sense (and the Hoogle description tells me nothing :sad:): [CODE]module Pangram where import Data.Char isPangram :: String -> Bool isPangram str = if any (==False) (map (`elem` (map toLower str)) ['a'..'z']) then False else True[/CODE] It took me a while to figure out how to use [C]elem[/C] with multiple arguments, but infix notation jumped in. I can understand how [C]any[/C] works, just not [C]all[/C]... |
[QUOTE=jvang;497731]I'm having trouble with the [C]all[/C] function in Haskell. [URL="https://www.codewars.com/kata/detect-pangram/"]Detect Pangram[/URL] would have been much easier if I could figure out how it works, but it makes no sense (and the Hoogle description tells me nothing :sad:)[/QUOTE]
Here's an example of all in Haskell: [CODE] Prelude> all (>5) [6,9,42,7] True Prelude> all (>5) [6,9,2,1] False[/CODE]The numbers 6,9,42 and 7 are all greater than 5 so it returns True. The numbers 6,9,2 and 1 are not all greater than 5 so it returns False. Or was that not what you meant? |
2 Attachment(s)
[QUOTE=Nick;497753]The numbers 6,9,42 and 7 are all greater than 5 so it returns True.
The numbers 6,9,2 and 1 are not all greater than 5 so it returns False. Or was that not what you meant?[/QUOTE] I think I've had the predicate formatted wrong... :buddy: My dad was fascinated when I told him about how photons carry the energy of radio waves, so today's topic is photons and electromagnetic radiation: [SIZE="1"]Or my likely inaccurate interpretation of what I think they are...[/SIZE] Photons are the quanta for electromagnetic radiation. Quantization is the property of a force in which there is a minimum amount of interaction possible, and, at the smallest levels, it is measurable in discrete integer amounts. This is important in physics as well as chemistry; in my chemistry class we learned that energy is quantized, denoted by the Planck constant [$]h[/$]. The energy of each photon is quantized by [$]h[/$]. Electromagnetic (EM) radiation refers to the waves of electromagnetic fields that carry energy, measured in joules. The wavelengths of such radiation is illustrated on the EM spectrum, and include (in order from longest to shortest) radio waves, microwaves, infrared, visible light, ultraviolet, X-rays, and gamma rays (graphic below). In the classical sense, an EM wave consists of two major parts: an electric field and a magnetic one. These fields oscillate in sync and perpendicular to each other (second graphic). [ATTACH]19131[/ATTACH] [ATTACH]19132[/ATTACH] In quantum mechanics/electrodynamics, EM radiation is instead represented by photons, which exhibit wave-particle duality. This means that photons have properties of both a wave and a particle. For example, each individual particle has a measurable momentum [I]or[/I] position, but can be refracted by a lens like a wave. Thus, some properties of photons can be described as if they were a wave, such as their velocity, frequency, and wavelength. As far as velocity, EM radiation propagates through a vacuum at the speed of light, [$]c[/$]. In other mediums, this speed differs (though it is always less than [$]c[/$]). Anything beyond this is really confusing; I still don't really get how wave-particle duality is a thing :unsure: But I think is stems from a likely misconception that I have with waves in general, because it's conceptually weird for me to think that the wavelength of a photon is larger than the photon. And how a photon has any momentum/energy at all while having 0 rest mass... :bangheadonwall: |
Finished a kata I got stuck on a while back, [URL="https://www.codewars.com/kata/dubstep/"]Dubstep[/URL]. I found a convenient new function, [C]splitOn[/C]:
[CODE]module Codewars.Kata.Dubstep where import Data.List.Split songDecoder :: String -> String songDecoder x = unwords (filter (/="") (splitOn "WUB" x))[/CODE] [C]splitOn[/C] takes an argument and a list, and returns a list of lists. The output does not include the sublist being split upon, starting from the left of a valid sublist. For instance, [C]splitOn ".." "a..b...c....d.."[/C] returns [C]["a","b",".c","","d",""][/C]. The whole [C]Data.List.Split[/C] module has a bunch of useful list splitting functions, such as [C]splitOneOf[/C], which splits based on any single-character sublist of the given elements. Another one I'm pretty sure I've seen is [C]chunksOf[/C], which returns a list of lists of the given length, with the last element potentially being shorter if [C]length xs `mod` n /= 0[/C]. |
[QUOTE=jvang;497967]Anything beyond this is really confusing; I still don't really get how wave-particle duality is a thing :unsure: But I think is stems from a likely misconception that I have with waves in general, because it's conceptually weird for me to think that the wavelength of a photon is larger than the photon. And how a photon has any momentum/energy at all while having 0 rest mass... :bangheadonwall:[/QUOTE]You are in extremely good company. Hardly anyone can get their head around wave/particle duality other than through a mathematical formulism. Almost all the others are deluded. Theoretical physicists, up to and including Nobel laureate status, are in this position. The most often adopted resolution, AFAICT, is to accept that that is how the universe behaves whether or not it makes sense at some level.
The photon energy conundrum is perhaps resolved by the experimental evidence that the photon is never found at rest but invariably has energy. as measured by many many experiments. Other experiments show that a photon has momentum. As above, accept that that is how the universe behaves. Why do you think that the universe must be comprehensible according to the rules of common sense? Perhaps common sense is seriously wrong. That's my view, anyway. |
[QUOTE=jvang;497967]But I think is stems from a likely misconception that I have with waves in general, because it's conceptually weird for me to think that the wavelength of a photon is larger than the photon[/QUOTE]It might help if you search on the term "wave packet", though [url]https://en.wikipedia.org/wiki/Wave_packet[/url] is very heavy going.
Actually, every particle can be smaller than its wavelength! The resolution of this paradox is that the measured size of the particle, which corresponds to its wavelength, depends on the energy of the interaction at which you measure the size. Bounce something off a particle at low energies and you will measure a large size.. Use a higher energy and. by and large, you will find that the something has a smaller size. Some particles, such as electrons, muons, quarks and photons show no minimum measurable size. Note: this is not to say that they are points, only that we can't rule out the possibility. Some particles, such as protons, molecules and mice, can be shown to have a measurable size by using interactions of high enough energy. A GeV is enough to determine that protons are not points; a keV for molecules and one eV (that is visible light) for mice. A low enough energy photon could not distinguish a mouse from a point particle from its corresponding waveform. |
I think I've used [C]sortOn[/C] before, but it's helpful again. It applies a function to a list, sorts it, and reverts the function while keeping the sorted order.
[CODE]module Alphabetized.Kata (alphabetized) where import Data.Char import Data.List alphabetized :: String -> String alphabetized xs = sortOn toLower (filter isAlpha xs)[/CODE] I also had to use [C]isAlpha[/C] to filter out non-alphabetic characters. I used [C]concat . words[/C] at first, but it was pointless :sad: |
| All times are UTC. The time now is 10:06. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.