Oreoorererereoo

62

12

Oreoorererereoo

Given an input string that is similar to the word "oreo", give an ASCII representation of the cookie that is as wide as the input string (to ensure cookie stability).

Rules

  • The input is lowercase, a non-empty string with no whitespace containing any combination of the strings "o" and "re", and containing only those strings.
  • The string "o" represents the solid cookie, while the string "re" represents the filling.
  • The output must be a stacked cookie that is as wide as the input string.
  • The output may not be an array of strings
  • The cookie must overlap the filling by one character on each side
  • The characters used for the output don't have to match the output below (█ and ░), they just have to be different non-whitespace characters for the two parts of the cookie
  • The whitespace padding on the left side of the filling is required, and any trailing whitespace is optional

Examples

Input: oreo
Output:
████
 ░░ 
████

Input: o
Output:
█

Input: re
Output: (two spaces)


Input: rere
Output:
 ░░ 
 ░░ 

Input: oreoorererereoo
Output:
███████████████
 ░░░░░░░░░░░░░ 
███████████████
███████████████
 ░░░░░░░░░░░░░ 
 ░░░░░░░░░░░░░ 
 ░░░░░░░░░░░░░ 
 ░░░░░░░░░░░░░ 
███████████████
███████████████

Since this is code golf the shortest answer wins, good luck :)

GammaGames

Posted 2019-01-04T01:09:34.990

Reputation: 995

3"The whitespace padding on each side of the filling is required". Does this actually mean that there must be a space character at the end of each line of filling? If so why? As long as it works visually then what does this requirement add to the challenge? – ElPedro – 2019-01-06T00:23:33.343

@ ElPedro Good point, I modified the rules and @Dennis I edited the rules so the comments should be okay to clean up – GammaGames – 2019-01-07T03:22:45.197

@JonathanAllan Since it's printing "ascii-art" I removed that rule, it looks like I forgot to update the question. Should be updated now. – GammaGames – 2019-01-07T16:05:06.207

Awesome, thanks! – Jonathan Allan – 2019-01-07T16:18:12.050

@GammaGames, if whitespace on the right is not required anymore, I assume the output for test case re should be now acceptable as 1 or 2 spaces, not necessarily 2? – Kirill L. – 2019-01-10T08:24:08.743

@KirillL. That would be correct, yes. When I originally designed it I accidentally didn't use general ascii rules, but I modified them as to be more flexible. – GammaGames – 2019-01-10T15:07:41.840

Answers

16

Jelly,  16 14  13 bytes

-1 Thanks to Erik the Outgolfer

OḂƇẒṁ€aØ.¦€⁶Y

Uses 1 for the cream and 0 for the cookie.

Try it online!

How?

OḂƇẒṁ€aØ.¦€⁶Y - Main Link: list of characters, V    e.g. 'orereo'
O             - ordinal (vectorises)                     [111,114,101,114,101,111]
  Ƈ           - filter keep those for which:
 Ḃ            -   modulo 2                               [111,    101,    101,111]
   Ẓ          - is prime? (vectorises)                   [  0,      1,      1,  0]
    ṁ€        - mould each like V                        [[0,0,0,0,0,0],[1,1,1,1,1,1],[1,1,1,1,1,1],[0,0,0,0,0,0]]
          €   - for each:
         ¦    -   sparse application...
       Ø.     -   ...to indices: literal [0,1] (0 is the rightmost index, 1 is the leftmost)
      a       -   ...apply: logical AND with:
           ⁶  -               space character           [[0,0,0,0,0,0],[' ',1,1,1,1,' '],[' ',1,1,1,1,' '],[0,0,0,0,0,0]]
            Y - join with newline characters            [0,0,0,0,0,0,'\n',' ',1,1,1,1,' ','\n',' ',1,1,1,1,' ','\n',0,0,0,0,0,0]
              - implicit print                       ...smashes everything together:
              -                                         000000
              -                                          1111 
              -                                          1111 
              -                                         000000

Previous 16 byter:

ḟ”eẋ€Ly@Ø.¦€⁾r Y

Uses r for the cream and o for the cookie.

Try it online!

Jonathan Allan

Posted 2019-01-04T01:09:34.990

Reputation: 67 804

I was hoping for a Jelly entry, such an interesting language! – GammaGames – 2019-01-04T17:39:46.103

19

Pepe, 364 bytes

Unfortunately the online interpreter does not take care of compressing comments, hence all o characters will be replaced by a space.. Neither the spaces nor the o are necessary, so this could be 295 bytes, but I like it more this way:

rEeEEeeEeEororEEoreoreeeEeeeeeorEEEEeoREeoreorEeEEeEEEEororEEoreorEEEEEoREeoreorEeEEEeeEeororEEoreoReoREoREEEeoREEEEEoreorEorEEEeorEEEEEoreEoREeoreoREEeoREEEEeEeeoREEEeoREeeEoREEEeoREEEEEEEorEEEeEorEEEeoREoREEEeoREEEEEoREEoReoreorEEEeEoREEEEEEeorEEEeoReEoREoREEEeoREEoReoroReEeoREoREEEeorEEEEeoReeoREEEeoREeeEoREEEeoREEEEEEEoreoReoReoREoREEEeoREEEEEoreeeeeEeEeoRee

Try it online!

Ungolfed

There might be some golfing oppurtunities with flags which I missed, but I'm done for now:

# "function" for 'e'
rEeEEeeEeE rrEE
  re          # remove duplicated argument
  reeeEeeeee  # print space
  rEEEEe      # decrement counter twice
REe re

# "function" for 'o'
rEeEEeEEEE rrEE
  re      # remove duplicated argument
  rEEEEE  # increment counter
REe re

# "function for 'r'
rEeEEEeeEe rrEE
  re Re              # remove duplicated argument & char
  RE REEEe REEEEE    # push 1
  re rE rEEEe rEEEEE # replace 1
  reE                # goto 1
REe re

# Main

REEe REEEEeEee                # read input & reverse
REEEe REeeE REEEe REEEEEEE    # push length-1 & move to r

rEEEeE rEEEe # dummy loop-var (fucking do-whiles...)
RE REEEe REEEEE REE  # while [label-1]

  # Call the right procedure depending on current character,
  # sets stacks up as follows:
  #   R [ .... *currentChar ]
  #   r [ (N-1) *count ]
  Re re          # pop 1 & loop-counter
  rEEEeE         # duplicate counter
  REEEEEEe rEEEe # copy current char to other stack
  ReE            # jeq to 'o'-label or 'e'-label

  # Output currentChar count times:
  RE REEEe REE # while [label-0]:
    Re         #   pop 0
    rReEe      #   print character
    RE REEEe   #   push 0
    rEEEEe     #   decrement counter
  Ree

  REEEe REeeE REEEe REEEEEEE  # push length-1 & move to r
  re Re Re                    # pop 0, counter and 9((((currentChar
  RE REEEe REEEEE             # push 1
  reeeeeEeEe                  # print new-line

Ree

ბიმო

Posted 2019-01-04T01:09:34.990

Reputation: 15 345

1

I moved this conversation to chat for you.

– James – 2019-01-09T16:13:07.730

9

Canvas, 19 18 17 bytes

e ∙╋
:r≠*┤];L×⁸↔⁸

Try it here!

Uses the annoyingly long code of :r≠*┤] to remove rs from the input..

dzaima

Posted 2019-01-04T01:09:34.990

Reputation: 19 048

