Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

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

I want(ed) to write a function that would expand a bit field (unsigned integer) into a list of powers of two, so f(0) = (), f(4) = (4), f(13) = (1,4,8), f(31) = (1,2,4,8,16)... I thought storing options in a single field and then having a separate table for definitions was a good idea. I have since realized that I should use object-oriented relational databases the way they are designed to be used, but I still think it's an interesting exerc ise. Anyway, I came up with a 5-minute-one-liner solution and was going to post a SoPW, but after I realized I wasn't going to use it anyway and since it was a one-liner I decided to turn it into a golf meditation. I'm a pretty lousy golfer and I never came up with challenges before but I'm curious how short someone else can make this. I originally wrote it as an anonymous function, so a valid solution should start with sub{ and end with } and return a list.

My original 5-minute solution


$,=qq.\n.;print q.\/\/____\/.,q./\ \ / / \\.,q.    /_/__.,q..
Happy, sober, smart: pick two.

In reply to mini-golf: convert integer into list of powers of two by xyzzy

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2021-05-17 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (170 votes). Check out past polls.

    Notices?