7 ms·
With friends like these
- Sniffnoy 7y agoI'm surprised this article doesn't optimize a little further. If you want to compute σ(n), and you can prime factor n, there's no need to go determining all the divisors of n and then adding them up. The σ function is multiplicative, i.e., one has σ(nm)=σ(n)σ(m) when (n,m)=1. So if you've factored n = p_1^a_1 * ... * p_k^a_k, it suffices to compute σ(p_i^a_i) for each i and then multiply them together. Meanwhile, while computing σ(p^a) can be done by summing, it can be done even more simply by noting that this is a geometric series and so sums to (p^(a+1)-1)/(p-1). Edit: Actually, not sure how this latter way compares to just doing Horner. Probably about the same, I imagine. I guess Horner would be the right way to do it if division is expensive for some reason.
- saagarjha 7y ago> which we extract and store in an appropriate Unicode-named variable: pₗpₘpₙ. Which my phone unfortunately doesn’t render :(
- TheRealPomax 7y agoTime to hack some more fonts into your phone.
- DonHopkins 7y agoThis is Perl, remember. It's rendering just fine -- it's not your phone: I see the same ₙ boxes in Chrome on my MacBook Pro. He meant to use those ₙ boxes on purpose to show off how unintelligible he could make the code look.
- dingo_bat 7y agoLooks perfectly fine on Firefox. Maybe you need an upgrade :)
- userbinator 7y agoWith all the special characters in source code and attempts at a terse syntax for array-ish operations, it looks like Perl is trying to become APL. But statements like return unique flat small-divisors, big-divisors; are ambiguous even to a human, because '-' is usually used for subtraction, but I guess Perl's parser somehow manages to disambiguate (between a single variable named 'small-divisors', and the subtraction of 'small' and 'divisor')?
- masak 7y agoYes. Somewhat simplified, hyphens inside of identifiers are allowed and not taken to mean infix minus. I remember when this was switched on. Larry Wall tried it out on the entire spectest suite, and nothing broke (or at most one random thing broke), because basically people already put whitespace around their infix operators. Incidentally, apostrophes are also allowed inside Perl 6 identifiers. Personally, I used to conservatively use underscore (`_`) in my Perl 6 identifiers for some years. Then I got used to hyphens, and it's hard to go back.
- faitswulff 7y ago> I remember when this was switched on. Larry Wall tried it out on the entire spectest suite, and nothing broke (or at most one random thing broke), because basically people already put whitespace around their infix operators. Larry Wall seems hilariously easy-going for a language BDFL!
- sp332 7y agoHe's a linguist and a self-professed post-modernist. He's interested in how people actually use language, and has very little interest in dictating language purity.
- DonHopkins 7y agoLarry Wall is to Linguistics as Deepak Chopra is to Quantum Physics: https://en.wikipedia.org/wiki/Larry_Wall https://en.wikipedia.org/wiki/Larry_Wall "While in graduate school at the University of California, Berkeley, Wall and his wife were studying linguistics with the intention of finding an unwritten language, perhaps in Africa, and creating a writing system for it. They would then use this new writing system to translate various texts into the language, among them the Bible. Due to health reasons these plans were cancelled, and they remained in the United States, where Larry instead joined the NASA Jet Propulsion Laboratory after he finished graduate school." https://en.wikipedia.org/wiki/Cultural_imperialism https://en.wikipedia.org/wiki/Cultural_imperialism https://en.wikipedia.org/wiki/Scramble_for_Africa https://en.wikipedia.org/wiki/Scramble_for_Africa https://en.wikipedia.org/wiki/Civilizing_mission https://en.wikipedia.org/wiki/Civilizing_mission https://rationalwiki.org/wiki/Quantum_woo https://rationalwiki.org/wiki/Quantum_woo
- foobar_ 7y agoThe article can't even render fonts correctly. Beta since the last 10 years. Language design is 1 step forward 2 steps back. That's the problem with Perl. Overpromise and underdelivers. Javascript does everything that Perl6 does.
- minitech 7y ago> The article can't even render fonts correctly. The article, or what you’re using to view it? Falls back fine for me.
- jsjohnst 7y agoRather tangential, but: > Perl 6 aims to let us express ourselves in whichever notation we find most convenient, comfortable, and comprehensible. Is the reason I’ve always hated Perl once I started using it in a team context vs personal projects. The diversity of code styles even on your own Perl code over the years changes more than other languages I’ve used, let alone taking into account lots of other developers too. <3 Damian’s articles and talks though, so this isn’t meant as a detractor on him.