That's a handy feature, and cool language! – GammaGames – 2019-01-04T01:48:51.243

7

Japt -R, 16 15 bytes

re ¬£çX sX²èrÃû

Try it

                    :Implicit input of string U
re                  :Remove all "e"s
   ¬                :Split to array of characters
    £               :Map each X
     çX             :  Repeat X to the length of U
        s           :  Slice from index
         X²         :   Duplicate X
           èr       :   Count the occurrences of "r"
             Ã      :End map
              û     :Centre pad each element with spaces to the length of the longest
                    :Implicitly join with newlines and output

Alternatives

re ¬ËpUÊaD²èrÃû
re ¬£îX rr²i^Ãû

Shaggy

Posted 2019-01-04T01:09:34.990

Reputation: 24 623

6

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

n=>n.Replace("o",new String('-',n.Length)+"\n").Replace("re"," ".PadRight(n.Length-1,'|')+"\n")

Try it online!

Alternative using Aggregate, 108 bytes

n=>n.Aggregate("",(d,c)=>d+(c<102?"":c<112?new String('-',n.Length)+"\n":" ".PadRight(n.Length-1,'|')+"\n"))

Try it online!

Embodiment of Ignorance

Posted 2019-01-04T01:09:34.990

Reputation: 7 014

1now it trims trailing spaces.. – dzaima – 2019-01-04T01:50:32.757

There was enough feedback that I removed the trailing newline rule. Feel free to update your entry. – GammaGames – 2019-01-04T04:40:57.427

Your replace doesn't work when the input is o, since the n.Length-2 will result in -1. – Kevin Cruijssen – 2019-01-04T10:18:05.683

The n.Length-2 is is for when the input has re. – Embodiment of Ignorance – 2019-01-04T16:27:51.173

6

05AB1E, 18 17 16 bytes

'eKεD'rQ2*Igα×}.c

-1 byte thanks to @Emigna

Uses o for the cookie and r for the filling.

Try it online or verify all test cases.

Explanation:

'eK                 '# Remove all "e" from the (implicit) input
                     #  i.e. "orereo" → "orro"
   ε         }       # Map all characters to:
    D                #  Duplicate the current character
     'rQ            '#  Check if it's an "r" (1 if truthy; 0 if falsey)
                     #   i.e. "r" → 1
                     #   i.e. "o" → 0
        ·            #  Double that
                     #   i.e. 1 → 2
                     #   i.e. 0 → 0
         Ig          #  Take the length of the input
                     #   i.e. "orereo" → 6
           α         #  Take the absolute difference between the two
                     #   i.e. 2 and 6 → 4
                     #   i.e. 0 and 6 → 6
            ×        #  Repeat the duplicated character that many times
                     #   i.e. "r" and 4 → "rrrr"
                     #   i.e. "o" and 6 → "oooooo"
              .c     # Then centralize it, which also imlicitly joins by newlines
                     # (and the result is output implicitly)
                     #  i.e. ["oooooo","rrrr","rrrr","oooooo"]
                     #   → "oooooo\n rrrr\n rrrr\noooooo"

Kevin Cruijssen

Posted 2019-01-04T01:09:34.990

Reputation: 67 575

Creative solution, But it does not solve the problem entirely:

oro would give a wrong answer – Mark Smit – 2019-01-06T09:15:52.097

@MarkSmit oro isn't a possible input, since the input will only contain os and res. Regardless, oro still seems to output correctly following the spec, since it outputs ooo\n r\nooo. What is wrong about it?

– Kevin Cruijssen – 2019-01-06T10:44:13.467

This is invalid: "The whitespace padding on each side of the filling is required" – NieDzejkob – 2019-01-06T15:14:25.743

2* can be · and the missing whitespace can be fixed by changing ».c to .c.B» – Emigna – 2019-01-07T09:29:01.137

@Emigna Ah, can't believe I haven't thought about ·, thanks! :) And always nice to have changing specs during the challenge, sigh.. – Kevin Cruijssen – 2019-01-07T09:40:02.963

Trailing whitespace is now optional! – Jacktose – 2019-01-08T00:28:34.690

@P1h3r1e3d13 Thanks for letting me know. :) – Kevin Cruijssen – 2019-01-08T07:48:09.490

6

R, 106 bytes

function(s,N=nchar(s)){m=rep(el(strsplit(gsub('re',0,s),'')),e=N)
m[m<1&seq(m)%%N<2]=' '
write(m,1,N,,"")}

Try it online!

  • -12 bytes thanks to @Giuseppe

Previous version with explanation :

R, 118 bytes

function(s,N=nchar(s)){m=t(replicate(N,el(strsplit(gsub('re',0,s),''))))
m[m<1&row(m)%in%c(1,N)]=' '
write(m,1,N,,'')}

Try it online!

  • -1 byte thanks to @Giuseppe

Unrolled code and explanation :

function(s){                       # s is the input string, e.g. 'oreo'

  N = nchar(s)                     # store the length of s into N, e.g. 4

  s1 = gsub('re',0,s)              # replace 're' with '0' and store in s1, e.g. 'o0o'

  v = el(strsplit(s1,''))          # split s1 into a vector v of single characters
                                   # e.g. 'o','0','o'

  m = replicate(N,v)               # evaluate N times the vector v and arrange 
                                   # the result into a matrix m (nchar(s1) x N)
                                   # e.g. 
                                   # 'o' 'o' 'o' 'o' 
                                   # '0' '0' '0' '0' 
                                   # 'o' 'o' 'o' 'o' 


  m = t(m)                         # transpose the matrix

  m[m<1 & row(m)%in%c(1,N)] = ' '  # substitute the zeros (i.e. where < 1) 
                                   # on the 1st and last row of the matrix with ' ' (space)
                                   # e.g. 
                                   # 'o' ' ' 'o' 
                                   # 'o' '0' 'o' 
                                   # 'o' '0' 'o' 
                                   # 'o' ' ' 'o'

  write(m,1,N,,'')                 # write the matrix to stdout (write function transposes it)
                                   # e.g.
                                   # oooo
                                   #  00 
                                   # oooo
}

digEmAll

Posted 2019-01-04T01:09:34.990

Reputation: 4 599

106 bytes – Giuseppe – 2019-01-04T22:40:41.880

aaand 104 bytes returning a list of lines, which isn't acceptable here, but it's an interesting idea (essentially my SNOBOL submission translated to R)

– Giuseppe – 2019-01-04T23:11:01.910

5

Retina, 74 73 bytes

I feel like I haven't posted an answer in a very long time. Well, here I am. Also, Retina has changed a lot, and I feel like I suck at it now.

.+
$0$.0
(\d+)
*
e

o|r
$&¶
_$

