Make a Word Icicle

45

5

Due to technical limitations of Stack Exchange, the title is rendered incorrectly. The correct title for this challenge is

Make a

Word Icicle!
Word Icicle 
Word  cicle 
 ord  cicle 
 ord   icle 
 ord   i le 
 or    i le 
 or    i l  
 or      l  
 or         
  r         

Today's challenge is to make icicles out of the input word. Given a string of entirely printable ASCII, and at least 2 non-space characters, perform the following steps:

  1. Print the current state of the string.

  2. Replace the lexically smallest character (other than spaces) with a space. If there is a tie, replace the leftmost character.

  3. Repeat on consecutive lines until the string contains only 1 non-space character.

This creates the effect that the input string looks like it's melting...

I'm Melting!!!
I'm Melting !!
I'm Melting  !
I'm Melting   
I m Melting     
  m Melting   
  m  elting   
  m   lting   
  m   ltin    
  m   lt n    
  m    t n    
       t n    
       t      

Rules

  • After a couple iterations, your output will almost surely have trailing spaces on each line. If you choose to truncate these, that is allowed.

  • You may have one trailing empty line, but not more.

  • Remember that the input may contain several spaces, but these are all effectively skipped. For example, the input a a should give

    a      a
           a
    
  • You may take input as a list of strings if you want. For output, you may return or print a list of strings, a single string with newlines, or char matrix/2D array. Generally, I prefer permissive IO formats, so other formats are most likely allowed as long as they are consistent and clearly correspond to the right output. If in doubt, feel free to ask. As usual, full programs or functions are allowed.

  • Remember, this is a contest to make the shortest answer in any language! If you choose to answer in Java, try to make the shortest Java answer (in bytes) that you can.

Test cases

Hello World! -->

Hello World!
Hello World 
 ello World 
 ello  orld 
 ello  orl  
  llo  orl  
   lo  orl  
    o  orl  
    o  or   
       or   
        r   


AbCdEfGhIjKlMnOpQrStUvWxYz -->

AbCdEfGhIjKlMnOpQrStUvWxYz
 bCdEfGhIjKlMnOpQrStUvWxYz
 b dEfGhIjKlMnOpQrStUvWxYz
 b d fGhIjKlMnOpQrStUvWxYz
 b d f hIjKlMnOpQrStUvWxYz
 b d f h jKlMnOpQrStUvWxYz
 b d f h j lMnOpQrStUvWxYz
 b d f h j l nOpQrStUvWxYz
 b d f h j l n pQrStUvWxYz
 b d f h j l n p rStUvWxYz
 b d f h j l n p r tUvWxYz
 b d f h j l n p r t vWxYz
 b d f h j l n p r t v xYz
 b d f h j l n p r t v x z
   d f h j l n p r t v x z
     f h j l n p r t v x z
       h j l n p r t v x z
         j l n p r t v x z
           l n p r t v x z
             n p r t v x z
               p r t v x z
                 r t v x z
                   t v x z
                     v x z
                       x z
                         z


PPCG is da BEST --> 

PPCG is da BEST
PPCG is da  EST
PP G is da  EST
PP G is da   ST
PP   is da   ST
 P   is da   ST
     is da   ST
     is da    T
     is da     
     is d      
     is        
      s        


({({})({}[()])}{}) -->

({({})({}[()])}{})
 {({})({}[()])}{})
 { {})({}[()])}{})
 { {}) {}[()])}{})
 { {}) {}[ )])}{})
 { {}  {}[ )])}{})
 { {}  {}[  ])}{})
 { {}  {}[  ] }{})
 { {}  {}[  ] }{} 
 { {}  {}   ] }{} 
 { {}  {}     }{} 
   {}  {}     }{} 
    }  {}     }{} 
    }   }     }{} 
    }   }     } } 
        }     } } 
              } } 
                } 

James

Posted 2018-04-13T18:00:03.987

Reputation: 54 537

1"lexically smallest" means by code point? – Giuseppe – 2018-04-13T18:03:13.960

1@Giuseppe Yes, the character with the smallest ASCII code point (other than space obviously) – James – 2018-04-13T18:04:12.923

2Reminds me of another challenge where we had to, I think, vertically repeat a character by its index in the alphabet. – Shaggy – 2018-04-13T18:23:23.030

6

@Shaggy You're probably thinking of Make some Alphabet Rain.

– Rainbolt – 2018-04-13T20:11:58.780

That's the very one, @Rainbolt. – Shaggy – 2018-04-13T20:14:23.257

Also somewhat related – FryAmTheEggman – 2018-04-14T04:33:28.030

2That reference to MediaWiki though... – Erik the Outgolfer – 2018-04-14T12:56:32.273

I am assuming it would be, but just to make sure: is an input string starting with a space valid? – Jonathan Frech – 2018-04-14T18:36:40.807

@Jonathan Yes, the input may contain leading/trailing spaces. – James – 2018-04-14T18:42:00.840

Kind of related – Esolanging Fruit – 2018-04-22T09:18:02.660

Answers

8

Python 2, 71 70 bytes

-1 byte thanks to ovs

x=input()
while x.strip():print x;r=x.replace;x=r(min(r(*' ~')),' ',1)

Try it online!

Rod

Posted 2018-04-13T18:00:03.987

Reputation: 17 588

8

Retina, 28 bytes

/\S/+¶<~(O`.
0L$`\S
0`$\$&¶ 

Try it online!Explanation:

/\S/+

Repeat while the input value isn't blank.

¶<

Print the current value.

~(

Execute the rest of the script on the value. Then, execute the result of that script as a script on the value.

O`.

Sort the characters into order.

0L$`\S
0`$\$&¶ 

Select the first nonblank character and output a Retina program that replaces the first literal ($\) occurrence of that character ($&) with a space (trailing space in original code).

Neil

Posted 2018-04-13T18:00:03.987

Reputation: 95 035

6

APL (Dyalog Unicode), 18 11 bytes

∪∘↓∘⍉⍋∘⍋⍴⌸⊢

Try it online!

uses ⎕io←1; returns an array of strings (vector of character vectors)

ngn

Posted 2018-04-13T18:00:03.987

Reputation: 11 449

Is the necessary? – user41805 – 2018-04-13T20:16:19.257

@Cowsquack yes, otherwise the first few rows of the output could be identical – ngn – 2018-04-13T20:19:22.080

@Cowsquack thanks, I didn't notice that – ngn – 2018-04-13T20:26:36.583

fortunately, fixing this led to a shorter solution :) – ngn – 2018-04-13T21:43:40.560

Nice one, really clever usage of ⍋∘⍋ :) – user41805 – 2018-04-14T07:14:46.547

6

05AB1E, 9 bytes

