This code should be readable enough to give you an idea what is happening and how to change it.
my $board-depth = 8;
my $board-width = 8;
my $squares = $board-depth * $board-width;
my @grains-per-square = ( 1 .. $squares ).map({ 2 ** ($_-1) })
say [+] @grains-per-square;
Which if you read Perl6 says number of squares, and in each one put 2^n-1 grains, then add them all up.Hint: `[]` is the reduction metaoperator, it lets you specify an operator to use when reducing a list. [+] means "add it up".
It finishes basically instantly, and while Perl6 has gotten a lot faster, it is not a fast language (yet?). So no need to optimize this.
I mean you write the code and then marketing will have a poorly specified variation like "double only the odd ones".
If you implemented this as `2^64-1` then you are starting from scratch.
For the above the map only needs a tweak:
map({ $_ %% 2 ?? $_ :: 2**(n-1) })
Or whatever it turns out that marketing meant.In the article, I didn't see informational intentionality, I saw premature optimization and obfuscation.
As to mixing variable names up with subtraction, you put spaces in your math formulas? someVar-anotherVar*thirdVar is pretty unpleasant to read, so not being able to do that is not much of a problem.
Perl6's relationship to sigils (like $) is a bit weird at first, but is very consistent and "fits lightly under your hands" in practice. Suffice to say, sigils indicate context and constrain the type of data you can put in a container. If you want to refer directly to a value, you use a sigil-less variable:
my \the-great-answer = 42;
See the docs on varibles if you want more information: https://docs.perl6.org/language/variables- Where can I find a set of practice problems which will force me to really engage with learning a new language?
- Given a specific problem, what does the solution look like in various langauges?
- Given a specific language, what do the solutions to a variety of problems look like?
Unfortunately, exercism's web interface is really only set up to cater to the first of those.
So I made an couple of indexes to solve for the other two:
https://gist.github.com/cellularmitosis/ae76bb09973f55418d97...
https://gist.github.com/cellularmitosis/2aec8d88a76771452f35...
https://github.com/exercism/exercism/issues/4333
(that's my work account)
With the new interface, I need to wait for official mentors, and while some have been way above and beyond, the dearth of reactions from anyone for long periods can be a real downer. I preferred the semi-OK amateur mentorship over the wildly inconsistent/non-existent mentor assistance.
There was one mentor that I would have happily paid directly to keep giving me feedback, but there was no mechanism in exercism for me to make that offer, even if exercism took a cut.
Also in the old interface, the community solutions were sorted by recency, so it was easier to interact with other fellow learners, and the new interface is not that, I'm not sure what the order is, but it's of no use for me to comment on a piece of code submitted two years ago.
Just to chime in with data here, there is 5x more feedback per day on the new system than there was with the old system. Depending on the track, you'll get feedback in 3hrs to 7days (very occasionally longer), so it is definitely inconsistent in that respect, but you will get feedback. In the old system, you'd get feedback at all in under 10% of submissions.
> There was one mentor that I would have happily paid directly to keep giving me feedback, but there was no mechanism in exercism for me to make that offer, even if exercism took a cut.
In the future we'll be adding the ability to "pair" mentor/mentees who have both rated the other highly, so this will sort-of happen for you.
Also, clicking "explore languages" at the bottom of the blog does nothing.
I would guess the design choice on the front page change on reloads to try to surface something potentially interesting to everyone, but I am not affiliated with them/have no additional insight. I can see how it would be frustrating.
They must have removed the link you are referencing, because I don't see it now. Clicking it from the front page works (probably because it is an anchor link).
Feel free to open an issue at https://github.com/exercism/exercism for the random language order. If there's consensus then it's an easy one to change.
I'd be glad to pay per puzzle or a subscription to get faster feedback.
Please, exercism. Take my money.
So in my opinion, the moral of the story isn't simply "design with intent", it's "get your code reviewed".
In a perfect world, readability would be one criteria during reviews, unfortunately it is often overlooked.
But I don't think the point is well made with a contrived whiteboard-interview style problem.
let 2**64==0