+(/_/&`o¶
oo¶
_$

)/_/&`r¶
rr¶
¶$

m`^r
 

Try it online!

mbomb007

Posted 2019-01-04T01:09:34.990

Reputation: 21 944

1Whoa, what a crazy looking language. I like it! – GammaGames – 2019-01-04T01:58:21.060

doesn't include trailing whitespaces.. – dzaima – 2019-01-04T02:00:03.717

2I like how [or] means o or r instead of [ or ]. Makes my head hurt. – nedla2004 – 2019-01-04T02:43:17.643

@dzaima The question does not specify that trailing whitespaces are required. A comment asked, but no reply was given. – mbomb007 – 2019-01-04T19:44:23.820

@nedla2004 That actually helped me notice a way to save a byte. Thanks. – mbomb007 – 2019-01-04T19:44:41.747

@mbomb007 if I remember correctly, the answer to my question, before it was deleted (because it mentioned the no trailing newline requirement that's now gone) was that they're not mandatory, except if the last line is "re", though I have asked for reclarification – dzaima – 2019-01-04T19:49:13.043

@nedla2004 well, it is regex – ASCII-only – 2019-01-08T00:02:14.443

71? – ASCII-only – 2019-01-08T00:02:47.080

49? – ASCII-only – 2019-01-08T00:31:04.840

Oh wait, Neil already has a 24 (and can use his old 21 since the trailing space requirement has been lifted) byte one – ASCII-only – 2019-01-08T00:33:38.823

5

C (gcc), 135 113 109 104 bytes

#define $ putchar(33
O(char*r){for(char*e,*o=r,x;*r;$-23))for(x=*r++>111,e=x?$-1),r++,o+2:o;*e++;$+x));}

Try it online!

Jonathan Frech

Posted 2019-01-04T01:09:34.990

Reputation: 6 681

Shave off a few bytes with -D$=putchar – None – 2019-01-04T13:55:20.870

131 bytes if you add a trailing newline as allowed by the rules. – NieDzejkob – 2019-01-06T13:54:21.130

127 bytes if you move the e=o to the condition of the first for loop and then remove the else. – NieDzejkob – 2019-01-06T14:20:45.827

118 bytes if you choose the cookie and filling characters carefully. – NieDzejkob – 2019-01-06T14:58:13.323

113 bytes – NieDzejkob – 2019-01-06T15:02:45.090

So the rules were bent enough to allow a trailing newline ... Thanks for your 22 byte improvement. – Jonathan Frech – 2019-01-06T15:07:59.040

@JonathanFrech I think they were just changed: "A line return at the end is optional" – NieDzejkob – 2019-01-06T15:09:36.373

@Rogem I know. But sometimes I refrain from using compiler flags. You are encouraged to fork my answer and implement your golf. – Jonathan Frech – 2019-01-06T22:59:29.763

102 bytes-Try it online! – Logern – 2019-01-08T15:32:21.447

@Logern As I already wrote Rogem, you are encouraged to fork my answer. – Jonathan Frech – 2019-01-08T19:30:24.303

-5 bytes since the whitespace rules changed. – NieDzejkob – 2019-01-08T21:40:27.150

@NieDzejkob The specifications really changed ... Thank you. – Jonathan Frech – 2019-01-08T22:10:11.820

5

Retina, 21 bytes

r

L$`.
$.+*$&
\bee
 

Try it online! Explanation:

r

Delete the rs.

L$`.
$.+*$&

List each letter on its own line repeated to the length of the original input.

\bee
 

Replace the first two ees on each line with a space.

Neil

Posted 2019-01-04T01:09:34.990

Reputation: 95 035

This breaks the rules: "The whitespace padding on each side of the filling is required" – NieDzejkob – 2019-01-06T15:16:31.833

@NieDzejkob Sorry for overlooking that, should be fixed now. – Neil – 2019-01-06T16:14:50.123

FYI trailing whitespace requirement lifted. – Jacktose – 2019-01-08T00:26:06.510

@Neil You should fix that &amp; :P – ASCII-only – 2019-01-08T00:35:43.017

4

JavaScript ES6, 103 bytes

Using replace 103 bytes:

x=>x.replace(/o/g,"-".repeat(s=x.length)+`
`).replace(/re/g," "+"|".repeat(s>1?s-2:0)+` 
`).slice(0,-1)

Try it online!

Using split and map 116 bytes:

x=>x.split("re").map(y=>("-"[h='repeat'](r=x.length)+`
`)[h](y.length)).join(" "+"|"[h](r>1?r-2:0)+` 
`).slice(0,-1)

Try it online!

fəˈnɛtɪk

Posted 2019-01-04T01:09:34.990

Reputation: 4 166

1JS, nice! You reminded me that I was going to add a rule about not having line returns at the end of the output, I've added it. Sorry about that! – GammaGames – 2019-01-04T01:45:24.373

3just removing the final newline is 12 bytes – fəˈnɛtɪk – 2019-01-04T01:51:06.387

There was enough feedback that I removed the trailing newline rule. Feel free to update your entry. – GammaGames – 2019-01-04T04:44:39.430

3You can save a byte by using a template string with ${"|".repeat(s>1?s-2:0)} and its whitespaces, instead of using " "+"|".repeat(s>1?s-2:0). – Ismael Miguel – 2019-01-04T10:26:15.710

If you use backticks for the string in the first split, you can remove the parentheses around it. – skiilaa – 2019-01-11T19:56:24.850

4

Python 3, 77 bytes

lambda x:x.replace("o","-"*len(x)+"\n").replace("re"," "+'.'*(len(x)-2)+"\n")

Try it online!

Rɪᴋᴇʀ

Posted 2019-01-04T01:09:34.990

Reputation: 7 410

Clever! I did intend the output to not be printing whitespace for the filling (it's pretty much oreo ascii), so I have edited the rules accordingly. Sorry about that! And I always love a python answer :) – GammaGames – 2019-01-04T04:50:05.147

@JonathanFrech migth as well delete the comments, that approach was invalidated. I'll work on golfing more tomorrow. – Rɪᴋᴇʀ – 2019-01-04T04:55:20.513

You can remove the space at +" \n" to save a byte. – Kevin Cruijssen – 2019-01-04T10:37:44.607

@KevinCruijssen can I? The input program says the whole cookie must be as wide as the input. – Rɪᴋᴇʀ – 2019-01-04T16:18:15.307

2I interpreted that as meaning that a trailing space is the same (visually) as no space. That's the beauty of answers to ascii art challenges. If they look right they are right :-) – ElPedro – 2019-01-04T21:33:07.107

Rules now say trailing whitespace is optional. – Jacktose – 2019-01-08T00:29:26.060

4

Java 11, 110 bytes

s->{int l=s.length();return s.replace("re"," "+"~".repeat(l-(l<2?1:2))+"\n").replace("o","=".repeat(l)+"\n");}

Uses = for the cookie and ~ for the filling.

Try it online.

Explanation:

s->{                       // Method with String as both parameter and return-type
  int l=s.length();        //  Get the length of the input
  return s                 //  Return the input
          .replace("re",   //  After we've replaced all "re" with:
            " "            //   A space
            +"~".repeat(l-(l<2?1:2))
                           //   Appended with length-2 amount of "~"
                           //   (or length-1 if the input-length was 1)
            +"\n")         //   Appended with a newline
          .replace("o",    //  And we've also replaced all "o" with:
            "=".repeat(l)  //   Length amount of "="
            +"\n");}       //   Appended with a newline

The above solution uses a replace. The following maps over the characters of the input instead:

Java 11, 113 112 bytes

s->s.chars().forEach(c->{if(c>101)System.out.println((c>111?" ":"")+(""+(char)c).repeat(s.length()-2*(~c&1)));})

-1 byte thanks to @Neil.

Try it online.

Explanation:

s->                           // Method with String parameter and no return-type
  s.chars().forEach(c->{      //  Loop over the characters as codepoint-integers
    if(c>101)                 //   If it's not an 'e':
      System.out.println(     //    Print with trailing newline:
       (c>111?                //     If it's an 'r'
         " "                  //      Start with a space
        :                     //     Else (it's an 'o' instead)
         "")                  //      Start with an empty string
       +(""+(char)c).repeat(  //     And append the character itself
          .repeat(            //     Repeated the following amount of times:
           s.length()         //      The input-length
           -2*(~c&1)));})     //      Minus 2 if it's an "r", or 0 if it's an "o"

Kevin Cruijssen

Posted 2019-01-04T01:09:34.990

Reputation: 67 575

1Can you use ~c&1? – Neil – 2019-01-04T11:34:24.143

@Neil I indeed can, thanks. – Kevin Cruijssen – 2019-01-04T11:57:32.580

This is invalid: "The whitespace padding on each side of the filling is required" – NieDzejkob – 2019-01-06T15:15:44.417

@NieDzejkob Fixed.. Always nice to have changing specs during the challenge, sigh.. – Kevin Cruijssen – 2019-01-07T09:43:53.443

@KevinCruijssen not anymore :P – ASCII-only – 2019-01-07T23:32:17.850

@ASCII-only Rollbacked. :) – Kevin Cruijssen – 2019-01-08T07:47:29.493

4

JavaScript, 72 65 64 bytes

s=>s.replace(/.e?/g,([x,y])=>(y?`
 `:`
`).padEnd(s.length+!y,x))

Try it online

Shaggy

Posted 2019-01-04T01:09:34.990

Reputation: 24 623

4

Perl 5 -p, 47 bytes

s|o|X x($i=y///c).$/|ge;s|re|$".O x($i-2).$/|ge

Try it online!

Xcali

Posted 2019-01-04T01:09:34.990

Reputation: 7 671

This breaks the rules: "The whitespace padding on each side of the filling is required" – NieDzejkob – 2019-01-06T15:16:46.910

4

Powershell, 71 69 66 bytes

-2 bytes thanks @Veskah

-3 bytes thanks @AdmBorkBork

$l=$args|% le*
switch($args|% t*y){'o'{'#'*$l}'r'{" "+'%'*($l-2)}}

Less golfed test script:

$f = {

$l=$args|% length
switch($args|% t*y){
    'o'{'#'*$l}
    'r'{" "+'%'*($l-2)}
}

}

@(

,(
'oreo',
'####',
' %%',
'####'
)
,(
'o',
'#'
)
,(
're',
' '
)
,(
'rere',
' %%',
' %%'
)
,(
'oreoorererereoo',
'###############',
' %%%%%%%%%%%%%',
'###############',
'###############',
' %%%%%%%%%%%%%',
' %%%%%%%%%%%%%',
' %%%%%%%%%%%%%',
' %%%%%%%%%%%%%',
'###############',
'###############'
)

) | % {
    $s,$expected = $_
    $result = &$f $s
    "$result"-eq"$expected"
    # $result # uncomment this line to display a result
}

Output:

True
True
True
True
True

mazzy

Posted 2019-01-04T01:09:34.990

Reputation: 4 832

1

Looks like you don't need parens around the $args 69 bytes

– Veskah – 2019-01-04T23:30:10.083

1The length of [string[]] is an [int[]]... The [int[]] is [int] if the array contains one element only. Great! Thanks! – mazzy – 2019-01-05T08:55:10.907

1The OP updated the challenge so you don't need trailing spaces anymore. This means your r can be " "+'%'*($l-2) instead for -3 bytes. – AdmBorkBork – 2019-01-18T20:19:06.770

4

PHP, 100 99 93 bytes

$l=strlen($i=$argv[1]);$r=str_repeat;echo strtr($i,[o=>$r(X,$l)."
",re=>' '.$r(o,$l-2)."
"]);

Try it online!

OUCH. PHP's waaaay_too_long function names strike again!

Output:

$php oreo.php oreo
XXXX
 oo
XXXX

$php oreo.php o
X

$php oreo.php rere
 oo
 oo

$ php oreo.php oreoorererereoo
XXXXXXXXXXXXXXX
 ooooooooooooo
XXXXXXXXXXXXXXX
XXXXXXXXXXXXXXX
 ooooooooooooo
 ooooooooooooo
 ooooooooooooo
 ooooooooooooo
XXXXXXXXXXXXXXX
XXXXXXXXXXXXXXX

640KB

Posted 2019-01-04T01:09:34.990

Reputation: 7 149

Invalid, cream lines need a trailing space – ASCII-only – 2019-01-05T05:03:36.327

Fixed the trailing space. Thanks! – 640KB – 2019-01-05T12:09:34.810

1Oh boy, PHP! Also any trailing whitespace is now optional, there were enough people that pointed out that since it's printing out ascii it shouldn't really be required. – GammaGames – 2019-01-07T03:26:51.060

4

Mathematica, 111 91 bytes

#~StringReplace~{"o"->"O"~Table~(n=StringLength@#)<>"\n","re"->" "<>Table["R",n-2]<>" \n"}&

Try It Online!

This was majorly shortened thanks to Misha's edits.


My original code:

(z=StringRepeat;n=StringLength@#;#~StringReplace~{"o"->"O"~z~n<>"\n","re"->" "<>If[n>2,z["R",n-2],""]<>" \n"})&

This code is not very fancy but it seems too expensive to convert away from strings and then back or to do anything else clever.

In particular, with only 3-4 commands that have the name String, my original approach couldn't save bytes at all by trying to abstract that away. For example, the following is 129 bytes:

(w=Symbol["String"<>#]&;z=w@"Repeat";n=w["Length"]@#;#~w@"Replace"~{"o"->"O"~z~n<>"\n","re"->" "<>If[n>2,z["R",n-2],""]<>" \n"})&

Mark S.

Posted 2019-01-04T01:09:34.990

Reputation: 251

1

A few improvements: StringRepeat can be Table since <> will convert the list into a string later; the If is unnecessary since we take the re branch only when n is at least 2; we can save on parentheses by defining n only when we use it. Try it online!

– Misha Lavrov – 2019-01-05T20:32:37.543

@MishaLavrov The If was added because StringRepeat would throw an error on the case of "re"; it doesn't allow you to repeat a string 0 times. Table has no such limitation, so that's a big save! – Mark S. – 2019-01-05T21:33:57.360

4

PHP, 96 87 85 bytes

Thanks to @gwaugh -9 Bytes
Thanks to @manatwork -2 Bytes

<?=strtr($i=$argv[1],[o=>($r=str_repeat)(X,$l=strlen($i))."
",re=>" {$r(o,$l-2)}
"]);

Try it online!

Try it online! (87 Bytes)

Try it online (original 97 bytes submition)!


And a recursive function

PHP, 135 bytes

function f($w,$x=0){$f=str_repeat;echo($x<($l=strlen($w)))?($w[$x]=='o')?$f(█,$l)."
".f($w,$x+1):" ".$f(░,$l-2)."
".f($w,$x+2):"";}

Try it online! (recursive)

Francisco Hahn

Posted 2019-01-04T01:09:34.990

Reputation: 591

1

by combining the best of our two submissions I was able to get it down to 87 bytes TIO. Would you be game to go in with this as a collaborative submission? :)

– 640KB – 2019-01-09T16:55:18.967

1I think we can remove 1 more byte by using the command short_tag_open, and instead of <?= we can use <?, or am i mistaken? – Francisco Hahn – 2019-01-09T18:46:40.027

12 characters shorter with string interpolation: ' '.$r(o,$l-2)." "" {$r(o,$l-2)} ". – manatwork – 2019-01-09T18:48:54.483

Thanks @manatwork sometimes i forgot php vars are evaluated in a string if the entire string is declared with "" istead of '' – Francisco Hahn – 2019-01-09T18:58:12.073

1

This can be 3 bytes shorter using $argn: Try it online!

– Night2 – 2019-09-02T12:00:38.553

4

Perl 6, 37 bytes

{m:g/o|r/>>.&({S/rr/ /.say}o*x.comb)}

Try it online!

Anonymous code block that takes a string and prints the oreo, with o as the cookie and r as the cream.

Explanation:

{                                   }   # Anonymous code block
 m:g/o|r/                               # Select all o s and r s
         >>.&(                     )    # Map each letter to
                            *x.comb     # The letter padded to the width
               S/rr/ /                  # Substitute a leading rr with a space
                      .say              # And print with a newline

Jo King

Posted 2019-01-04T01:09:34.990

Reputation: 38 234

I didn't realize o could be used in place of . Very nicely golfed. – primo – 2019-01-16T13:22:57.527

3

Pyth, 28 bytes

FNzIqN"o"*lzN)IqN"r"+d*-lz2N
FNz                              For each value, N, in input
   IqN"o"                        if the character is "o"
         *lzN                    return the character times the length of the input
             )                   end if
              IqN"r"             if the character is "r"
FNzIqN"o"*lzN)IqN"r"+d*-lz2N
                        *-lz2N   return the character times length - 2
                    +d           padded on the left with " "

Try it here! This one uses a loop.

Pyth, 30 bytes

(As string replace)

::z"o"+*lz"="b"re"++d*-lz2"~"b
 :z"o"                           With the input, replace "o" with
       *lz"="                    "=" times the length of the input
      +      b                   and a newline added to the end
:             "re"               With the input, replace "re" with
                     *    "~"    "~" times
                      -lz2       the length of the input minus 2
                   +d            padded on the left with " "
                  +          b   and a newline added to the end

Try it here! This one uses string replacement.

I really like python (it's what I wrote my original test scripts in), so I thought I'd do a pyth entry for fun :)

GammaGames

Posted 2019-01-04T01:09:34.990

Reputation: 995

1Isn't this 37 bytes? I thought Pyth uses default ASCII as its codepage just like Python, if I remember correctly. So even though your code is 33 characters, both and are three bytes each. Or am I missing something here? – Kevin Cruijssen – 2019-01-04T07:05:09.073

Good call, I didn't realize that (I couldn't get pyth to work on tio.run, so I used the length counter on the herokuapp page). In the for loop I could just replace the character with N, even saving a few bytes! – GammaGames – 2019-01-04T14:38:57.230

Thought something like that happened. :) I once had the same issue with a 05AB1E answer of mine that was using characters outside its code page. Unfortunately TIO displays chars and bytes the same for most golfing languages. For Java or Python TIO will correctly state 33 chars, 37 bytes, but not in golfing languages on TIO. But in your solutions just changing those characters indeed fixes the issue, so it's not that big of a deal here. – Kevin Cruijssen – 2019-01-04T14:41:47.393

@KevinCruijssen Wait, 05AB1E doesn't use an actual SBCS? – ASCII-only – 2019-01-06T01:08:36.060

@ASCII-only Nope, it uses this codepage. If you use any character not in this codepage you'll have to use a different encoding (like ASCII), increasing the byte-count by A LOT considering the many non-ASCII characters 05AB1E uses itself already.

– Kevin Cruijssen – 2019-01-06T10:37:40.753

@KevinCruijssen Isn't that an actual SBCS? Even though 05AB1E can use different encodings, that specific codepage does still have glyphs for all 256 bytes (meaning it can't have muti-byte sequences) – ASCII-only – 2019-01-07T03:27:01.610

1

If you're interested, it seems to work effortlessly on TIO for me.

– NieDzejkob – 2019-01-09T16:07:44.777

@NieDzejkob Thank you! I updated the post with the tio links – GammaGames – 2019-01-09T17:04:18.633

3

Charcoal, 19 bytes

Fθ≡ιo⟦⭆θ#⟧e«→P⁻Lθ²↙

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

Fθ

Loop through the characters of the input string.

≡ι

Switch on each character.

o⟦⭆θ#⟧

If it's an o then print the input string replaced with #s on its own line.

e«→P⁻Lθ²↙

If it's an e then move right, print a line of -s that's two less than the length of the input string, then move down and left.

Neil

Posted 2019-01-04T01:09:34.990

Reputation: 95 035

3

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

s=>s.Aggregate("",(a,c)=>a+(c>111?" ":"\n".PadLeft(s.Length+c/5-21,c)))

Try it online!

Borrowed some ideas from on Embodiment of Ignorance's answer for sure.

-6 bytes thanks to @ASCIIOnly!

The overall concept is to compute a string aggregate over the input characters following these rules:

  • If an r is encountered, append a single space character for indentation. We know the next character will be an e.
  • If an o or an e is encountered, generate a string by repeating the current character a specific number of times and prepending it to a newline or some padding and a newline.
  • The number of times to repeat is determined by length of input string and whether the current line is indented.
  • The PadLeft function is used to generate the repeating character string.

The result is the concatenation of all of these strings.

dana

Posted 2019-01-04T01:09:34.990

Reputation: 2 541

171 – ASCII-only – 2019-01-05T01:09:52.077

@ASCIIOnly - Thanks :) – dana – 2019-01-05T01:57:23.970

ockquote>

The whitespace padding on each side of the filling is required

– ASCII-only – 2019-01-05T04:57:35.810

185? – ASCII-only – 2019-01-05T05:01:21.877

I didn't notice that :) Although, in reviewing the posted answers about 1/2 have done this incorrectly as well. Good catch though! – dana – 2019-01-05T05:08:17.227

3

Bash, 87 bytes

Without sed:

f(){ printf %$1s|tr \  $2;}
c=${1//o/`f ${#1} B`
}
echo "${c//re/ `f $[${#1}-2] F` 
}"