ðм{v=yð.;

Try it online!

Explanation

ð      # Push space
м      # Implicit input. Remove spaces
{      # Sort. Gives string of sorted, non-space chars
v      # For each char in that string
  =    #   Print latest string, without popping. The first time it prints the input
  y    #   Push current char
  ð    #   Push space
  .;   #   Replace first occurrence of current char by space
       # Implicitly end for-each loop

Luis Mendo

Posted 2018-04-13T18:00:03.987

Reputation: 87 464

1{ðKv=yð.; was mine, nice one. – Magic Octopus Urn – 2018-05-01T17:28:21.247

@MagicOctopusUrn Heh, pretty similar – Luis Mendo – 2018-05-01T17:52:55.543

1@MagicOctopusUrn Actually, it would still be the same 9 bytes in the latest 05AB1E version.. : replaces all characters instead of .; which replaces the first (i.e. see what your 7-byter does with the ! in the test case). Also, the challenge explicitly states excluding spaces, so your 7-byter wouldn't work for input with multiple spaces. PS: Nice answer, Luis! +1 from me. :) – Kevin Cruijssen – 2018-10-22T14:50:36.010

1@KevinCruijssen leave it to me to forget why I had to use .; in the first place. I literally remember struggling with that on May 1st earlier this year now that you mention it. – Magic Octopus Urn – 2018-10-22T14:57:17.327

Thanks both for your comments! I am not familiar with 05AB1E's recent features... – Luis Mendo – 2018-10-22T15:01:29.383

1@LuisMendo Well, none of the commands you've used in this answer have changed in the Elixir rewrite of 05AB1E. :) – Kevin Cruijssen – 2018-10-22T15:17:51.507

5

Pyth, 17 14 13 bytes

V-SQdQ=XQxQNd

Try it here

V-SQdQ=XQxQNd
V-SQd              For each non-space character in the sorted input (Q)...
     Q             ... print the current value of Q...
      = Q          ... and set Q to itself...
         xQN       ... with the first instance of the character...
       X    d      ... replaced by a space.

user48543

Posted 2018-04-13T18:00:03.987

Reputation:

5

sed -rn, 142 143 bytes

:a
p
s/$/	ABCDEFGHIJKLMNOPQRSTUVWXYZ/
s	\w+$	!"#$%\&'()*+,-./0123456789:;<=>?@&[\\]^_`\L&{|}~	
:b
/(.).*	\1/!s/	./	/
tb
s/(.)(.*)	\1.*/ \2/
ta

Try it online!

(note: there are tabs in the program)

Since sed has no concept of lexicographical order, I had to hardcode the set of printable ASCII characters in and it takes up more than half the bytecount.

Using sed 4.2.2 will reduce bytecount by 2, since that allows for unnamed labels, Try it online!


-r enables extended regular expressions (golfier)

-n disables implicit printing of the pattern space at the end of the program

The pattern space starts with the input

:a label a, this is the main program loop

p print the pattern space (fancy name for the buffer)

now we append the set of printable ASCII characters (excluding the space)

s/$/ ABCDEFGHIJKLMNOPQRSTUVWXYZ/ append a tab, acting as the 1-byte delimiter, followed by the uppercase alphabet

s<tab> substitute (sed can take any character as the delimiter, in this case the tab is used to save a byte from escaping the /)

  • \w+$ the uppercase alphabet we just appended

  • <tab> with

  • !"#$%\&'()*+,-./0123456789:;<=>?@&[\\]^_\`\L&{|}~<tab> the rest of the characters, note that \L& is the lowercase version of the uppercase alphabet

:b label b, remove characters from the beginning set that are not present in input

/(.).* \1/! if the first character from the ASCII set is not in the input

  • s/ ./ / remove it

tb repeat b until the substitution fails

s/(.)(.*) \1.*/ \2/ replace the first character in the ASCII set present in the input with a space, and remove the ASCII set

ta recurse

user41805

Posted 2018-04-13T18:00:03.987

Reputation: 16 320

Non-greedy matching would have been really helpful here, but I was able to come up with something that fooled sed enough to save at least 4 bytes: Try it online!

– Neil – 2018-04-14T00:35:16.137

(Cows quack pointed out that I was only partly able to fool sed, as I remove identical characters in the wrong order.) – Neil – 2018-04-14T10:33:25.200

4

Ruby, 60 58 55 47 bytes

->a{[-a]+a.scan(/\S/).sort.map{|x|a[x]=' ';-a}}

Try it online!

Kirill L.

Posted 2018-04-13T18:00:03.987

Reputation: 6 693

You can swap in a-b=[' '] and a-b for a quick -2 bytes – benj2240 – 2018-04-13T19:09:15.903

Yeah, thanks for that, but now I've changed the approach a bit, so it is no longer used. – Kirill L. – 2018-04-13T21:04:44.533

I like the new approach! – benj2240 – 2018-04-13T21:41:30.047

4

R, 140 100 bytes

-40 bytes Thanks to Giuseppe !

function(x)for(i in any((z=utf8ToInt(x))<33):max(y<-rank(z,,"f"))){z[y==i]=32
cat(intToUtf8(z),"
")}

Try it online!

A solution using outer and Giuseppe's magic to work properly is longer at 104 bytes. Inspired by this answer.

function(x,z=utf8ToInt(x)-32)apply(t(outer(rank(z,,"f"),(2-(min(z)>0)):nchar(x),">=")*z+32),1,intToUtf8)

Try it online!

JayCe

Posted 2018-04-13T18:00:03.987

Reputation: 2 655

109 bytes taking input as a vector of chars – Giuseppe – 2018-05-01T22:07:56.137

1100 bytes taking input as a string! – Giuseppe – 2018-05-01T22:08:10.243

Still, a very nice answer; mine had ballooned to over 200 bytes since I didn't remember about rank! – Giuseppe – 2018-05-01T22:08:43.597

@Giuseppe Tell me about it - I first tried "order" for a result that was melting but not in the correct order! – JayCe – 2018-05-01T22:40:20.857

@Giuseppe and my attempt at using outer inspired by your post only managed to remove all spaces. TIO I'd love to see a working outer approach posted as a separate answer. Still working on it but it might not be that elegant.

– JayCe – 2018-05-01T23:52:21.533

oh, outer! You're almost there; I found a 91 byte solution with outer but I won't spoil it if you're still working on it. – Giuseppe – 2018-05-02T00:26:37.497

@Giuseppe Please post it I've given up :) – JayCe – 2018-05-02T00:36:28.273

Let us continue this discussion in chat.

– Giuseppe – 2018-05-02T00:41:25.587

3

Python 3, 71 bytes

f=lambda a:[*a.strip()]and[a]+f(a.replace(min(a.replace(*" ~"))," ",1))

Try it online!

-4 bytes thanks to ovs

HyperNeutrino

Posted 2018-04-13T18:00:03.987

Reputation: 26 575

Save 2 bytes using *bool({*a}-{" "}) instead of if{*a}-{" "}else[a] – RootTwo – 2018-04-13T20:54:31.677

@RootTwo wouldn't this result in a RecursionError? – ovs – 2018-04-13T21:11:58.323

@RootTwo if/else shortcuts but *bool doesn't, so yes, recursionerror like ovs said – HyperNeutrino – 2018-04-14T02:44:48.980

Of course you are correct. Because of a bug, my function recursed by calling your function so it appeared to work. – RootTwo – 2018-04-14T04:41:38.757

3

K (ngn/k), 26 24 bytes

{?(,x),x{x[y]:" ";x}\<x}

Try it online!

ngn

Posted 2018-04-13T18:00:03.987

Reputation: 11 449

Beautiful! My K attempt came in at 41: {.[x;(-1+#x)&x?_ci&/_ic x _dv" ";:;" "]}\ I'm wasting bytes converting to ints and back and making sure it doesn't go out of bounds. – uryga – 2018-05-02T01:34:18.157

@uryga Thanks. If I had implemented projections properly, {@[x;y;:;" "]} could have been @[;;:;" "]. Which version of k do you use? I'm not familiar with these: _ci _ic _dv. – ngn – 2018-05-02T12:16:37.873

I think it's 2.8-ish? I'm using the Kona interpreter which provides operators as builtins: char-of-int, int-of-char, delete-value. – uryga – 2018-05-02T12:19:05.007

3

Python 2, 70 69 66 64 bytes

def f(s):print s;S=set(s)-{' '};S and f(s.replace(min(S),' ',1))

Try it online!

Thx for 2 bytes from ovs via using S and f() instead of if S:f()

Chas Brown

Posted 2018-04-13T18:00:03.987

Reputation: 8 959

You're missing the ...If there is a tie, replace the leftmost character... rule, you can fix that with replace(min(...),' ',1) – Rod – 2018-04-13T19:55:50.077

@Rod: Ah! Got it... – Chas Brown – 2018-04-13T19:58:02.040

3

Perl 5 -n, 37 34 bytes

Dropped three bytes with help from @TonHospel

say&&s/\Q$a/ / while($a)=sort/\S/g

Try it online!

Xcali

Posted 2018-04-13T18:00:03.987

Reputation: 7 671

Ah, very nice, much nicer approach! I think you need the \Q though for the last test case.... I missed that the first times too! – Dom Hastings – 2018-04-14T05:25:13.577

You're right. Added it. – Xcali – 2018-04-14T05:47:53.977

Shorter: say&&s/\Q$a/ / while($a)=sort/\S/g. Also properly handles 0 – Ton Hospel – 2018-04-15T16:28:01.183

3

JavaScript, 67 66 65 bytes

Because I haven't golfed drunk in a while!

s=>[...t=s].sort().map(x=>x>` `?t+=`
${s=s.replace(x,` `)}`:0)&&t

Try it online

Thanks to DanielIndie for pointing out 4 redundant bytes that beer included!

Shaggy

Posted 2018-04-13T18:00:03.987

Reputation: 24 623

why do you specify y in the map? :P it can be made 67 – DanielIndie – 2018-04-14T08:17:17.650

@DanielIndie, because Beer! :D Thanks for pointing it out. – Shaggy – 2018-04-14T08:37:23.633

yes, i thought that would be the case :P – DanielIndie – 2018-04-14T08:45:52.163

3

Jelly, 8 bytes

ẋ"ỤỤ$z⁶Q

Try it online!

Idea

The basic idea is to build the columns of the desired output directly, instead of manipulating the string and returning all intermediate results.

We start by numerating the characters of the input string in the order they will be removed. For the moment, we'll pretend spaces will be removed as well.

tee ay oh
845139276

Now, we build the columns by repeating each character by its index in this enumeration.

tee ay oh
tee ay oh
tee ay oh
tee  y oh
t e  y oh
t    y oh
t    y o 
t    y   
     y   

All that's left is to remove duplicates, to account for the spaces.

Code

ẋ"ỤỤ$z⁶Q  Main link. Argument: s (string)

    $     Combine the two links to the left into a chain.
  Ụ       Grade up; sort the indices of s by their corresponding values.
          Let's call the result J.
          Grade up again, sorting the indices of J by the corr. values in J.
          This enumerates the positions of s as described before.
ẋ"        Repeat each character of s that many times.
     z⁶   Zip the resulting 2D array, filling missing characters with spaces.
       Q  Unique; deduplicate the array of rows.

Dennis

Posted 2018-04-13T18:00:03.987

Reputation: 196 637

2

JavaScript (Node.js), 80 65 bytes

x=>[...x].sort().map(c=>x=x.replace(c,' ',c>' '&&console.log(x)))

Try it online!

Didn't know replace take string as string, not regexp

l4m2

Posted 2018-04-13T18:00:03.987

Reputation: 5 985

2

Perl 5 with -nlF/\s|/, 39 bytes

@F=sort@F;say,s~\Q$F[$F++]~ ~ while/\S/

This might be pushing the boundaries of Perl's flags not being counted, if so I'll revert to the previous answer.

Try it online!

Dom Hastings

Posted 2018-04-13T18:00:03.987

Reputation: 16 415

Got it down to 35 bytes with only a -n flag: https://codegolf.stackexchange.com/questions/162161/make-a-word-icicle/162202#162202

– Xcali – 2018-04-13T22:00:16.570

2

gcc 32-bit, 66 65 bytes

char*p,i;f(a){for(i=32;i++;)for(p=a;*p;)*p==i?puts(a),*p=32:++p;}
main(){char s[]="3.1415926";f(s);}

Thanks for Jonathan Frech for -1 byte

l4m2

Posted 2018-04-13T18:00:03.987

Reputation: 5 985

*p==i?...:0; could probably be *p-i?0:...;. – Jonathan Frech – 2018-04-13T20:06:22.187

@JonathanFrech No, it's 1 byte longer (though *p-1||(...) is same length) – l4m2 – 2018-04-14T07:45:17.840

Sorry, did not recognize the importance to keep the comma expression together. However, this might be 65 bytes. I also do not know how f(a) compiles, as a should be of type char*, but I assume that has something to do with your 32-bit gcc usage.

– Jonathan Frech – 2018-04-14T17:20:08.787

@JonathanFrech I think char*p,i;f(long long a){for(i=31;++i;)for(p=a;*p;)*p==i?puts(a),*p=32:++p;} on tio(64bit) may explain how f(a) work – l4m2 – 2018-04-14T18:11:54.230

I am sorry, though I asked the OP about the challenge specifications and they said the input string may start with a space. Therefore my proposed solution is invalid (as such an input results in an infinite loop) and you should most likely revert back to your original solution. – Jonathan Frech – 2018-04-14T20:27:53.560

@JonathanFrech Your init value is wrong. Fixing it makes [start with a space] fine – l4m2 – 2018-04-14T20:54:00.290

You are right; I thought that for(i=32;i++;) would be equivalent to for(i=31;++i;), though did not realize that you use char overflow to end the for loop and that you start your second for loop with i==33. Glad to know that my golf works! – Jonathan Frech – 2018-04-14T21:00:53.210

2

C# (Visual C# Interactive Compiler), 129 bytes

var s=ReadLine();while(s.Any(c=>c!=32)){WriteLine(s);var i=s.IndexOf(s.Min(c=>c==32?(char)999:c));s=s.Remove(i,1).Insert(i," ");}

Try it online!

Pavel

Posted 2018-04-13T18:00:03.987

Reputation: 8 585

c!=32 can be c>32; c==32 can be c<33; and (char)999 can be '¡' (or any other character above the printable ASCII unicode range). – Kevin Cruijssen – 2018-04-16T07:00:28.277

Oh, and you can save two more bytes changing the while to for and placing the var s=ReadLine() and s=s.Remove(i,1).Insert(i," ") inside it (so the two semi-colons are no longer needed). – Kevin Cruijssen – 2018-04-16T07:07:20.267

2

Haskell, 67 bytes

12 bytes saved thanks to Laikoni

f s|(a,_:b)<-span(/=minimum(id=<<words s))s=putStrLn s>>f(a++' ':b)

Try it online!

This one terminates in an error

Haskell, 83 79 bytes

g(a,_:b)=a++' ':b
mapM_ putStrLn.(iterate$g.(span=<<(/=).minimum.concat.words))

Try it online!

This one terminates in an error

Haskell, 86 bytes

u=concat.words
g(a,_:b)=a++' ':b
(take.length.u)<*>(iterate$g.(span=<<(/=).minimum.u))

Try it online!

Haskell, 100 91 88 bytes

u=concat.words
f x|(a,_:b)<-span(/=minimum(u x))x=a++' ':b
(take.length.u)<*>(iterate f)

Try it online!

Post Rock Garf Hunter

Posted 2018-04-13T18:00:03.987

Reputation: 55 382

67 bytes: f s|(a,_:b)<-span(/=minimum(id=<<words s))s=putStrLn s>>f(a++' ':b) Try it online!

– Laikoni – 2018-04-13T22:15:15.423

@Laikoni Thanks! I was just on the verge of something like that and I fell asleep. However I don't think I would have come up with id=<< that's pretty clever – Post Rock Garf Hunter – 2018-04-13T23:32:34.457

2

K4, 28 20 18 bytes

Solution:

?x{x[y]:" ";x}\<x:

Example:

q)k)?x{x[y]:" ";x}\<x:"PPCG is da BEST"
"PPCG is da BEST"
"PPCG is da  EST"
"PP G is da  EST"
"PP G is da   ST"
"PP   is da   ST"
" P   is da   ST"
"     is da   ST"
"     is da    T"
"     is da     "
"     is d      "
"     is        "
"      s        "
"               "

Explanation:

It's the same thing as ngn is doing. Find indices that would result in an ascending list, overwrite them one-by-one with " ", then take the distinct to remove any duplicate lines:

?x{x[y]:" ";x}\<x: / the solution
                x: / save input as x
               <   / return indices that would result in ascending sort
 x{        ; }\    / two-line lambda with scan
        " "        / whitespace
       :           / assignment
   x[y]            / x at index y
            x      / return x
?                  / distinct

streetster

Posted 2018-04-13T18:00:03.987

Reputation: 3 635

2

Common Lisp, 240 228 224 bytes

(setf s(read))(defun f(x)(setf y(char-code(elt s x)))(if(= y 32)1e9 y))(loop for _ across s do(print s)do(setf s(replace s" ":start1(position(code-char(reduce #'min (loop for i from 0 below(length s)collect i):key #'f))s))))

Try it online!

This is my first time posting.
I'm in the process of learning lisp so I'm sure someone can think of something shorter than this.

JoshM

Posted 2018-04-13T18:00:03.987

Reputation: 379

1Welcome to the site! Good to see some common lisp! – Post Rock Garf Hunter – 2018-04-14T21:24:55.910

2

MATLAB, 74 bytes

This uses the 2-output form of the max() function to retrieve the smallest character and its index, having transformed the string to zero values in the spaces and 256-the character value for the printable characters.

s=input('s');x=1;while(x);disp(s);[x,y]=max((256-s).*(s~=' '));s(y)=' ';end

Richard

Posted 2018-04-13T18:00:03.987

Reputation: 21

1Welcome to PPCG! Nice work! – AJFaraday – 2018-04-16T12:58:46.450

1

APL (Dyalog Unicode), 39 bytesSBCS

{⎕←⍵⋄×≢⍵∩g←' '~⍨⎕UCS⍳256:∇' '@(⊃g⍋⍵)⊢⍵}

Try it online!

Dfn.

How?

{⎕←⍵⋄×≢⍵∩g←' '~⍨⎕UCS⍳256:∇' '@(⊃g⍋⍵)⊢⍵} ⍝ Main function, argument ⍵
 ⎕←⍵⋄                                    ⍝ Print ⍵
         g←' '~⍨⎕UCS⍳256                 ⍝ Assign to g every Unicode character except space
     ×≢⍵∩                :               ⍝ If ⍵∩g is not empty
                          ∇              ⍝ Recursively call the function with argument:
                           ' '@       ⍵  ⍝ Space at
                               (⊃g⍋⍵)    ⍝ The first (⊃) element in ⍵ graded up (⍋) with g
                                         ⍝ The dyadic grade up function will index ⍵ according
                                         ⍝ to its left argument, in this case g.

J. Sallé

Posted 2018-04-13T18:00:03.987

Reputation: 3 233

1

V, 27 bytes

>>ò2Ùúú^lDhrfDj|@"r kdòdj<H

Try it online!

Hexdump:

00000000: 3e3e f232 d9fa fa5e 6c44 6872 6644 6a7c  >>.2...^lDhrfDj|
00000010: 4022 7220 6b64 f264 6a3c 48              @"r kd.dj<H

James

Posted 2018-04-13T18:00:03.987

Reputation: 54 537

1

PowerShell, 103 99 bytes

param($a)2..$a.length|%{($x=$a);[regex]$p=""+([char[]]$a-ne' '|sort)[0];$a=($p.replace($x," ", 1))}

Try it online!

Takes input as a string into $a. We then loop from 2 to $a.length (i.e., the appropriate number of vertical times necessary to remove all but one character). Each iteration, we output the current string and conveniently saved into $x at the same time. We then construct a new [regex] object, $pattern consisting of the remaining characters in $a that are -notequal to space, sorted, then the 0th one thereof.

We then set $a equal to a new string of the regex object with the .Replace method to replace in the string $x, the $pattern, with a space " ", but only the 1st match. Yeah, this syntax is weird.

The strings are left on the pipeline and implicit Write-Output gives us a newline between them for free, plus one trailing newline.

AdmBorkBork

Posted 2018-04-13T18:00:03.987

Reputation: 41 581

1

Perl 6, 42 37 bytes

{$_,{S/$(.comb(/\S/).min)/ /}...*eq*}

Try it online!

nwellnhof

Posted 2018-04-13T18:00:03.987

Reputation: 10 037

1

Java (JDK 10), 140 bytes

s->{for(int m=1,i;m>0;s=s.substring(0,i=s.indexOf(m=s.chars().filter(c->c>32).min().orElse(0)))+" "+s.substring(i+1))System.out.println(s);}

Try it online!

Technically there's a blank line, but it's not empty.

Olivier Grégoire

Posted 2018-04-13T18:00:03.987

Reputation: 10 647

1

Japt, 32 18 bytes

Saved 14 bytes thanks to Shaggy!

rS ¬£=hSUbZn gYÃiN

Try it online!

Oliver

Posted 2018-04-13T18:00:03.987

Reputation: 7 160

Save a byte by returning an array of lines: https://ethproductions.github.io/japt/?v=1.4.5&code=rMulUz9TOlU9ZEZuIGdFIFM=&input=IkhlbGxvIFdvcmxkISIKLVI=

– Shaggy – 2018-04-13T20:49:20.423

22 bytes. Will try a port of my JS solution soon, see how that works out. – Shaggy – 2018-04-14T08:46:42.733

1

Got it down to 18 bytes.

– Shaggy – 2018-04-14T09:44:52.900

1

MATL, 17 16 bytes

tSXz"tOy@=f1)(]x

Try it online! Or verify all test cases.

Explanation

t       % Implicit input. Duplicate
S       % Sort
Xz      % Remove spaces
"       % For each char in that string
  t     %   Duplicate last result. This is the most recent string obtained
        %   from replacing chars by spaces in the input
  O     %   Push 0
  y     %   Duplicate from below
  @     %   Push current char
  =     %   Equals? (element-wise) Gives 1 for occurrences of current char
        %   in the most recent string, 0 otherwise
  f     %   Indices of nonzeros
  1)    %   Get the first entry
  (     %   Write 0 at that position. Char 0 will be displayed as space
]       % End
x       % Delete last result, which consists only of space / char zero

Luis Mendo

Posted 2018-04-13T18:00:03.987

Reputation: 87 464

1

Stax, 9 bytes

ü¡%/"=πbΓ

Run and debug it

This is the same algorithm as Luis' 05AB1E solution

recursive

Posted 2018-04-13T18:00:03.987

Reputation: 8 616

1

Excel VBA, 167 bytes

An anonymous VBE immediate window function that takes input from range [A1] and outputs to the VBE immediate window.

s="Code(Mid(A$1,Row(),1))":[B1].Resize([Len(A1)])="=If("&s &"=32,1E3,"&s &")":For i=1To[Len(A1)-CountIf(B:B,1E3)]:?[A1]:[A1]=[Substitute(A1,Char(Min(B:B))," ",1)]:Next

Ungolfed and Commented

''  run as `call icicle("Test")` or `icicle"I am the WALRUS`
Sub icicle(Optional str As String)
    If Not IsMissing(str) Then [A1] = str   ''  pipe input
    [B:B].Clear                             ''  reset between runs
    [B1].Resize([Len(A1)]) = "=If(Code(Mid(A$1,Row(),1))=32,1E3,Code(Mid(A$1,Row(),1)))"  ''  get char number for every char in input
    For i = 1 To [Len(A1)-CountIf(B:B,1E3)] ''  iterate across from 1 to length of input - number of spaces
        Debug.Print [A1]                    ''  output a single line
        [A1]=[Substitute(A1,Char(Min(B:B))," ",1)]  ''  replace minimum char with space
    Next
End Sub

Taylor Scott

Posted 2018-04-13T18:00:03.987

Reputation: 6 709

1

Z80 machine code on an Amstrad CPC, 51 bytes, 54 with safety

The following code progressively destroys the input string as each line is output:

(1A B7 C8)EB 4E 23 5E 23 56 41 1A 13 CD 5A BB 10
 F9 26 FF 41 1B 1A FE 21 38 06 BC 30 03 68 67 24
 10 F2 24 C8 2D 26 00 19 36 20 3E 0D CD 5A BB 3E
 0A CD 5A BB 18 D3

As assembler:

WinAPE Z80 Assembler V1.0.13

000001  0000  (8000)        ORG &8000
000002  8000  1A            LD A, (DE)
000003  8001  B7            OR A
000004  8002  C8            RET Z
000006  8003  EB            EX DE, HL
000008  8004  4E            LD C, (HL)
000010  8005  23            INC HL
000011  8006  5E            LD E, (HL)
000012  8007  23            INC HL
000013  8008  56            LD D, (HL)
000015  8009                LabelPrintString
000016  8009  41            LD B, C
000017  800A                LabelPrintChar
000018  800A  1A            LD A, (DE)
000019  800B  13            INC DE
000020  800C  CD 5A BB      CALL &BB5A
000021  800F  10 F9         DJNZ LabelPrintChar
000023  8011  26 FF         LD H, &FF
000024  8013  41            LD B, C
000026  8014                LableIcicle
000027  8014  1B            DEC DE
000028  8015  1A            LD A, (DE)
000029  8016  FE 21         CP &21
000030  8018  38 06         JR C, LabelNextChar
000031  801A  BC            CP H
000032  801B  30 03         JR NC, LabelNextChar
000033  801D  68            LD L, B
000034  801E  67            LD H, A
000035  801F  24            INC H
000036  8020                LabelNextChar
000037  8020  10 F2         DJNZ LableIcicle
000038  8022  24            INC H
000039  8023  C8            RET Z
000040  8024  2D            DEC L
000041  8025  26 00         LD H, &00
000042  8027  19            ADD HL, DE
000043  8028  36 20         LD (HL), &20
000044  802A  3E 0D         LD A, &0D
000045  802C  CD 5A BB      CALL &BB5A
000046  802F  3E 0A         LD A, &0A
000047  8031  CD 5A BB      CALL &BB5A
000048  8034  18 D3         JR LabelPrintString

Z80 machine code on an Amstrad CPC, 63 bytes, 66 with safety

I reworked the code to be non-destructive, but unfortunately the best I could do increased the size by 12 bytes:

(1A B7 C8)EB 46 23 5E 23 56 26 20 24 C8 2E 00 D5
 C5 0E 00 1A BC 38 0A 20 0A 0C 79 BD 38 03 1A 18
 02 3E 20 2C 2D 28 03 CD 5A BB 13 10 E6 28 0A 3E
 0D CD 5A BB 3E 0A CD 5A BB 7D B9 C1 D1 30 CC 2C
 18 CD

As assembler:

000001  0000  (8000)        ORG &8000
000002  8000                LabelSafeEntry
000003  8000                ; On entry, DE contains pointer to last parameter
000004  8000  1A            LD A, (DE)
000005  8001  B7            OR A
000006  8002  C8            RET Z ; Return if the input string had zero length
000008  8003                ; Start here if safety not required
000009  8003                LabelUnsafeEntry
000010  8003  EB            EX DE, HL ; HL is easier to use than DE. Swap their values
000012  8004                ; First byte is length of string
000013  8004  46            LD B, (HL)
000015  8005                ; Next word is address of string. Load it into DE
000016  8005  23            INC HL
000017  8006  5E            LD E, (HL)
000018  8007  23            INC HL
000019  8008  56            LD D, (HL)
000021  8009  26 20         LD H, &20 ; current_char
000023  800B                LabelNextChar
000024  800B  24            INC H
000025  800C  C8            RET Z
000026  800D  2E 00         LD L, &00 ; number
000028  800F                LabelParseString
000029  800F  D5            PUSH DE
000030  8010  C5            PUSH BC
000032  8011  0E 00         LD C, &00 ; number2
000033  8013                LabelPrintString
000034  8013  1A            LD A, (DE)
000035  8014  BC            CP H
000036  8015  38 0A         JR C, LabelPrintSpace
000037  8017  20 0A         JR NZ, LabelPrintChar
000038  8019  0C            INC C
000039  801A  79            LD A, C
000040  801B  BD            CP L
000041  801C  38 03         JR C, LabelPrintSpace
000042  801E  1A            LD A, (DE)
000043  801F  18 02         JR LabelPrintChar
000044  8021                LabelPrintSpace
000045  8021  3E 20         LD A, &20
000046  8023                LabelPrintChar
000047  8023  2C            INC L
000048  8024  2D            DEC L
000049  8025  28 03         JR Z, LabelSkipPrint
000050  8027  CD 5A BB      CALL &BB5A
000051  802A                LabelSkipPrint
000052  802A  13            INC DE
000053  802B  10 E6         DJNZ LabelPrintString
000055  802D  28 0A         JR Z, LabelNoNewLine
000056  802F  3E 0D         LD A, &0D
000057  8031  CD 5A BB      CALL &BB5A
000058  8034  3E 0A         LD A, &0A
000059  8036  CD 5A BB      CALL &BB5A
000060  8039                LabelNoNewLine
000061  8039  7D            LD A, L
000062  803A  B9            CP C
000063  803B  C1            POP BC
000064  803C  D1            POP DE
000065  803D  30 CC         JR NC, LabelNextChar
000066  803F  2C            INC L
000067  8040  18 CD         JR LabelParseString
  • The first 3 optional bytes check if the string is empty. Since the challenge specified a string of at least two characters, I'm not counting these bytes and starting execution with CALL &8003, a$ instead of CALL &8000, a$
  • The next 6 bytes get the input string into a usable state. A pointer to a reference to the last parameter (the string) is passed to the program in DE. The pointer can be used directly, but the reference needs to be dereferenced

Program 1

  • 8009 - 8035 Print String
    • Load counter register B with string length C
    • Do Print Char (on exit B is &00 and DE is the string address + its length)
    • Load H with &FF - an invalid ASCII character
    • Load counter register B with string length C
    • Do Icicle (on exit B is &00, H is the next ASCII character after the one to be replaced (if found), L is the character position to change to a space, and DE is back to just the string address)
    • Increment H. If it was still &FF, it will wrap to &00
    • Return if zero (this is the only exit point)
    • Decrement L to make it zero-based
    • Load H with &00. This expands the 8-bit value in L to a 16-bit value in HL
    • Add DE to HL (this is the address of the character to change)
    • Load the memory at (HL) with a space
    • Print "\r" (5 bytes of code!)
    • Print "\n" (another 5 bytes of code!)
    • Repeat Print String
  • 800A - 8010 Print Char (works the string left-to-right)
    • Load A with the current character pointed to by (DE)
    • Increment DE
    • Do a system call to print the character in A
    • Decrement B and repeat Print Char if not zero
  • 8014 - 8021 Icicle (works the string right-to-left)
    • Decrement DE
    • Load A with the current character pointed to by (DE)
    • If A is less than &21, go to the end of the loop
    • If A is greater than or equal to H, go to the end of the loop
    • Store the current character position (B) in L
    • Store the current ASCII character in H
    • Increment H so that repeats of this character can be detected easily
    • Decrement B and repeat Icicle if not zero

The last line always contains only spaces.

Word Icicle 1 output

Program 2

See annotations in the code. The last line always contains one printing character other than spaces.

Word Icicle 2 output

The programs are called from BASIC by either passing a string variable or a string literal.

  • CALL &8003, a$
  • CALL &8003, "I'm Melting!!!"

CJ Dennis

Posted 2018-04-13T18:00:03.987

Reputation: 4 104

1

Oracle SQL 11.2, 196 bytes

WITH v(s)AS(SELECT :1 FROM DUAL UNION ALL SELECT REGEXP_REPLACE(s,(SELECT MIN(TRIM(SUBSTR(s,LEVEL,1)))FROM DUAL CONNECT BY LEVEL<=LENGTH(s)),' ',1,1)FROM v WHERE LENGTH(TRIM(s))>0)SELECT * FROM v;

Un-golfed

WITH v(s)AS
(
  SELECT :1 FROM DUAL
  UNION ALL
  SELECT REGEXP_REPLACE(s,(SELECT MIN(TRIM(SUBSTR(s,LEVEL,1)))
                           FROM DUAL CONNECT BY LEVEL<=LENGTH(s)),' ',1,1)
  FROM v WHERE LENGTH(TRIM(s))>0
)
SELECT * FROM v;

Jeto

Posted 2018-04-13T18:00:03.987

Reputation: 1 601

1

Pyth, 13 bytes

uXGxG<r6S
G1d

Try it here!

A nice challenge I wanted to answer for a long time. I am aware that there's another Pyth 13-byter, but the methods used to solve the task are quite different, so I think it's worth posting (this one doesn't use imperative structures like V nor assignments such as =). The output contains obnoxiously many unnecessary trailing spaces and linefeeds.

Explanation

It's a full program that takes input from STDIN (quoted) and outputs to STDOUT.

uXGxG<r6S\nG1d – Note that I escaped the newline using \n, for readability.

u              – Until a result that has occurred before is found, do the following:
         \nG   – Print the current state of the string, G, which is initially the input.
        S      – Sort the current string.
      r6       – Strip all whitespace.
     <      1  – Take the first element, but avoid throwing errors if there are no
                 characters left to be trimmed.
   xG          – Find its index in G.
 XG          d – And replace the character at the index with a space.

Mr. Xcoder

Posted 2018-04-13T18:00:03.987

Reputation: 39 774

1

J,  36  32 bytes

echo~.(\:\:~"1]\@\:~)&.|.>2{ARGV

previous 36 = echo~.@|.@(|.@/:/:~"1[:]\\:~)>2{ARGV .. my silly redundant @'s wasted 2 chars NB. improvements courtesy of @FrownyFrog

explanation:

  • > 2{ ARGV unboxes the second argument of TIO's script runner
  • &. |. reverse string do … and re-reverse the result
  • ( \: \:~"1 ]\@\:~ ) permutes each row (i.e. columns)
  • \: permutation required to rank descending \:~ sort descending
  • echo ~. print the distinct (aka "nub") rows

or if the text has a space as its least char, 24 bytes fn

f=:/:~{~i.@#(]*<)"{/:@/:

TIO

jayprich

Posted 2018-04-13T18:00:03.987

Reputation: 391

The first 2 @s are unnecessary but you can use one in ]\@\:~ – FrownyFrog – 2018-04-29T08:18:25.007

So you can get rid of the ~ in the middle, and save another one with &.|. for 31. – FrownyFrog – 2018-04-29T08:32:34.740

You forgot to commute – FrownyFrog – 2018-05-03T06:29:38.683

1

brainfuck, 125 bytes

,[.[>+>+<<-]>>>++++[<-------->-],]<,<[[<<<]>>>[[>[-[>]->[>>]<<<+[>,<+++[>+++++++
+<-]>[<<<]>>>[.>>>]+[-<+]]]>]>]<<<[<<[>>]<]<]

Formatted:

,
[
  .[>+>+<<-]
  >>>++++[<-------->-],
]
<,<
[
  [<<<]
  >>>
  [
    [
      >
      [
        -[>]
        ->[>>]
        <<<+
        [
          >,<+++[>++++++++<-]>[<<<]
          >>>[.>>>]
          +[-<+]
        ]
      ]
      >
    ]
    >
  ]
  <<<
  [
    <<[>>]
    <
  ]
  <
]

Expects a trailing newline in the input.

Try it online

Mitch Schwartz

Posted 2018-04-13T18:00:03.987

Reputation: 4 899

1

Attache, 45 bytes

PeriodicSteps!{Place[_,_&Index!Min!_^^sp,sp]}

Try it online!

Explanation

PeriodicSteps takes a function f as an argument and returns a function which nests f on the argument until two results are the same. Then, all intermediate results are stored in a list and returned.

Then, {Place[_,_&Index!Min!_^^sp,sp]} performs a single "metling" iteration:

{Place[_,_&Index!Min!_^^sp,sp]}
{                             }   anonymous function
 Place[                    sp]    place a space
           Index!Min!_              where the index of of the minimal element
                      ^^sp            (except spaces)
       _,_&                       ...in the input

Conor O'Brien

Posted 2018-04-13T18:00:03.987

Reputation: 36 228

1

Powershell, 92 bytes

param($s)($s|% t*y)-ne' '|sort|%{$c=$_;$s
$s=-join($s|% t*y|%{if(!($c-$_)){$c=($_=' ')}$_})}

Less golfed test script:

$f = {

param($s)                   # an argument string
($s|% t*y)-ne' '|sort|%{    # convert toCharArray(), exclude ' ', sort and make for each char...
    $s                      # push current string to the pipe as a line of the result
    $c=$_                   # store current char
    $s=-join($s|% t*y|%{    # $s is a new copy
        if(!($c-$_)){       # in which a first occurence of the current char and spaces
            $c=($_=' ')     # replaced by space char
        }
        $_                  # push a char to new $s
    })
}

}

@(

    ,("TD.([)]* a) regex specials",   # ;P
      "TD.([)]* a) regex specials",
      "TD. [)]* a) regex specials",
      "TD. [ ]* a) regex specials",
      "TD. [ ]* a  regex specials",
      "TD. [ ]  a  regex specials",
      "TD  [ ]  a  regex specials",
      "T   [ ]  a  regex specials",
      "    [ ]  a  regex specials",
      "      ]  a  regex specials",
      "         a  regex specials",
      "            regex specials",
      "            regex speci ls",
      "            regex spe i ls",
      "            r gex spe i ls",
      "            r g x spe i ls",
      "            r g x sp  i ls",
      "            r   x sp  i ls",
      "            r   x sp    ls",
      "            r   x sp     s",
      "            r   x s      s",
      "                x s      s",
      "                x        s",
      "                x         ")

    ,("Word Icicle!",
      "Word Icicle!",
      "Word Icicle ",
      "Word  cicle ",
      " ord  cicle ",
      " ord   icle ",
      " ord   i le ",
      " or    i le ",
      " or    i l  ",
      " or      l  ",
      " or         ",
      "  r         ")

     ,("I'm Melting!!!",
       "I'm Melting!!!",
       "I'm Melting !!",
       "I'm Melting  !",
       "I'm Melting   ",
       "I m Melting   ",
       "  m Melting   ",
       "  m  elting   ",
       "  m   lting   ",
       "  m   ltin    ",
       "  m   lt n    ",
       "  m    t n    ",
       "       t n    ",
       "       t      ")

     ,("Hello World!",
       "Hello World!",
       "Hello World ",
       " ello World ",
       " ello  orld ",
       " ello  orl  ",
       "  llo  orl  ",
       "   lo  orl  ",
       "    o  orl  ",
       "    o  or   ",
       "       or   ",
       "        r   ")

    ,("AbCdEfGhIjKlMnOpQrStUvWxYz",
      "AbCdEfGhIjKlMnOpQrStUvWxYz",
      " bCdEfGhIjKlMnOpQrStUvWxYz",
      " b dEfGhIjKlMnOpQrStUvWxYz",
      " b d fGhIjKlMnOpQrStUvWxYz",
      " b d f hIjKlMnOpQrStUvWxYz",
      " b d f h jKlMnOpQrStUvWxYz",
      " b d f h j lMnOpQrStUvWxYz",
      " b d f h j l nOpQrStUvWxYz",
      " b d f h j l n pQrStUvWxYz",
      " b d f h j l n p rStUvWxYz",
      " b d f h j l n p r tUvWxYz",
      " b d f h j l n p r t vWxYz",
      " b d f h j l n p r t v xYz",
      " b d f h j l n p r t v x z",
      "   d f h j l n p r t v x z",
      "     f h j l n p r t v x z",
      "       h j l n p r t v x z",
      "         j l n p r t v x z",
      "           l n p r t v x z",
      "             n p r t v x z",
      "               p r t v x z",
      "                 r t v x z",
      "                   t v x z",
      "                     v x z",
      "                       x z",
      "                         z")

    ,("PPCG is da BEST",
      "PPCG is da BEST",
      "PPCG is da  EST",
      "PP G is da  EST",
      "PP G is da   ST",
      "PP   is da   ST",
      " P   is da   ST",
      "     is da   ST",
      "     is da    T",
      "     is da     ",
      "     is d      ",
      "     is        ",
      "      s        ")

    ,("({({})({}[()])}{})",
      "({({})({}[()])}{})",
      " {({})({}[()])}{})",
      " { {})({}[()])}{})",
      " { {}) {}[()])}{})",
      " { {}) {}[ )])}{})",
      " { {}  {}[ )])}{})",
      " { {}  {}[  ])}{})",
      " { {}  {}[  ] }{})",
      " { {}  {}[  ] }{} ",
      " { {}  {}   ] }{} ",
      " { {}  {}     }{} ",
      "   {}  {}     }{} ",
      "    }  {}     }{} ",
      "    }   }     }{} ",
      "    }   }     } } ",
      "        }     } } ",
      "              } } ",
      "                } ")

) | % {
    $s,$expected = $_
    $result = &$f $s
    "$result"-eq"$expected"
    $result            # comment this line to compact output
}

Output:

True
TD.([)]* a) regex specials
TD. [)]* a) regex specials
TD. [ ]* a) regex specials
TD. [ ]* a  regex specials
TD. [ ]  a  regex specials
TD  [ ]  a  regex specials
T   [ ]  a  regex specials
    [ ]  a  regex specials
      ]  a  regex specials
         a  regex specials
            regex specials
            regex speci ls
            regex spe i ls
            r gex spe i ls
            r g x spe i ls
            r g x sp  i ls
            r   x sp  i ls
            r   x sp    ls
            r   x sp     s
            r   x s      s
                x s      s
                x        s
                x
True
Word Icicle!
Word Icicle
Word  cicle
 ord  cicle
 ord   icle
 ord   i le
 or    i le
 or    i l
 or      l
 or
  r
True
I'm Melting!!!
I'm Melting !!
I'm Melting  !
I'm Melting
I m Melting
  m Melting
  m  elting
  m   lting
  m   ltin
  m   lt n
  m    t n
       t n
       t
True
Hello World!
Hello World
 ello World
 ello  orld
 ello  orl
  llo  orl
   lo  orl
    o  orl
    o  or
       or
        r
True
AbCdEfGhIjKlMnOpQrStUvWxYz
 bCdEfGhIjKlMnOpQrStUvWxYz
 b dEfGhIjKlMnOpQrStUvWxYz
 b d fGhIjKlMnOpQrStUvWxYz
 b d f hIjKlMnOpQrStUvWxYz
 b d f h jKlMnOpQrStUvWxYz
 b d f h j lMnOpQrStUvWxYz
 b d f h j l nOpQrStUvWxYz
 b d f h j l n pQrStUvWxYz
 b d f h j l n p rStUvWxYz
 b d f h j l n p r tUvWxYz
 b d f h j l n p r t vWxYz
 b d f h j l n p r t v xYz
 b d f h j l n p r t v x z
   d f h j l n p r t v x z
     f h j l n p r t v x z
       h j l n p r t v x z
         j l n p r t v x z
           l n p r t v x z
             n p r t v x z
               p r t v x z
                 r t v x z
                   t v x z
                     v x z
                       x z
                         z
True
PPCG is da BEST
PPCG is da  EST
PP G is da  EST
PP G is da   ST
PP   is da   ST
 P   is da   ST
     is da   ST
     is da    T
     is da
     is d
     is
      s
True
({({})({}[()])}{})
 {({})({}[()])}{})
 { {})({}[()])}{})
 { {}) {}[()])}{})
 { {}) {}[ )])}{})
 { {}  {}[ )])}{})
 { {}  {}[  ])}{})
 { {}  {}[  ] }{})
 { {}  {}[  ] }{}
 { {}  {}   ] }{}
 { {}  {}     }{}
   {}  {}     }{}
    }  {}     }{}
    }   }     }{}
    }   }     } }
        }     } }
              } }
                }

