Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hi monks,

I was about to solve this problem using perl5, but while I was writing I realized there were at least two features in Perl6 that could be usefull if I want to spare a few lines of code.

So I wrote my solution in Perl6, and it passed on first try. Execution took a bit of time (about a minute or so) but it was well in the five minutes delay so that was fine. It was pretty easy. About ten lines of code.

On rosalind, once you solved a problem you can join a discussion thread where you can post your solution and see other people's ones, with comments. So I did that as I do usually.

And then I was intrigued because most people were complaining about how this problem was a pain in the xxx because of the floating point approximations.

At first I did not understand. But then, thinking about it, I realised that this problem indeed requires computing a lot of differences between decimal numbers and then comparing those differences. It sure is the kind of things that creates issues when using floating point numbers.

Yet I had totally failed to notice that this problem could occur. So how was it possible that my code worked?

Well, I then remember that Perl6 treats decimals as rationals, not floating points, and I guessed this was the answer.

I also remember that I once wondered if that was not a bit of a luxury to do that in Perl6. But now I'm totally convinced it is a good idea. A decimal should really be treated as a rational, unless explicitly casted otherwise.

I won't say that's the first time Perl6 impresses me. But hey, kind of.

In reply to How Perl6 treating decimals as rationals helped me solve a problem by grondilu

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    thezip vouches for that, but then forgets what he was vouching for...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (10)
    As of 2018-06-21 16:48 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (118 votes). Check out past polls.