Thanks to @manatwork.

With sed (90 bytes):

f(){ printf %$1s|tr \  $2;}
echo $1|sed "s/o/`f ${#1} B`\n/g;s/re/ `f $[${#1}-2] F` \n/g"

Green

Posted 2019-01-04T01:09:34.990

Reputation: 31

Could you show us some sample usage? I'm a bit confused by your function expecting 2 parameters. – manatwork – 2019-01-06T18:34:44.123

You write that into a script called test.sh. Then, you call test.sh from the command line as follows: bash test.sh oreoorererereoo. f is needed to repeat the character $2 $1 number of times – Green – 2019-01-06T18:41:42.037

Oops. I completely misunderstood function f. Some further minor changes could be made there: Try it online!

– manatwork – 2019-01-06T18:55:20.100

Nice! Thank you for your suggestions! I will incorporate them into my answer. :) – Green – 2019-01-06T19:16:38.740

For the sed based one you could use sed "…"<<<$1 instead of echo $1|sed "…". – manatwork – 2019-01-06T19:45:13.243

175 bytes. – Dennis – 2019-01-07T04:15:53.483

160 bytes – Nahuel Fouilleul – 2019-01-08T08:27:58.647

with zsh, 50 bytes

– Nahuel Fouilleul – 2019-01-08T08:33:25.657