mazzy

Posted 2018-04-13T18:00:03.987

Reputation: 4 832

0

Retina, 40 bytes

/\S/{¶<`^
$'¶
O`\G.
 *(\S).*¶(.*?)\1
$2 

Try it online!

Martin Ender

Posted 2018-04-13T18:00:03.987

Reputation: 184 808

0

Haskell, 107 bytes

f s|sum[1|' '<-s]+1==length s=[s]|g<-(/=minimum(filter(/=' ')s))=s:f(fst(span g s)++' ':tail(snd$span g s))

Try it online!

Just out-golf me. Shouldn't be too hard, my brain isn't fully functional right now. :P

totallyhuman

Posted 2018-04-13T18:00:03.987

Reputation: 15 378

2Here ya go :), However once Laikoni or H.P.Wiz sees this I'm done. – Post Rock Garf Hunter – 2018-04-13T20:39:02.403

sum[1|' '<-s]+1==length s can be 1:[1|' '<-s]==(1<$s). filter(>' ')s should also work. – Laikoni – 2018-04-13T22:19:24.300

0

Julia 0.6, 82 bytes

g(s,r=filter(c->c!=' ',s),q=println(s))=isempty(r)||g(replace(s,minimum(r),' ',1))

Try it online!

gggg

Posted 2018-04-13T18:00:03.987

