16
\$\begingroup\$

A paragraph of text has numbers and alphabetic letters mixed. Your task is to separate the numbers to the left side and the alphabetic letters to the right side in the same order of each line.

Rules:

  1. Numbers are plain integers; so no decimal point, and no negative/positive signs.
  2. Numbers may or may not be contiguous, but whatever the case may be, they have to be pushed to left side in the same order.
  3. Numbers may occur in between words.
  4. The text contains only ASCII alphabetic letters and numbers, along with spaces, underscores, commas and dots.
  5. The one who does this with minimum keystrokes (like vim macros) or least amount of bytes in case of scripting is the winner.

Example Text:

A word can have any number of text like 433884,
but all the numb89ers has to be moved left side 
but alph6abetical va9lues has to be pas46ted on right side.
The text might con4tain chara29cters s2huffled like hlep or dfeintino or even
meaningless1 words co43mbined togeth81er.

Expected output:

433884A word can have any number of text like ,
89but all the numbers has to be moved left side 
6946but alphabetical values has to be pasted on right side.
4292The text might contain characters shuffled like hlep or dfeintino or even
14381meaningless words combined together.
\$\endgroup\$
15
  • 4
    \$\begingroup\$ @SibiCoder Welcome aboard then! You might want to use the sandbox next time. It's used for posting challenges before doing it here. That way you can get feedback from other users and improve the challenge \$\endgroup\$
    – Luis Mendo
    Commented May 25, 2016 at 11:15
  • 1
    \$\begingroup\$ Using alphabet to mean letter is, I believe, a distinctive of Indian English. \$\endgroup\$
    – TRiG
    Commented May 25, 2016 at 14:35
  • 2
    \$\begingroup\$ @AstroDan Both are allowed by default. \$\endgroup\$
    – Adnan
    Commented May 25, 2016 at 15:26
  • 2
    \$\begingroup\$ Seems pretty clear now. @close-voters - do you think you can retract your votes now? \$\endgroup\$ Commented May 25, 2016 at 17:44
  • 1
    \$\begingroup\$ Fixed the first test case, since it was most likely nothing more than a typo. I am voting to reopen this post. \$\endgroup\$ Commented May 26, 2016 at 8:44

33 Answers 33

1
2
0
\$\begingroup\$

Jelly, 10 bytes

Ỵðf;ḟµ€ØDY

Try it online!

\$\endgroup\$
0
\$\begingroup\$

K4, 21 bytes

Solution:

{x(&a),&~a:x in .Q.n}

Example:

q)k){x(&a),&~a:x in .Q.n}"The text might con4tain chara29cters s2huffled like hlep or dfeintino or even"
"4292The text might contain characters shuffled like hlep or dfeintino or even"

Explanation:

{x(&a),&~a:x in .Q.n} / the solution
{                   } / lambda function, implicit arg x
                .Q.n  / list "0123456789"
           x in       / true/false for each character of x
         a:           / save as variable a
        ~             / negate (so non numerics)
       &              / indices where true
      ,               / joined with
  (&a)                / indices where true
 x                    / index into x at these indices

Bonus:

23 byte implementation in K (oK):

{x(&a),&~a:x in 48+!10}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

ReRegex, 25 bytes

([^\n\d])(\d)/$2$1/#input

Try it online!

\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.