3

Ruby, 62 60 bytes

->s{s.gsub /./,?r=>" #{(?**z=s.size)[0..-3]}
",?o=>?O*z+?\n}

Try it online!

Uses O for the cookie, * for the filling.

-1 thanks to @manatwork pointing out a silly mistake and another -1 due to relaxation of the rules about whitespaces.

Kirill L.

Posted 2019-01-04T01:09:34.990

Reputation: 6 693

No need for parenthesis around .gsub's parameters. – manatwork – 2019-01-09T20:54:02.187

$/ is an alias for ?\n. – Value Ink – 2019-11-19T05:40:52.320

2

Dart, 120 106 107 bytes

f(s)=>s.replaceAll('o',''.padRight(s.length,'#')+'\n').replaceAll('re',' '.padRight(s.length-1,'-')+' \n');

Try it online!

  • +1 byte : Added trailing whitespace

Elcan

Posted 2019-01-04T01:09:34.990

Reputation: 913

This is invalid: "The whitespace padding on each side of the filling is required" – NieDzejkob – 2019-01-06T15:15:27.317

Oh, never mind then, I'll correct it soon. Thanks for the info, I missed it – Elcan – 2019-01-06T22:14:11.447

2

Python 2, 77 76 72 bytes

lambda i:'\n'.join((x*len(i),' '+x*(len(i)-2))[x>'o']for x in i if'e'<x)

Try it online!

The outer part of the cookie is 'o' and the filling is 'r'.

ElPedro

Posted 2019-01-04T01:09:34.990

Reputation: 5 301

68 bytes. Although I doubt if you can really omit the trailing spaces, the spec does say "The whitespace padding on each side of the filling is required"... – Erik the Outgolfer – 2019-01-05T22:35:45.840

Thanks @EriktheOutgolfer. Thought a lambda would be shorter! Guess in this case not. Had missed the requirement about the mandatory trailing space on the filling. Really can't see the point with an ascii art challenge but if that's what OP requires then I guess my answer is invalid anyway. – ElPedro – 2019-01-06T00:13:00.903

Now corrected... – ElPedro – 2019-01-06T00:18:47.350

Why bring it back to 76? Just put +' ' after (l-2). Also, you have a typo, *' ' must be +' '. – Erik the Outgolfer – 2019-01-06T00:23:06.067

That's what I did with my current solution. Will take a closer look at your hints tomorrow (later today). It's late here and I have been shoveling snow all day so too tired for golf. Thanks for the tips though :) – ElPedro – 2019-01-06T00:27:56.410