Reputation: 1 715

0

Charcoal, 22 bytes

WΦθ‹ κ«θ⸿≔⭆θ⎇⁼λ⌕θ⌊ι κθ

Try it online! Link is to verbose verison of code. Explanation:

WΦθ‹ κ«

Filter out spaces from the value. Repeat while there are still characters remaining, which are saved in the variable i, as we'll need the smallest later, and we don't want to include spaces in that determination. (There used to be a bug in Charcoal whereby the while loop didn't reserve the variable i until after the first loop, which would have made the Filter impossible, as the first loop it would try to use i instead of k.)

θ⸿

Print the value on its own line.

≔⭆θ⎇⁼λ⌕θ⌊ι κθ

Map over the characters of the value, replacing the one at the same position as the lexically smallest with a space, and replace the value with the result.

Neil

Posted 2018-04-13T18:00:03.987

Reputation: 95 035

0

Python 3, 93 bytes

a=input()
while len(a)-a.count(' '):print(a);a=a.replace(sorted(a.replace(' ',""))[0],' ',1)

EDIT: Python 3, +1 -> remembered that python 2's input is int

sonrad10

Posted 2018-04-13T18:00:03.987

Reputation: 535

0

Coconut, 46 bytes

x->scan((o,n)->o.replace(n,' ',1),sorted(x),x)

Try it online!

ovs

Posted 2018-04-13T18:00:03.987

Reputation: 21 408