It's not a strange reason, if anything it's expected, since most of the like... three existing ASCII-art languages, as well as the matrix based languages output a trailing space anyway. Plus, for some languages the symmetry may even help – ASCII-only – 2019-01-06T01:10:05.110

I guess that's why in the majority of challenges, trailing whitespace is optional. – ElPedro – 2019-01-06T08:38:20.120

Well, it's optional now (yay) – ASCII-only – 2019-01-07T23:32:58.910

2

C# (.NET Core), 143 bytes

Without LINQ.

p=>{var q="";foreach(char c in p){if(c!='e'){for(var j=0;j<p.Length;j++)q+=(j<1|j>p.Length-2)&c>'q'?" ":c<'p'?"█":"░";q+="\n";}}return q;};

Try it online!

Destroigo

Posted 2019-01-04T01:09:34.990

Reputation: 401

2

Clojure, 137 bytes

(fn[f](let[w(count f)r #(apply str(repeat % %2))](clojure.string/join"\n"(replace{\o(r w \#)\e(str \ (r(- w 2)\-) \ )}(remove #{\r}f)))))

I'm not using the nice characters in the printout in the golfed version since those are expensive. Returns a string to be printed.

Try it online!

See below for explanation.

Pre-golfed:

; Backslashes indicate a character literal
(defn oreo [format-str]
  (let [width (count format-str)

        ; A helper function since Clojure doesn't have built-in string multiplication
        str-repeat #(apply str (repeat % %2))

        ; Define the layers
        cookie (str-repeat width \█)
        cream (str \ (str-repeat (- width 2) \░) \ )]

    (->> format-str ; Take the input string,
         (remove #{\r}) ; remove r for simplcity,
         (replace {\o cookie, \e cream}) ; replace the remaining letters with the layers,
         (clojure.string/join "\n")))) ; and join the layers together with newlines

Carcigenicate

Posted 2019-01-04T01:09:34.990

Reputation: 3 295

2

x86-64 machine code (Linux), 97 bytes

0000000000000000 <oreo_asm>:
   0:   56                      push   %rsi
   1:   57                      push   %rdi

0000000000000002 <len>:
   2:   48 ff c7                inc    %rdi
   5:   80 3f 00                cmpb   $0x0,(%rdi)
   8:   75 f8                   jne    2 <len>
   a:   49 89 fc                mov    %rdi,%r12
   d:   5f                      pop    %rdi
   e:   49 29 fc                sub    %rdi,%r12
  11:   4d 31 f6                xor    %r14,%r14
  14:   eb 18                   jmp    2e <outer_loop.skip>

0000000000000016 <extra>:
  16:   41 c6 01 20             movb   $0x20,(%r9)
  1a:   c6 03 20                movb   $0x20,(%rbx)
  1d:   49 ff ce                dec    %r14
  20:   eb 06                   jmp    28 <outer_loop>

0000000000000022 <newline>:
  22:   c6 06 0a                movb   $0xa,(%rsi)
  25:   48 ff c6                inc    %rsi

0000000000000028 <outer_loop>:
  28:   49 ff c6                inc    %r14
  2b:   48 ff c7                inc    %rdi

000000000000002e <outer_loop.skip>:
  2e:   44 8a 07                mov    (%rdi),%r8b
  31:   41 80 f8 65             cmp    $0x65,%r8b
  35:   74 df                   je     16 <extra>
  37:   45 84 c0                test   %r8b,%r8b
  3a:   74 23                   je     5f <done>
  3c:   48 89 f3                mov    %rsi,%rbx

000000000000003f <inner_loop>:
  3f:   44 88 06                mov    %r8b,(%rsi)
  42:   49 89 f1                mov    %rsi,%r9
  45:   48 ff c6                inc    %rsi
  48:   48 31 d2                xor    %rdx,%rdx
  4b:   48 89 f0                mov    %rsi,%rax
  4e:   48 2b 04 24             sub    (%rsp),%rax
  52:   4c 29 f0                sub    %r14,%rax
  55:   49 f7 f4                div    %r12
  58:   48 85 d2                test   %rdx,%rdx
  5b:   74 c5                   je     22 <newline>
  5d:   eb e0                   jmp    3f <inner_loop>

000000000000005f <done>:
  5f:   5e                      pop    %rsi
  60:   c3                      retq

This x86-64 function takes in the pointer to the input string in rsi and builds the output starting at the pointer in rdi (these are the registers used to pass the first two arguments from a C function on Linux). For convenience, I've written a C++ wrapper for this which also does nice input sanitization and prints the output. That code can be located here. This also shows the original nasm syntax assembly I wrote for this function (as well as the non-golfed version I got working first).

A few things to note is that this code doesn't respect any callee saved registers, which means that the C++ code likely will crash if run for a while after calling this function. On my machine it doesn't, but that's rather surprising. I also don't add a null byte to delimit the output string, and instead the space allocated for the output string is pre-filled with bytes. (If this isn't allowed I can add the null terminator at a cost of 3 bytes).

The logic for this code is essentially counting the length of the string, then building a line of this length for each 'o' and 'r' characters seen in the input string, and then for any 'e' character seen, replacing the first and last characters on the previous line with space characters.

I can't find anywhere online to compile and run a mix of C++ and nasm source code, so I might write some small wrapper code for this to prove it works. Otherwise you should be able to compile and run this with the makefile in the link I gave with the command:

$ make oreo ASM_FILE=oreo_golf.nasm
$ ./oreo oreoorererereoo --use_asm

I was able to format the assembly to something acceptable by gcc, so try it online!

davey

Posted 2019-01-04T01:09:34.990

Reputation: 321

1Oh my, now this is an entry! – GammaGames – 2019-01-08T15:09:01.117

2

Sed, 89 characters

(86 characters code + 3 characters command line option)

h;s/./E/g;H;g;s/\n//;:b;s/(o|re)([ore]+)(E*)/\1\3\n\2\3/;tb;s/o//g;s/reE(E*)E/ \L\1 /g

Commented with example for input “oreo”:

h        # copy to hold space
s/./E/g  # change into cookie: EEEE
H        # append to hold space
g        # copy back to pattern space: oreo␤EEEE
s/\n//   # remove the newline: oreoEEEE

:b                                 # split the os and res in separate lines
  s/(o|re)([ore]+)(E*)/\1\3\n\2\3/ # repeating the EEEE for each:
tb                                 # oEEEE␤reEEEE␤oEEEE

s/o//g                # remove the os: EEEE␤reEEEE␤EEEE
s/reE(E*)E/ \L\1 /g   # remove the res, cut edge, change fill: EEEE␤ ee ␤EEEE

Sample run:

bash-4.4$ sed -r 'h;s/./E/g;H;g;s/\n//;:b;s/(o|re)([ore]+)(E*)/\1\3\n\2\3/;tb;s/o//g;s/reE(E*)E/ \L\1 /g' <<< oreoorererereoo
EEEEEEEEEEEEEEE
 eeeeeeeeeeeee 
EEEEEEEEEEEEEEE
EEEEEEEEEEEEEEE
 eeeeeeeeeeeee 
 eeeeeeeeeeeee 
 eeeeeeeeeeeee 
 eeeeeeeeeeeee 
EEEEEEEEEEEEEEE
EEEEEEEEEEEEEEE

Try it online!

manatwork

Posted 2019-01-04T01:09:34.990

Reputation: 17 865

I didn't expect an entry like that, creative! – GammaGames – 2019-01-11T15:04:51.623

Same byte count but with newlines - Try it online! – Logern – 2019-01-11T18:52:54.560

@Logern, thanks for playing with it. This brought to my attention that the TIO code was still the first version, which didn't handled input “re” correctly. – manatwork – 2019-01-11T19:02:07.430

2

C (gcc), -D$=putchar(33 + 88 = 102 bytes

O(char*r){for(char*e,*o=r,x;*r;$-x),$-23))for(x=*r++>111,e=x?$-1),r++,o+1:o;*++e;$+x));}

Try it online!

Logern

Posted 2019-01-04T01:09:34.990

Reputation: 845

2

APL (Dyalog Extended), 22 bytesSBCS

Anonymous tacit prefix function. Cookies are o, cream is r.

'^rr'⎕R' '⍤1≢⊢⍤/⍪~'e'⍨

Try it online!

 swap the input for:

'e' this letter

~ remove all the "e"s from:

 the columnised argument

⊢⍤/ replicate that single column to be as many columns as:

 the tally of characters in the input

⍤1 on each row (lit. on each 1D sub-array):

'^rr'⎕R' ' PCRE Replace leading "rr" with a single space

Adám

Posted 2019-01-04T01:09:34.990

Reputation: 37 779

2

Brainfuck, 276 268 bytes

Technicaly as the brainfuck only has 8 instructions, that means it needs only 3 bits per character instead of 8 (that also means we could encode brainfuck in base64 with exactly 2 instructions per character), but I'll play fair and say it's 268 bytes long.

I was afraid of using more cells to set up the values to be displayed, so it can probably be shortened, at least I used one to get a shorter solution.

It was a fun challenge, thanks!

Edit: now featuring the 3rd rule!

Edit: moving the line feed from the datapool to the display part of the code allowed me to get down to 268 bytes.

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

Here's a more readable version:

The datapool is made like so: [first character, placeholder value used to move the input character count, repeated character, last character]

>>+<,[//start of the loop
<++++++++++[>-----------<-]>-//"o"
[>-<,>>+<<[-]//if it's not a "o", skip one character and:

>>>>[>]//go to the data pool and search for the end
>++++[<++++++++>-]//put " " in memory
+>//put 1 in memory
>++++++++++[<+++++++++++>-]<+>//put a "o" in memory
>++++[<++++++++>-]<//put another " " in memory
[<]<<<//get back to the beginning of the data pool and get back to the program

]>[[-]//else (so if it's a "o"):

>>>[>]//go to the data pool and search for the end
>+++++++[<+++++>-]//put a "#" in memory
+>//put 1 in memory
>+++++++[<+++++>-]//put a "#" in memory
>+++++++[<+++++>-]<//put a "#" in memory
[<]<<//get back to the beginning of the data pool and get back to the program

]+<,>>+<<]//loop until the end of the input line and count the number of characters

>>//go to the number of characters variable
--//substract 2 to it because the first and last characters take one space each
[>>>+<<<-]//copy the value to the next place
>>[.>//start of the loop and display of the first character
-[>>>>+<<<<->.<]//display of the repeated character while copying the character count to the next line
>>.//display of the last character
[-]++++++++++.//display a line feed
>]//loop until the end of the data pool

it works on copy.sh/brainfuck with default settings (link)

Xaetral

Posted 2019-01-04T01:09:34.990

Reputation: 21

Fun language, nice entry! :) – GammaGames – 2019-07-22T03:59:12.747

1Oops, it looks like it breaks the third rule! The output isn't as wide as the input :s – GammaGames – 2019-07-22T14:50:11.090

ah sorry, I didn't read that one, thanks I'm gonna work on that – Xaetral – 2019-07-22T20:54:53.993

alright the only case where the result is not the expected one is "o" "re" outputs 2 spaces and "" outputs nothing but "o" is not doable with the method I chose because the repeated character should be negative here – Xaetral – 2019-07-23T10:19:52.200

1

SNOBOL4 (CSNOBOL4), 136 bytes

	S =INPUT
	N =SIZE(S)
S	S ('o' | 're') . X REM . S	:F(END)
	OUTPUT =IDENT('o',X) DUPL(X,N)	:S(S)
	OUTPUT =' ' DUPL(0,N - 2) ' '	:(S)
END

Try it online!

Giuseppe

Posted 2019-01-04T01:09:34.990

Reputation: 21 077

1

Batch, 133 bytes

@set/ps=
@set o=%s:r=o%
@set o=%o:e=o%
@set r=%o:o=-%
@set r= %r:~2%
@set s=%s:e= %
@for %%c in (%s:o=o %)do @call echo %%%%c%%

Takes input on STDIN. Explanation:

@set/ps=

Input the string.

@set o=%s:r=o%
@set o=%o:e=o%

Make a copy of the string with all of the rs and es replaced with os.

@set r=%o:o=-%
@set r= %r:~2%

Make a copy of the string of os, change them to -s and replace the first two with a space.

@set s=%s:e= %
@for %%c in (%s:o=o %)do @call echo %%%%c%%

Change the es into spaces and also add a space after each o, allowing the os and rs to be iterated over, printing the appropriate string each time.

Neil

Posted 2019-01-04T01:09:34.990

Reputation: 95 035

1

CJam, 27 bytes

q:T'e-{i2%T,'9*_:)2>S\+?N}/

Try it online!

Explanation:

q                            read input:                    | "oreoo"
 :T                          store in variable T            | "oreoo", T="oreoo"
   'e-                       remove all 'e' characters:     | "oroo"
      {                  }/  for each character:            | 'o
       i                       get Unicode value:           | 79
        2%                     modulo 2:                    | 1
          T                    push original input:         | 1 "oreoo"
           ,                   get length:                  | 1 5
            '9*                repeat '9' that many times:  | 1 "99999"
               _               duplicate:                   | 1 "99999" "99999"
                :)             increment every character:   | 1 "99999" ":::::"
                  2>           remove first two characters: | 1 "99999" ":::"
                    S\+        prepend a space:             | 1 "99999" " :::"
                       ?       conditional:                 | "99999"
                        N      add a newline:               | "99999" N
                             (implicit output)              | "99999" N " :::" N "99999" N "99999" N

Esolanging Fruit

Posted 2019-01-04T01:09:34.990

Reputation: 13 542

This breaks the rules: "The whitespace padding on each side of the filling is required" – NieDzejkob – 2019-01-06T15:19:08.793

Sorry, I allowed the optional trailing whitespaces. Nice entry! – GammaGames – 2019-01-07T03:27:49.533

1

Lua, 112 bytes

s=io.read()for t in s:gmatch"."do io.write(t=="o"and t:rep(#s).."\n"or(t=="r"and" "..t:rep(#s-2).." \n"or""))end

Explanation

s = io.read() -- Reads the input
for t in s:gmatch(".") do -- For each character in the input, call it 't' and enter the loop
 io.write(t=="o" and t:rep(#s).."\n" or (t=="r" and " "..t:rep(#s-2).." \n" or ""))

          t=="o" and  -- if 't' is equal to "o" then
                     t:rep(#s).."\n"  -- you have to write 't' repeated N times, where N is
                                      -- is the size of the input s, appended by a new line
                                     or (t=="r" and  -- else, if 't' is equal to "r" then
                                                    " "..t:rep(#s-2).." \n"  -- write a space, followed by 't' repeated N-2 times,
                                                                             -- where N is the size of the input.
                                                                             -- followed by a space and a new line.
                                                                            or "" -- else, just don't write anything.

end

Try it online!

Visckmart

Posted 2019-01-04T01:09:34.990

Reputation: 151

1

JavaScript, 70 bytes

x=>x.replace(/()()o|re/g,(_,o=1,s=' ')=>s.padEnd(x.length-o,+o)+s+`
`)

Try it online!

Or... If we're allowed to use other characters for whitespace, we can get it down to 65 bytes:

x=>x.replace(/()()o|re/g,(_,o=1,s=' ')=>s.padEnd(x.length-o,+o)+s+`
`)

Try it online!

...but I don't think that counts.

Yair Rand

Posted 2019-01-04T01:09:34.990

Reputation: 381

You're right, the padding has to be whitespace. Nice entry! – GammaGames – 2019-01-07T03:24:42.343

1

JavaScript (Node.js), 65 bytes

s=>s[R='replace'](/.e?/g,x=>s[R](/./g,x[0])[R](/^r|r$/g,' ')+`
`)

Try it online!

Thanks to Yair Rand, saves 2 bytes.

tsh

Posted 2019-01-04T01:09:34.990

Reputation: 13 072

You can save a byte by moving the last replace a bit earlier and removing the m flag: s=>s[R='replace'](/re|o/g,x=>s[R](/./g,x[0])[R](/^r|r$/g,' ')+ ) – Yair Rand – 2019-01-07T04:09:18.857

And another byte by using /.e?/g instead of /re|o/g . – Yair Rand – 2019-01-07T04:50:59.743

@YairRand Thanks. – tsh – 2019-01-07T05:40:39.403

1

Python 2, 70 75 bytes

lambda s:"\n".join((c*(len(s)-2*(c<'f'))).center(len(s))for c in s if'r'>c)

Try it online!

Uses 'o' for cookie, 'e' for filling. Returns a string.

EDIT: Saved 4 bytes thanks to Jo King.

Explanation:

# anonymous function, returns a string seperated by line breaks
lambda s:"\n".join(.......................................................)
                                                        # iterate through string, return each non-'r' character
                                                        for c in s if'r'>c
                    # duplicate the character until it is the length of the original string,
                    # minus two characters if the current letter is 'e'
                    c*(len(s)-2*(c<'f'))
                   # pad the string with spaces out to the length of the original string
                   (....................).center(len(s))

Triggernometry

Posted 2019-01-04T01:09:34.990

Reputation: 765

Sorry, the output should be a single string with line-breaks that can be printed or the program should print the output as it is processed. Arrays of strings aren't allowed, because of the "ascii" part. – GammaGames – 2019-01-07T19:13:24.593

@GammaGames Bluh, I should really read the rules more closely. Thank you! – Triggernometry – 2019-01-07T20:22:59.250

66 bytes – Jo King – 2019-01-08T03:32:12.720

1

Python 2, 64 bytes

s=input()
for c in s:
	if'n'<c:j='o'<c;print' '*j+c*(len(s)-2*j)

A full program which prints the result.

Try it online! Or see the test-suite.

Jonathan Allan

Posted 2019-01-04T01:09:34.990

Reputation: 67 804

1

Tcl, 216 bytes

set s [gets stdin]
set l [string map {o { o } re { re }} $s]
set n [string length $s]
foreach i $l {
if {$i eq "o"} {
puts [string repeat █ $n]
} elseif {$i eq "re"} {
puts " [string repeat ░ [expr {$n-2}]] "
}
}

Try it online!

Sean Woods

Posted 2019-01-04T01:09:34.990

Reputation: 31

1

Assume valid input and handle “o” and “r” and ignore “e”. For this split $s "" is shorter than string map. You only need $l once, so better skip the assignment to variable and use the expression directly in foreach. If you reverse the conditions, you can remove the spaces: $i eq "o""o"eq$i. Use if instead of elseif. no need the braces around expr's argument. Try it online!

– manatwork – 2019-01-09T19:26:50.690

1

Stax, 13 bytes

äNëY┬2-]‼Cv6╤

Run and debug it

Uses "o" and "r" characters for the layers.

recursive

Posted 2019-01-04T01:09:34.990

Reputation: 8 616

Oh man, you tied the current lowest! Really cool language too, I appreciate stack-based languages. – GammaGames – 2019-07-24T14:14:35.640

1

Excel, 93 bytes

=SUBSTITUTE(SUBSTITUTE(A4,"o",REPT("O",LEN(A4))&"
"),"re"," "&REPT("r",MAX(0,LEN(A4)-2))&"
")

MAX(0, is needed to handle o. Uses O and r.

Wernisch

Posted 2019-01-04T01:09:34.990

Reputation: 2 534

Very cool, though since it is an ascii challenge you should output the text in a stack (probably with CHAR(10) in excel), and you can replace the block characters with letters to cut down a few bytes :) – GammaGames – 2019-11-18T16:35:27.380

1@GammaGames, \n is included in code and bytecount. You need to switch on "Wrap text" to see them though. – Wernisch – 2019-11-19T11:41:30.680

Ah, gotcha. Thank you for your answer! – GammaGames – 2019-11-19T15:02:43.163