title: One more LUL and I'm out

text:
# Question
Title: One more LUL and I'm out
# Challenge description

On some channels on a popular streaming site twitch.tv a common message people tend to spam in chats to bait people into spamming "LUL" is

```
One more LUL and I'm out

```

LUL is a popular emote used to express that something funny happened on stream.

Soon dank memes showed their potential and a parody of the copy-pasta ensued:

```
One more "One more LUL and I'm out" and I'm out

```

Which is the same message nested in itself. Given a non-negative integer `N`, output the LUL-pasta nested `N` times in itself following the pattern below.

Standard rules apply, the shortest code in bytes wins.

# Sample input / output

```
0: One more LUL and I'm out
1: One more "One more LUL and I'm out" and I'm out
2: One more "One more "One more LUL and I'm out" and I'm out" and I'm out
...
7: One more "One more "One more "One more "One more "One more "One more "One more LUL and I'm out" and I'm out" and I'm out" and I'm out" and I'm out" and I'm out" and I'm out" and I'm out

```

# Notes

* Leading/trailing newlines are allowed
* Capitalization must be preserved
* Your code may be a full program or a function
* Instead of printing, you may return a string or its equivalent in your language of choice
* You may index from `1` instead of `0`

# Answer
> 29 votes
# Python 2, 56 bytes

```
lambda x:('"One more '*x+'LUL'+' and I\'m out"'*x)[1:-1]

```

Try it online!
It is 1-indexed

# Answer
> 20 votes
# JavaScript, ~~57~~ ~~56~~ ~~54~~ 52 bytes

```
f=q=>`One more ${q?`"${f(q-1)}"`:"LUL"} and I'm out`

```

Test Snippet:

```
f=q=>`One more ${q?`"${f(q-1)}"`:"LUL"} and I'm out`
```

```
<input type=number min=0 oninput=o.textContent=f(+this.value)>

<p id=o>
```

For some reason the snack snippet is being buggy when the input is `0`, but this works otherwise. Call it like `f(4)`.

### Explanation

```
f=q=>                      //declares a function f with argument q
`One more ... and I'm out` //hardcoded string
 ${q?`"${f(q-1)}"`:"LUL"}  // does recursion based on q
                           // if q is true, ie not 0, recurse
                           // else return "LUL"

```

# Answer
> 11 votes
# Befunge, 91 bytes

```
&:00p10p>"tuo m'I dna "1v
09p00-1<^g09p01-1_v#:g0<<vg
>>00g:#^_$>:#,_@  >$"LUL">" erom enO"

```

Try it online!

This is a breakdown of the source code with the various component parts highlighted.

We start by reading the repeat count *N*, and storing two duplicates of it in memory.
We then countdown the first *N*, pushing multiple copies of " and I'm out" onto the stack in reverse. Each additional copy is separated from the one before with a quote. The quote is generated with the sequence `90g` (basically reading a copy from the first line of the source), since that's the shortest way to do so.
Once this first loop is complete, we push "LUL" onto the stack (technically this is in reverse, but it obviously makes no difference when it's a palindrome).
Then we have another loop, wrapping across the right border, over to the left of playfield, and then back again. This time we're counting down the second *N*, pushing multiple copies of "One more " onto the stack (again in reverse). And again, each additional copy is separated from the one before with a quote.
Once the second loop is complete, the entire phrase is now on the stack (in reverse), so we simply need to write it out.

# Answer
> 6 votes
# C++, 118 + 16 = 134 bytes

```
auto L(int x){std::string k="One more LUL and I'm out",r=k;for(int i=0;i++<x;)r.replace(i*10-1,3,'"'+k+'"');return r;}

```

`#include<string>` \- +16

replaces "LUL" to the whole string N times.

Anyone has better golfs?

Try it online!

Massive thanks to **Kritixi Lithos** and **hvd**, for, uh, Massive help.

# Answer
> 6 votes
# 05AB1E, ~~30~~ 29 bytes

```
…LULIF“"One€£ ÿ€ƒ I'm€Ä"“}}¦¨

```

Try it online!

Different string-types doesn't seem to mix well, so for some reason I need to end the loop twice.

# Answer
> 5 votes
# Javascript (ES6), 68 Bytes

```
f=(x,y="LUL")=>~x?f(--x,`"One more ${y} and I'm out"`):y.slice(1,-1)

```

Call like `f(n)`.

You can also call it like `f(n, "LUL")` and replace LUL with any word you wish.

# Answer
> 5 votes
# , ~~39~~ 37 bytes

Two bytes with the help of @KritixiLithos for coming up with the substitution method

```
iOne more LUL and I'm outÀñÓLUL/"."

```

Try it online!

Hexdump:

```
00000000: 694f 6e65 206d 6f72 6520 4c55 4c20 616e  iOne more LUL an
00000010: 6420 4927 6d20 6f75 741b c0f1 d34c 554c  d I'm out....LUL
00000020: 2f22 122e 22                             /".."

```

# Answer
> 4 votes
# Java, 79 77 bytes

Golfed:

```
String f(int l){return"One more "+(l<1?"LUL":'"'+f(l-1)+'"')+" and I'm out";}

```

Ungolfed, with test:

```
public class OneMoreLulAndImOut {

  public static void main(String[] args) {
    OneMoreLulAndImOut obj = new OneMoreLulAndImOut();
    for (int i = 0; i < 8; ++i) {
      System.out.println(Integer.toString(i) + ": " + obj.f(i));
    }
  }

  String f(int l) {
    return "One more " + (l < 1 ? "LUL" : '"' + f(l - 1) + '"') + " and I'm out";
  }
}

```

Program output:

```
0: One more LUL and I'm out
1: One more "One more LUL and I'm out" and I'm out
2: One more "One more "One more LUL and I'm out" and I'm out" and I'm out
3: One more "One more "One more "One more LUL and I'm out" and I'm out" and I'm out" and I'm out
4: One more "One more "One more "One more "One more LUL and I'm out" and I'm out" and I'm out" and I'm out" and I'm out
5: One more "One more "One more "One more "One more "One more LUL and I'm out" and I'm out" and I'm out" and I'm out" and I'm out" and I'm out
6: One more "One more "One more "One more "One more "One more "One more LUL and I'm out" and I'm out" and I'm out" and I'm out" and I'm out" and I'm out" and I'm out
7: One more "One more "One more "One more "One more "One more "One more "One more LUL and I'm out" and I'm out" and I'm out" and I'm out" and I'm out" and I'm out" and I'm out" and I'm out

```

# Answer
> 3 votes
# Python, 79 bytes

I just wanted to do a recursive solution, even though it's longer than other answers.

```
x='"One more %s and I\'m out"'
f=lambda n,s=x:n and f(n-1,s%x)or(s%"LUL")[1:-1]

```

**Try it online**

# Answer
> 3 votes
## C#, 125 bytes

```
n=>{string f="One more {0} and I'm out",s=f;for(int i=0;i++<n;)s=string.Format(s,$"\"{f}\"");return string.Format(s,"LUL");};

```

# Answer
> 3 votes
## C#, ~~119~~ ~~85~~ 71 bytes

```
string m(int n)=>$"One more {(n<1?"LUL":$"\"{m(--n)}\"")} and I'm out";

```

*Saved 14 bytes thanks to @Luc*

# Answer
> 3 votes
# Mathematica, ~~69~~ 68 bytes

*Thanks to Martin Ender for saving 1 hard-to-find byte!*

```
""<>Nest[{q="\"",{"One more ",#," and I'm out"},q}&,"LUL",#+1][[2]]&

```

Unnamed function taking a nonnegative integer argument and returning a string. `Nest` applies a function repeatedly to an initial argument; in this case, the function is to surround its argument by the appropriate words and quotation marks. We start from `"LUL"` and iterate `N+1` times; that results in unwanted quotation marks enclosing the entire phrase, but `[[2]]` keeps only the stuff between them. At the end, `""<>` turns the resulting heavily nested list into a single string.

Previous submission:

```
""<>Nest[{o,q="\"",#,q,a}&,{o="One more ","LUL",a=" and I'm out"},#]&

```

# Answer
> 3 votes
# C, 140 111 bytes

My first attempt at a golfing question.. Golfed:

```
#define F printf(
#define P 1&&putchar(34)
int a=0;void q(n){a=a?a:n,n?n>0?F"One more "),n-P:n?n+P,F" and I'm out"):0:F"LUL"),n+a?q(n-1):0;}

```

I have come to realise is the wrong output since q(0) just gives LUL. The next attempt:

```
#define o(Q) O(Q,n?34:0);
#define O printf
void q(int n){o("One more %c")n?q(n-1):O("LUL"),o("%c and I’m out")}

```

Example program (tested with GCC on OSX):

```
#define o(Q) O(Q,n?34:0);
#define O printf
void q(int n) {o("One more %c")n?q(n-1):O("LUL"),o("%c and I’m out")}

int main() {
    q(0),putchar('\n');
    q(1),putchar('\n');
    q(2),putchar('\n');
    q(3),putchar('\n');

    return 0;
}

```

Gives output

```
One more LUL and I’m out
One more "One more LUL and I’m out" and I’m out
One more "One more "One more LUL and I’m out" and I’m out" and I’m out
One more "One more "One more "One more LUL and I’m out" and I’m out" and I’m out" and I’m out

```

# Answer
> 2 votes
## R, 100 97 92 bytes

*"One more recursive function and I'm out"*

```
f=function(n)paste("One more",`if`(n<1,"LUL",paste0('"',f(n-1),'"')),"and I'm out");cat(f(scan()))

```

Edit: Turns out that a non-recursive approach is slightly shorter:

```
x="One more ";y=" and I'm out";cat(x,rep(c('"',x),n<-scan()),"LUL",rep(c(y,'"'),n),y,sep="")

```

# Answer
> 2 votes
## Retina, 51 bytes

```
.+
$*00LUL1$&$*
0
"One more
1
 and I'm out"
^"|"$

```

Try it online!

# Answer
> 2 votes
## R, 97 bytes

```
function(n){s="One more LUL and I'm out";while(n){s=sub("LUL",paste0('"',s,'"'),s);n=n-1};cat(s)}

```

Ungolfed:

```
function(n) {
  s = "One more LUL and I'm out";
  while(n) {
    s = sub("LUL", paste0('"', s, '"'), s);
    n = n - 1
  };
  cat(s)
}

```

# Answer
> 2 votes
# PowerShell, ~~72~~ 67 bytes

```
"$('"One more '*($c=1+"$args"))LUL$(' and I''m out"'*$c)".Trim('"')

```

Try it online!

# Answer
> 2 votes
# Japt, 39 bytes

*Thank you @ETHproductions for helping.*

```
`"O Ú `p°U +"LUL"+` d I'm t"`pU)s1J

```

Try it here!

# Answer
> 2 votes
# Ruby, 51 bytes

One-indexed. Try it online

```
->n{['One more ']*n*?"+'LUL'+[" and I'm out"]*n*?"}

```

# Answer
> 2 votes
# Go, ~~104~~ 82 bytes

```
func f(n int)string{if n<0{return"LUL"}
return`One more "`+f(n-1)+`" and I'm out`}

```

Attempt This Online!

* -22 bytes by @Steffan: string concat instead of `Sprintf`

# Answer
> 1 votes
## Lua, 101 bytes

```
i,f,g='"One more ',' and I\'m out"',io.read()+1 print((i:rep(g).."LUL"..f:rep(g)):sub(2,g*24-(g-2)))

```

Obvious string attempt. Repeats `"One more` and `and I'm out"` exactly input + 1 times, with a `LUL` inbetween, then removes first and last quote.

# Answer
> 1 votes
# Stacked, 54 bytes

```
('"One more ' ' and I''m out"')*'LUL'join'^.|.$'εrepl

```

Try it here! Example usage of "function":

```
1
('"One more ' ' and I''m out"')*'LUL'join'^.|.$'εrepl
out

```

---

One for 56 bytes:

```
@n'One more LUL and I''m out':@o['LUL' '"'o'"'+ +repl]n*

```

# Answer
> 1 votes
# PHP, ~~69~~ 66 bytes

Note: uses IBM-850 encoding

```
for($o=LUL;~$argn--;$d=~¦)$o="One more $d$o$d and I'm out";echo$o;

```

Run like this:

```
echo 2 | php -nR 'for($o=LUL;~$argn--;$d=~¦)$o="One more $d$o$d and I'"'"'m out";echo$o;';echo
> One more "One more "One more LUL and I'm out" and I'm out" and I'm out

```

# Explanation

```
for(
  $o=LUL;                           # Start with output string "LUL".
  ~$argn--;                         # Loop until N is -1.
  $d=~¦                             # Set delimiter to `"` after first
                                    #   iteration.
)
  $o="One more $d$o$d and I'm out"; # Add text with previous output
                                    #   embedded, between delims.

echo$o;                             # Output resulting string.

```

# Answer
> 1 votes
# Haskell, 51 bytes

Indexes from 1.

```
f 0="LUL";f n="One more \""++f(n-1)++"\" and I'm out"

```

# Answer
> 1 votes
# CJam, ~~51~~ 49 bytes

```
" and I'm out\"""\"One more "li1+_@*"LUL"+1>@@*W<

```

Try it online

### Ungolfed:

```
" and I'm out\""   "\"One more " // Push two strings to the stack
     l i 1 +                     // Read a number and add 1
     _ @                         // Copy number and rise '"One more ' to the top
     *                           // Multiply '"One more ' by a number
     "LUL" +                     // Add "LUL"
     1>                          // Chop the first quote
     @@                          // Push the result down
     *                           // Multiply ' and I\'m out"' by a number
     W<                          // Chop the last quote

```

# Answer
> 1 votes
# Python 3, 68 Bytes

`def f(a):return('"One more '*a+'LUL'+(' and I%sm out"'%"'")*a)[1:-1]`

# Answer
> 1 votes
# Ruby, 70 bytes

```
def l x,t="LUL";x.times{t='"One more %s and I\'m out"'%t};t[1..~1];end

```

Simply loops for the amount it's given, surrounding the last string via a format string each time.

Index starts at one.

# Answer
> 1 votes
## Mathematica, ~~65~~ 63 Bytes

```
Nest["\"One more "<>#<>" and I'm out\""&,"LUL",#]~StringTrim~_&

```

Two bytes off by noticing the challenge allows 1-indexing.

# Answer
> 1 votes
## Groovy, 54 bytes

```
{x->('"One more '*x+'LUL'+' and I\'m out\"'*x)[1..-2]}

```

Pretty straightforward, same as the python answer but 2 bytes shorter. It is also 1-indexed.

Try it Online!

# Answer
> 1 votes
# PHP

Hello, i found so far two ways for doing this.

The replacement way 1-indexed **(121 bytes)**.

```
function f($x){$v='One more LUL and i\'m out';$t=$v;for($i=1;$i<=$x;$t=str_replace('LUL','"'.$t.'"',$v),$i++);return $t;}

```

The recursive way **(86 bytes)**.

```
function r($n){$v=($n==0)?'LUL':'"'.r($n-1).'"';return'One more '.$v.' and i\'m out';}

```

# Answer
> 1 votes
# Tcl, 91 bytes

```
set g [set f "One more LUL and I'm out"]
time {regsub -all LUL $f "\"$g\"" f} $argv
puts $f

```

Try it online!

# Answer
> 1 votes
# C++, 80 + 16 = 96 bytes

```
std::string L(int c){return"One more "+(c?'"'+L(--c)+'"':"LUL")+" and I'm out";}

```

`#include<string>` \- +16

Ungolfed:

```
std::string LUL(int count) {
    return "One more " + (count? ('"' + LUL(--count) + '"') : "LUL") + " and I'm out";
}

```

Calls itself recursively and uses string addition. Pretty straight forward. I mean what else can I say? Even the ungolfed version is essentially a one liner.

Try it online!

# Answer
> 1 votes
# Common Lisp, ~~90~~ ~~89~~ ~~108~~ ~~105~~ 103 bytes

```
(set's"One more LUL and I'm out")(dotimes(n(read)(princ s))(set's(format()"One more ~a and I'm out"s)))

```

### Other solution (91 bytes)

Using Winny's solution in Racket (my is not exact copy)

```
(defun l(n)(if(< n 0)'LUL(format()"One more ~:[~a~;\"~a\"~] and I'm out"(> n 0)(l(1- n)))))

```

usage:

```
(format t"~a"(l 2))

```

Ideas for improvement are welcomed.

# Answer
> 1 votes
# Cheddar, 71 bytes

```
i->('One more "'*i).slice(0,-1)+'LUL '+('and I\'m out" '*i).slice(0,-2)

```

Try it online!

# Answer
> 1 votes
# Jelly, 39 bytes

First Jelly submission! Can probably slice off a few by encoding the strings, but I couldn't get it working with the spaces yet.

```
“"One more ”;;“ and I'm out"”
“LUL”Ç¡ḊṖ

```

A 0-indexed version needs an additional `Ç` after the `Ç¡`.

Try it online!

**Explanation** will follow soon!

# Answer
> 1 votes
# Haskell - 73 bytes

```
n!s=[1..n]>>s
f n=init(n!"One more \"")++" LUL"++tail(n!"\" and I'm out")

```

I wonder if there something I could use besides init and tail to save a few bytes.

Try it here!

# Answer
> 1 votes
# Perl 5, 55 + 1 (-p) = 56 bytes

```
$_='"One more 'x++$_.LUL.' and I\'m out"'x$_;s/^.|.$//g

```

Try it online!

# Answer
> 1 votes
# Stax, 27 bytes

```
âΔ▓♥CPM9C"4█é¢┐╥äΔ↔╖◄b)►┤≤▐

```

Run and debug it

This is a recursive program that decrements the input on each call.

I discovered a bug in stax writing this program. I'll fix the bug sooner or later, but I won't incorporate it into this solution, as it seems unsporting to me.

# Answer
> 1 votes
## Microsoft Excel, 69

Cells:

* `A1` \- input
* `A2` \- `One more "`
* `A3` \- `" and I'm out`
* `A4` \- `""` (Otherwise I'd have to escape them)
* Wherever - `=SUBSTITUTE(REPT(A2,A1)&REPT(A3,A1),A4,"LUL"`

# Answer
> 1 votes
# International Esoteric Phonetic Language, 80 bytes

```
<f>/qubʌɔ|a|"\""u1z<f>"\""uɔ|b||a|ʍu|b|ɖbuʈ\"LUL"w" and I'm out""One more "ɪ<f>""o

```

Recursive implementation that decrements the input number when recursing.

## Explanation:

```
<f>/qubʌɔ|a|"\""u1z<f>"\""uɔ|b||a|ʍu|b|ɖbuʈ\"LUL"w" and I'm out""One more "ɪ<f>""o
<f>/                                                                              (fun def)
    qu                                                                            (one more)
      bʌɔ|a|                                                                      (if index == 0, continue, else jump to else)
           "\""u                                                                  (quote)
                1z                                                                (decrement index)
                  <f>                                                             (recurse)
                     "\""u                                                        (quote)
                          ɔ|b|                                                    (skip to end)
                              |a|                                                 (else)
                                 ʍu                                               (LUL)
                                   |b|                                            (end)
                                      ɖbuʈ\                                       (and i'm out)
                                           "LUL"w                                 (wegister going wwww LUL)
                                                 " and I'm out""One more "        (strings)
                                                                          ɪ<f>    (input and call)
                                                                              ""o (print newline)

```

# Answer
> 1 votes
# Husk, 27 bytes

```
!¡σ"LUL"s₁₁
¨Ønø LULÄdİ'møo

```

Try it online!

Does infinite replacement of LUL and indexes into it.

1-indexed.

# Answer
> 1 votes
# YASEPL, 161 bytes

```
=a'(=s)"One more "=u)apostrophe=m)" and I"ſuſ"m out"=x)"LUL"=n=q$34»!a@!sſq!-!m)qſ" and I"ſuſ"m out"=x)"One more LUL"ſ" and I"ſuſ"m out"`1!b;s,a~#x;m,a<

```

# Answer
> 0 votes
# Perl 6, 57 bytes

```
{substr "\"One more "x$_~"LUL"~" and I'm out\""x$_,1,*-1}

```

Slightly more interesting, but 58 bytes:

```
{join "LUL",("One more "," and I'm out"Xxx$_)».join('"')}

```

# Answer
> 0 votes
## Clojure, 84 bytes

```
#(nth(iterate(fn[s](str"One more \""s"\" and I'm out"))"One more LUL and I'm out")%)

```

Argh why isn't the first `LUL` in quotes? :( Almost correct in 63 bytes:

```
#(nth(iterate(fn[s](str"One more \""s"\" and I'm out"))"LUL")%)

```

# Answer
> 0 votes
# GameMaker Language, 106 bytes

1-indexed

```
s='LUL'for(a=0,a<argument0;a++)s='"One more '+s+" and I'm out\""return string_copy(s,2,string_length(s)-2)

```

# Answer
> 0 votes
# Clojure, 90 bytes

```
(fn c[n](if(= n -1)"LUL"(let[q(if(> n 0) \")](str"One more "q(c(dec n))q" and I'm out"))))

```

Written and golfed on my phone on a soft keyboard using the "Clojure REPL" app. That was sure a treat.

Explicitly recursive solution. Inserts the results of recursing into the "template string".

Pregolfed:

```
(defn lul [n]
  (if (= n -1)
    "LUL"
    (let [quote? (if (> n 0) \")]
      (str "One more "
            quote? (lul (dec n)) quote?
           " and I'm out" ))))

```

# Answer
> 0 votes
# Octave, ~~72~~ 70 bytes

```
@(n)[{'"One more '}{o=!(1:n)+1} "LUL " {"and I'm out\" "}{o}](2:end-2)

```

1 based index

Try It Online!

# Answer
> 0 votes
# PowerShell, 88 bytes

```
for($d=($s="One more LUL and I'm out");$i++-lt$args[0]){$d=$d.Replace("LUL","`"$s`"")}$d

```

# Answer
> 0 votes
## Batch, 95 bytes

```
@set s=LUL
@for /l %%i in (0,1,%1)do @call set s="One more %%s%% and I'm out"
@echo %s:~1,-1%

```

0-indexed, because that means it works even if you forget to pass a parameter. (The 1-indexed version would just print `U` in that case, which looks silly.)

# Answer
> 0 votes
# C#, ~~102~~ 90 bytes

~~`string l(string s,int n){return n<0?s.Substring(1,s.Length-2):l($"\"One more {s} and I'm out\"",--n);}`~~

Recursive, call with ~~`l("LUL",7);`~~

**EDIT**

Thank you for pointing out that it is illegal to pass input not specified in the challenge. Here is the fixed version that only takes an integer `N`:

```
string l(int N){return N<0?"":$"One more \"{l(--N)}\" and I'm out".Replace("\"\"","LUL");}

```

# Answer
> 0 votes
# Racket, ~~88~~ 87 bytes

```
(define(f n)(format"One more ~a and I'm out"(if(= n 0)'LUL(format"\"~a\""(f(- n 1))))))

```

## Ungolfed

```
(define (f n)
  (format "One more ~a and I'm out"
          (if (= n 0)
              'LUL
              (format "\"~a\"" (f (- n 1))))))

```

## Unit tests

```
(module+ test
  (require rackunit)
  (check-equal? (f 0) "One more LUL and I'm out")
  (check-equal? (f 1) "One more \"One more LUL and I'm out\" and I'm out")
  (check-equal? (f 2) "One more \"One more \"One more LUL and I'm out\" and I'm out\" and I'm out")
  (check-equal? (f 7) "One more \"One more \"One more \"One more \"One more \"One more \"One more \"One more LUL and I'm out\" and I'm out\" and I'm out\" and I'm out\" and I'm out\" and I'm out\" and I'm out\" and I'm out"))

```

# Answer
> 0 votes
# Scala, 63 bytes

```
(n:Int)=>("One more \""*n init)+"LUL"+("\" and I'm out"*n tail)

```

1-indexed

# Answer
> 0 votes
# C++, 183 bytes

Simply input N times you want 'One more LUL' nested.

```
#include <iostream>
#include <string>
#define s string
using namespace std;main(){int N;cin>>N;s a="LUL";s b="One more \"";s c="\"and I'm out";for(int i=0;i<N;i++){a=b+a+c;}cout<<a;}

```

Try Me Online!

# Answer
> 0 votes
# C++14, 90 bytes

As unnamed lambda modifying its input. Requires `s` to be `std::string` or alike.

```
[](auto&s,int i){s="LUL",++i;for(char c=0;i--;s="One more "+(c+s+c)+" and I'm out",c=34);}

```

Ungolfed and usage:

```
#include<string>
#include<iostream>

auto f=
[](auto&s,int i){
 s="LUL",++i;        //set basic LUL
 for(
  char c=0;          //first string concat without quotes
  i--;
  s="One more "+(c+s+c)+" and I'm out", //string concat
  c=34                                  //set c to "
 );
}
;

int main(){
 std::string s;
 f(s,0);
 std::cout << s << std::endl;
 f(s,1);
 std::cout << s << std::endl;
 f(s,2);
 std::cout << s << std::endl;
 f(s,3);
 std::cout << s << std::endl;
}

```

# Answer
> 0 votes
# Objective-C, 218

```
#define p NSString stringWithFormat
-(NSString *)f:(int)a{NSString *o=@"One more ",*k=@" and I'm out",*i=[p:@"%@LUL%@",o,k],*s=@"";for(int j=-a;a-->j+1;s=[p:@"%@\"%@",s,a>0?o:a<0?k:i]);return [s substringFromIndex:1];}

```

Not the most beautiful language to golf in, but I had fun

# Answer
> 0 votes
## QBIC, 72 bytes

```
:[a|X=X+@One more `+chr$(34)┘Z=Z+chr$(34)+@ and I'm out`]Z=X+A+@LUL`+B+Z

```

The `chr$(34)` for the quotes is particularly costly, I need to fix a bug in the interpreter to make them work inside a string literal...

Sample output:

```
Command line: 0
One more LUL and I'm out

Command line: 3
One more "One more "One more "One more LUL and I'm out" and I'm out" and I'm out" and I'm out

```

# Answer
> 0 votes
# dc, 82 bytes

```
?dsasw[[LUL ]P]se[34dP]sr[lalw>r[One more ]nlad1-dsar1=e0<y[and I'm out]nP32P]dsyx

```

Might as well add an answer in `dc`. This is 1-indexed.

"Calculate" it on the Internet!

# Answer
> 0 votes
# Python, 78 bytes

```
f=lambda n:'One more "'*(n-1)+"One more LUL and I'm out"+'" and I\'m out'*(n-1)

```

# Answer
> 0 votes
# k, 58 bytes

Indexing starts at `0`. This is a recursive function.

```
`0:`c${"One more ",$[x;34,o[x-1],34;"LUL"]," and I'm out"}

```

Try it online.

# Answer
> 0 votes
# GolfScript, 44 bytes

```
~"LUL"\{'"One more
 and I\'m out"'n/*}*(;);

```

Try it online!

1-indexed.

Explanation:

```
~"LUL"\{'"One more \n and I\'m out"'n/*}*(;); ("\n" is a newline)
~                                             Eval (input is the only stack element on program start)
 "LUL"                                        Push "LUL"
      \                                       Swap
       {'"One more \n and I\'m out"'n/*}      Push block:
        '"One more \n and I\'m out"'            Push "\"One more \n and I'm out\""
                                    n           Push n (default: newline)
                                     /          Split
                                      *         Join
                                        *     Repeat block
                                         (    Pop first element and push to stack
                                          ;   Pop
                                           )  Pop last element and push to stack
                                            ; Pop

```

# Answer
> 0 votes
# SOGL V0.12, 27 bytes

```
LUL”.I{" ž-┌πēj░ō|≥π┘⁴‘⁾}jk

```

Try it Here!

# Answer
> 0 votes
# FEU, ~~107~~ 97 bytes

```
Ep/v
a/One more LUL and I'm out
EP/v
u/a
/a/g
Ep/v
s/LUL/"One more LUL and I'm out"
EP/v
end
Ep/v

```

Try it online!

# Answer
> 0 votes
# Japt, 33 bytes

```
`O Ú {?Q²¬qßUÉ:`lª`u} d I'm t

```

Try it

# Answer
> 0 votes
# Vyxal, ~~34~~ 33 bytes

```
`"λŀ λƈ `*‛⇧Ṫ⇧+` λ¬ I'm λ₅"`?*+ḢṪ

```

Try it Online!

-1 thx to @steffan

# Answer
> 0 votes
# Thunno 2, 34 bytes

```
ʋLULs{‘"One Ḍḋ % and I'm out"‘Œ}ḣṫ

```

Attempt This Online!

#### Explanation

```
ʋLULs{‘...‘Œ}ḣṫ  # Implicit input
ʋLUL             # Push the string "LUL"
    s            # Swap so the input is back on top
     {      }    # Repeat input number of times:
      ‘...‘      # Push compressed template string
                 # `"One more % and I'm out"`
           Œ     # Replace the "%" with the
                 # next item on the stack
             ḣṫ  # Remove the first and last characters
                 # Implicit output

```

# Answer
> 0 votes
# TypeScript's type system, ~~100~~ 77 bytes

```
type F<N>=`One more ${N extends[1,...infer K]?`"${F<K>}"`:"LUL"} and I'm out`

```

Try it at the TS playground

This is a generic type `F<N>` where N is a unary number represented by a tuple type of 1s.

This is not tail recursive, so it only works for N \< 50. Here's a tail recursive version which works for N \< 1000:

# TypeScript's type system, 106 bytes

```
// @ts-ignore
type F<N,O="LUL",W="">=N extends[1,...infer K]?F<K,`One more ${W}${O}${W} and I'm out`,'"'>:O

```

Try it at the TS playground

---
Tags: code-golf, string
---


# Question
Title: Find the largest number that's adjacent to a zero
**Challenge:**

Take a vector / list of integers as input, and output the largest number that's adjacent to a zero.

**Specifications:**

* As always, optional input and output format
* You may assume that there will be at least one zero, and at least one non-zero element.

**Test cases:**

```
1 4 3 6 0 3 7 0
7

9 4 9 0 9 0 9 15 -2
9

-4 -6 -2 0 -9
-2

-11 0 0 0 0 0 -12 10
0

0 20
20

```

Good luck and happy golfing!

# Answer
# Jelly, 8 bytes

```
ṡ2ẠÐḟS€Ṁ

```

Try it online!

```
ṡ2            Overlapping pairs
  ẠÐḟ         Remove pairs without zeroes
     S€       Sum of each pair
       Ṁ      Maximum

```
> 3 votes

# Answer
# MATL, 10 bytes

```
t~5BZ+g)X>

```

Try it online! Or verify all test cases.

### Explanation

Let's take input `[-4 -6 -2 0 -9]` as an example.

```
t     % Input array. Duplicate
      %   STACK: [-4 -6 -2 0 -9],  [-4 -6 -2 0 -9]
~     % Logical negate. Replaces zeros by logical 1, and nonzeros by logical 0
      %   STACK: [-4 -6 -2 0 -9],  [0 0 0 1 0]
5B    % Push logical array [1 0 1] (5 in binary)
      %   STACK: [-4 -6 -2 0 -9], [0 0 0 1 0], [1 0 1]
Z+    % Convolution, maintaining size. Gives nonzero (1 or 2) for neighbours of
      % zeros in the original array, and zero for the rest
      %   STACK: [-4 -6 -2 0 -9], [0 0 1 0 1]
g     % Convert to logical
      %   STACK: [-4 -6 -2 0 -9], [0 0 1 0 1]
)     % Use as index into original array
      %   STACK: [-2 -9]
X>    % Maximum of array.
      %   STACK: -2
      % Implicitly display

```
> 20 votes

# Answer
# Haskell, ~~63~~ 43 bytes

```
f x=maximum[a+b|(a,b)<-tail>>=zip$x,a*b==0]

```

Thanks to @MartinEnder for 4 bytes!
> 11 votes

# Answer
# 05AB1E, 9 bytes

```
ü‚D€P_ÏOZ

```

**Explanation**

```
ü‚         # pair up elements
  D        # duplicate
   €P      # product of each pair (0 if the pair contains a 0)
     _     # logical negate, turns 0 into 1 and everything else to 0
      Ï    # keep only the pairs containing at least 1 zero
       O   # sum the pairs
        Z  # take max

```

Doesn't work in the online interpreter, but works offline.
> 10 votes

# Answer
# Pyth, 12 11 10 bytes

```
eSsM/#0,Vt

```

Forms pairs, filters by zero member, sorts by sum, returns largest.
> 9 votes

# Answer
## JavaScript (ES6), ~~59~~ ~~57~~ 56 bytes

```
let f =

l=>l.map((n,i)=>m=l[i-1]==0|l[i+1]==0&&n>m?n:m,m=-1/0)|m

console.log(f([1, 4, 3, 6, 0, 3, 7, 0]));       // 7
console.log(f([9, 4, 9, 0, 9, 0, 9, 15, -2]));  // 9
console.log(f([-4, -6, -2, 0, -9]));            // -2
console.log(f([-11, 0, 0, 0, 0, 0, -12, 10]));  // 0
console.log(f([3, 0, 5]));                      // 5
console.log(f([28, 0, 14, 0]));                 // 28
```

*Edit: saved 2 bytes thanks to Huntro*
*Edit: saved 1 byte thanks to ETHproductions*
> 7 votes

# Answer
# Python, 49 bytes

```
lambda a:max(sum(x)for x in zip(a,a[1:])if 0in x)

```

Tests are at **ideone**

Zips through the pairs, sums the ones containing any zero, returns the maximum.
> 7 votes

# Answer
## JavaScript (ES6), 53 bytes

```
a=>(m=-1/0,a.reduce((l,r)=>(m=l*r||l+r<m?m:l+r,r)),m)

```

Because I like using `reduce`. Alternative solution, also 53 bytes:

```
a=>Math.max(...a.map((e,i)=>e*a[++i]==0?e+a[i]:-1/0))

```
> 6 votes

# Answer
# PHP, ~~77~~ ~~68~~ 71 bytes

~~-3 bytes from anonymous,~~ -4 and -2 from MartinEnder

```
preg_match_all("#(?<=\b0 )\S+|\S+(?= 0)#",$argv[1],$m);echo max($m[0]);

```

run with `php -r '<code>' '<space separated values>'`
> 4 votes

# Answer
## Ruby, 51 bytes

```
->a{a.each_cons(2).map{|a,b|a*b!=0?-1.0/0:a+b}.max}

```

### usage

```
f=->a{a.each_cons(2).map{|a,b|a*b!=0?-1.0/0:a+b}.max}
p f[gets.split.map(&:to_i)]

```
> 4 votes

# Answer
# Java 7, ~~118~~ ~~105~~ 106 bytes

```
int d(int[]a){int i=0,m=1<<31,c;for(;++i<a.length;m=a[i]*a[i-1]==0&(c=a[i]+a[i-1])>m?c:m);return m;}

```

13 bytes saved thanks to *@cliffroot* by using an arithmetic approach instead. 1 additional byte thank to *@mrco* after he discovered a bug (the added test case `2, 1, 0` would return `2` instead of `1`).

**Ungolfed & test code:**

Try it here.

```
class M{
  static int c(int[] a){
    int i,
        m = a[i=0],
        c;
    for(; ++i < a.length; m = a[i] * a[i-1] == 0 & (c = a[i] + a[i - 1]) > m)
                           ? c
                           : m);
    return m;
  }

  public static void main(String[] a){
    System.out.println(c(new int[]{ 1, 4, 3, 6, 0, 3, 7, 0 }));
    System.out.println(c(new int[]{ 9, 4, 9, 0, 9, 0, 9, 15, -2 }));
    System.out.println(c(new int[]{ -4, -6, -2, 0, -9 }));
    System.out.println(c(new int[]{ -11, 0, 0, 0, 0, 0, -12, 10 }));
    System.out.println(c(new int[]{ 0, 20 }));
    System.out.println(c(new int[]{ 2, 1, 0 }));
  }
}

```

**Output:**

```
7
9
-2
0
20
1

```
> 4 votes

# Answer
# Jelly, ~~6~~ 5 bytes

```
SfµƝṀ

```

Try it online!

*-1 remembering it's not a dyadic chain*

```
  µƝ     For each pair of adjacent elements, monadically:
S        Sum the pair,
 f       and filter it to only element[s] in the pair.
    Ṁ    Take the maximum.

```
> 4 votes

# Answer
# Nekomata, 7 bytes

```
qᵗZđ+aṀ

```

Attempt This Online!

```
qᵗZđ+aṀ
q           Non-deterministically choose a contiguous subsequence
 ᵗZ         Check that it contains a 0
   đ        Unpair; check that its length is 2, and push the two elements
    +       Add
     a      All possible values
      Ṁ     Maximum

```
> 4 votes

# Answer
## CJam, 16 bytes

```
q~2ew{0&},::+:e>

```

Try it online! (As a test suite.)

### Explanation

```
q~    e# Read and eval input.
2ew   e# Get all (overlapping) pairs of adjacent values.
{0&}, e# Keep only those that contain a 0.
::+   e# Sum each pair to get the other (usually non-zero) value.
:e>   e# Find the maximum.

```
> 3 votes

# Answer
# MATLAB with Image Processing Toolbox, 32 bytes

```
@(x)max(x(imdilate(~x,[1 0 1])))

```

This is an anonymous function. Example use for the test cases:

```
>> f = @(x)max(x(imdilate(~x,[1 0 1])))
f =
  function_handle with value:
    @(x)max(x(imdilate(~x,[1,0,1])))

>> f([1 4 3 6 0 3 7 0])
ans =
     7

>> f([9 4 9 0 9 0 9 15 -2])
ans =
     9

>> f([-4 -6 -2 0 -9])
ans =
    -2

>> f([-11 0 0 0 0 0 -12 10])
ans =
     0

>> f([0 20])
ans =
    20

```
> 3 votes

# Answer
# Mathematica, ~~46~~ 43 bytes

*Saved 3 bytes due to @MartinEnder.*

```
Max[Tr/@Partition[#,2,1]~Select~MemberQ@0]&

```

Anonymous function. Takes a list of integers as input and returns an integer as output. Based off of the Ruby solution.
> 3 votes

# Answer
## R, 48 47 bytes

EDIT: Fixed an error thanks to @Vlo and changed it to read input from stdins, saved one byte by assigning `w` and skipping parantheses.

```
function(v)sort(v[c(w<-which(v==0)-1,w+1)],T)[1]

```

```
v=scan();w=which(v==0);sort(v[c(w-1,w+1)],T)[1]

```

### Unnested explanation

1. Find indices for which the vector `v` takes on the values 0: `w <- which(v == 0)`
2. Create new vector which contains the indices `+-1`: `w-1` and `w+1`
3. Extract elements that match the indices `w-1` and `w+1`
4. Sort in descending order and extract fist element

Note that if the last or first element of `v` is a zero, `w+-1` will effectively fetch an index outside of the length of the vector which implies that `v[length(v)+1]` returns `NA`. This is generally no problem but the `max()` functions inconveniently returns `NA` if there are any occurrences in the vector unless one specifies the option `na.rm=T`. Thus it is 2 bytes shorter to sort and extract first element than to use `max()`, e.g.:

```
max(x,na.rm=T)
sort(x,T)[1]

```
> 3 votes

# Answer
# Dyalog APL, 14 bytes

```
⌈/∊2(+↑⍨0∊,)/⎕

```

`⌈/` largest of

the flattened ("**e**nlisted"

`2(`...`)/` pairwise

`+` sum (zero plus something is something)

`↑⍨` taken if

`0` zero

is a member of

`,` the pair (lit. the concatenation of the left-hand number and the right-hand number)

TryAPL online!
> 3 votes

# Answer
# K (ngn/k), 14 bytes

```
|/+/'(*/')_2':

```

Try it online!

```
|/+/'(*/')_2':
           2':   pairs
     (*/')_      discard those whose product are nonzero
  +/'            sum of each pair
|/               maximum

```
> 3 votes

# Answer
## Julia, ~~56~~ 55 Bytes

```
f(l)=max(map(sum,filter(t->0 in t,zip(l,l[2:end])))...)

```

Create tuples for neighboring values, take those tuples containing 0, sum tuple values and find maximum
> 2 votes

# Answer
# Perl, 42 bytes

Includes +1 for `-p`

Give the numbers on line on STDIN

```
largest0.pl <<< "8 4 0 0 5 1 2 6 9 0 6"

```

`largest0.pl`:

```
#!/usr/bin/perl -p
($_)=sort{$b-$a}/(?<=\b0 )\S+|\S+(?= 0)/g

```
> 2 votes

# Answer
# J, 18 bytes

```
[:>./2(0&e.\#+/\)]

```

## Explanation

```
[:>./2(0&e.\#+/\)]  Input: array A
                 ]  Identity. Get A
     2              The constant 2
      (         )   Operate on 2 (LHS) and A (RHS)
               \    Get each subarray of size 2 from A and
             +/       Reduce it using addition
           \        Get each subarray of size 2 from A and
       0&e.           Test if 0 is a member of it
            #       Filter for the sums where 0 is contained
[:>./               Reduce using max and return

```
> 2 votes

# Answer
# Vyxal `G`, 36 bitsv2, 4.5 bytes

```
2lƛ∑w↔

```

Try it Online!

Porting Jelly is (still) always the best option

## Explained

```
zṠ↔G
z     # Overlapping pairs (equivalent to 2l)
 Ṡ    # summed (vectorised)
  ↔   # with only items in the input kept.
   G  # Get the biggest number in that list.

```

Created with the help of Luminespire.
> 2 votes

# Answer
# Nibbles, 8.5 bytes

```
`/.|!$>>@:?$0+$]

```

Attempt This Online!

Disgustingly long…

```
`/.|!$>>@:?$0+$]
    !    :       Zip
     $            the input
      >>          with the tail of
        @         the input
   |             Filter by
          ?$0     containing a zero
  .              Map
             +$   sum
`/             ] Maximum

```
> 2 votes

# Answer
# BQN, 14 bytes

```
⌈´((«∨»)0⊸=)⊸/

```

Try

Seemed like a good excuse to use the shifts in `«∨»`.
> 2 votes

# Answer
# , 16 bytes

```
}.>./@(+#~0=*)}:

```

Attempt This Online!

```
}.>./@(+#~0=*)}:
}.            }:    Input without first and without last, respectively
          0=*       elementwise product equals 0?
       +            elementwise sum
        #~          filter the left by the right being true
                    (the right is true iff one of the two is zero,
                    and the corresponding sum is the other number)
  >./@              maximum of those

```
> 2 votes

# Answer
# Vyxal 3 `G`, 4 bytes

```
oᶻΠf

```

Try it Online!

```
oᶻΠf
o     # overlapping pairs
 ᶻΠ   # where the product is zero
   f  # flatten

```

Created with the help of Luminespire.
> 2 votes

# Answer
# Python 2, 74 Bytes

```
def f(x):x=[9]+x;print max(x[i]for i in range(len(x)) if 0in x[i-1:i+2:2])

```

Cycle through every element, if there's a `0` in the position of either the left or the right of the current element, include it in the generator, and then run it through `max`. We need to pad the list with some non-`0` number. It'll never be included because the slice `[-1:2:2]` won't include anything.
> 1 votes

# Answer
# C# ~~76~~ 74 bytes

```
using System.Linq;i=>i.Zip(i.Skip(1),(a,b)=>a*b==0?1<<31:a+b).Max();

```

Explanation:

Use zip to join the array with itself but skipping the first value in the 2nd reference so that item zero joins to item one. Multiply a times b, if the result is zero, one of them must be zero and output a + b. Otherwise, output the minimum possible integer in the language. Given the assumption that we will always have a zero and a non-zero, this minimum value will never be output as the max.

Usage:

```
[TestMethod]
public void LargestFriend()
{
    Assert.AreEqual(7, F(new int[] { 1, 4, 3, 6, 0, 3, 7, 0 }));
    Assert.AreEqual(9, F(new int[] { 9, 4, 9, 0, 9, 0, 9, 15, -2 }));
    Assert.AreEqual(-2, F(new int[] { -4, -6, -2, 0, -9 }));
    Assert.AreEqual(0, F(new int[] { -11, 0, 0, 0, 0, 0, -12, 10 }));
    Assert.AreEqual(20, F(new int[] { 0, 20 }));
}

```
> 1 votes

# Answer
# T-SQL, 182 bytes

**Golfed:**

```
DECLARE @x varchar(max)='1 5 4 3 6 1 3 17 1 -8 0 -7'

DECLARE @a INT, @b INT, @ INT WHILE @x>''SELECT @a=@b,@b=LEFT(@x,z),@x=STUFF(@x,1,z,''),@=IIF(@a=0,IIF(@b<@,@,@b),IIF(@b<>0 or @>@a,@,@a))FROM(SELECT charindex(' ',@x+' ')z)z PRINT @

```

**Ungolfed:**

```
DECLARE @x varchar(max)='1 5 4 3 6 1 3 17 1 -8 0 -7'

DECLARE @a INT, @b INT, @ INT
WHILE @x>''
  SELECT
   @a=@b,
   @b=LEFT(@x,z),
   @x=STUFF(@x,1,z,''),
   @=IIF(@a=0,IIF(@b<@,@,@b),IIF(@b<>0 or @>@a,@,@a))
  FROM(SELECT charindex(' ',@x+' ')z)z
PRINT @

```

**Fiddle**
> 1 votes

# Answer
## PowerShell v3+, 62 bytes

```
param($n)($n[(0..$n.count|?{0-in$n[$_-1],$n[$_+1]})]|sort)[-1]

```

A bit longer than the other answers, but a nifty approach.

Takes input `$n`. Then loops through the indices `0..$n.count`, uses the `Where-Object` (`|?{...}`) to pull out those indices where the previous or next item in the array is `0`, and feeds those back into array slice `$n[...]`. We then `|sort` those elements, and take the biggest `[-1]`.

### Examples

```
PS C:\Tools\Scripts\golfing> @(1,4,3,6,0,3,7,0),@(9,4,9,0,9,0,9,15,-2),@(-4,-6,-2,0,-9),@(-11,0,0,0,0,0,-12,10)|%{""+$_+" --> "+(.\largest-number-beside-a-zero.ps1 $_)}
1 4 3 6 0 3 7 0 --> 7
9 4 9 0 9 0 9 15 -2 --> 9
-4 -6 -2 0 -9 --> -2
-11 0 0 0 0 0 -12 10 --> 0

PS C:\Tools\Scripts\golfing> @(0,20),@(20,0),@(0,7,20),@(7,0,20),@(7,0,6,20),@(20,0,6)|%{""+$_+" --> "+(.\largest-number-beside-a-zero.ps1 $_)}
0 20 --> 20
20 0 --> 20
0 7 20 --> 7
7 0 20 --> 20
7 0 6 20 --> 7
20 0 6 --> 20

```
> 1 votes

# Answer
# q, 38 bytes

```
{max x where 0 in'x,'(next x),'prev x}

```
> 1 votes

# Answer
# Perl 6, 53 bytes

```
{max map ->$/ {$1 if !$0|!$2},(1,|@_,1).rotor(3=>-2)}

```

## Expanded:

```
# bare block lambda with implicit signature of (*@_)
{
  max

    map

      -> $/ {           # pointy lambda with parameter ｢$/｣
                        # ( ｢$0｣ is the same as ｢$/[0]｣ )
        $1 if !$0 | !$2 # return the middle value if either of the others is false
      },

      ( 1, |@_, 1 )     # list of inputs, with added non-zero terminals
      .rotor( 3 => -2 ) # grab 3, back-up 2, repeat until less than 3 remain
}

```
> 1 votes

# Answer
# PHP, 66 bytes

```
foreach($a=$argv as$k=>$v)$v||$m=max($m,$a[$k-1],$a[$k+1]);echo$m;

```

Pretty straightforward. Iterates over the input, and when a number is `0`, it sets `$m` to the highest number of the 2 adjacent numbers **and** any previous value of `$m`.

Run like this (`-d` added for aesthetics only):

```
php -d error_reporting=30709 -r 'foreach($a=$argv as$k=>$v)$v||$m=max($m,$a[$k-1],$a[$k+1]);echo$m;' -- -4 -6 -2 0 -9;echo

```
> 1 votes

# Answer
# SPSS Syntax (98 bytes)

Golfed solution:

```
CRE L=lead(A,1).
COMP R=MAX(lag(A),L).
EXE.
SEL IF A=0.
EXE.
AGG
/S=MAX(R).
LIST S
/CAS=1.

```

Ungolfed:

```
CREATE L=lead(A,1).
COMPUTE R=MAX(lag(A),L).
EXECUTE.
SELECT IF A=0.
EXECUTE.
AGGREGATE
/S=MAX(R).
LIST S
/CASES=1.

```

Explanation: Input values is ordered vertically in a column. The first line of code creates a column with the lead number, the number before any given number. MAX(lag,A) returns the lagging number, the number after any given number (in test series A). So the second line of code creates a column with the highest number of neighbourging numbers of any given number. We are only interested in the neighbours of zeros, so the forth line selects all the rows with zeros, which now also include the highest valued neighbours. The 6th and 7th line of code finds the max value of selected neighbours.

With data inputs:

```
* This syntax solves: Returning the greatest adjacent number bigger or equal to itself,
  for any number V.
* CodeGolf asks for the solution for the case V=0.
* Bytes=98.

DATA LIST LIST
/ Sample (A7) a b c d e f g h i j k l m .
BEGIN DATA.
"A" 1, 4, 3, 6, 0, 3, 7, 0
"B" 9, 4, 9, 0, 9, 0, 9, 15, -2
"C" -4, -6, -2, 0, -9
"D" -11, 0, 0, 0, 0, 0, -12, 10
"E"  0, 20
END DATA.
DATASET NAME Inputs WINDOW=FRONT.

FLIP VARIABLES=a b c d e f g h i
/NEWNAMES=Sample.
DATASET NAME CodeGolf WINDOW=FRONT.
DATASET CLOSE Inputs.

CRE L=lead(A,1).
COMP R=MAX(lag(A),L).
EXE.
SEL IF A=0.
EXE.
AGG
/S=MAX(R).
LIST S
/CAS=1.

```

Just change the sample references (A to E) for testing each sample.
> 1 votes

# Answer
# R, 48 54 bytes

```
s=scan()

w=which;max(s[c(w(s==0)+1,w(s==0)-1)],na.rm=T)

```

Reads vector from console input, then takes the maximum over all values adjacent to 0.

Edit: Catches NAs produced at the boundary, thanks rturnbull!
> 1 votes

# Answer
# Thunno 2 `G`, 6 bytes

```
ḣZæp}ʂ

```

Try it online!

#### Explanation

```
ḣZæp}ʂ  # Implicit input
ḣZ      # All overlapping pairs
  æp}   # Filter by product == 0
     ʂ  # Sum each inner pair
        # Implicit output of maximum

```
> 1 votes

# Answer
`awk`

---

```
gawk '{__=!_++?+$NF:!NF?(!_<__?__:!_):__<+(!RT||+$NF<+$!_? $!_:\
         $!_=$NF)?+$!_:__ }END{ print __ }' RS='(^| +)0([ \n]+|$)'

```

---

```
-11 0 0 0 0 0 -12 10
0
-4 -6 -2 0 -9
-2
0 20
20
1 4 3 6 0 3 7 0
7
9 4 9 0 9 0 9 15
9

```
> 1 votes

# Answer
# Scala, ~~106~~ 97 bytes

A port of @Kevin Cruijssen's Java 7 answer in Scala.

Saved 9 bytes thanks to the comment of @ceilingcat

---

Golfed version. Try it online!

```
a=>{var(i,m,c)=(0,1<<31,0);while({i+=1;i<a.length})if(a(i)*a(i-1)==0)m=Math.max(a(i)+a(i-1),m);m}

```

Ungolfed version. Try it online!

```
object M {
  def c(a: Array[Int]): Int = {
    var i = 0
    var m = 1 << 31
    var c: Int = 0

    while ({i += 1; i < a.length}) {
      if (a(i) * a(i - 1) == 0) {
        c = a(i) + a(i - 1)
        m = Math.max(c, m)
      }
    }
    m
  }

  def main(args: Array[String]): Unit = {
    println(c(Array(1, 4, 3, 6, 0, 3, 7, 0)))
    println(c(Array(9, 4, 9, 0, 9, 0, 9, 15, -2)))
    println(c(Array(-4, -6, -2, 0, -9)))
    println(c(Array(-11, 0, 0, 0, 0, 0, -12, 10)))
    println(c(Array(0, 20)))
    println(c(Array(2, 1, 0)))
  }
}

```
> 1 votes

# Answer
# Pip, 15 bytes

```
M$|*:0N_FIgZ@>g

```

Takes the numbers as command-line arguments. Attempt This Online!

### Explanation

```
M$|*:0N_FIgZ@>g
          g      ; List of command-line args
           Z     ; Zip with
            @>g  ; All but the first element of that same list
        FI       ; Filter those pairs of elements on this function:
     0N_         ;   Contains a 0
 $|*:            ; Fold each pair on logical OR
M                ; Maximum

```
> 1 votes

# Answer
## Racket 183 bytes

```
(λ(k)(let*((lr(λ(l i)(list-ref l i)))(l(append(list 1)k(list 1)))(m(for/list((i(range 1(sub1(length l))))
#:when(or(= 0(lr l(sub1 i)))(= 0(lr l(add1 i)))))(lr l i))))(apply max m)))

```

Detailed version:

```
(define f
 (λ(k)
    (let* ((lr (λ(l i)(list-ref l i)))
           (l (append (list 1) k (list 1)))
           (m (for/list ((i (range 1 (sub1(length l))))
                         #:when (or (= 0 (lr l (sub1 i)))
                                    (= 0 (lr l (add1 i))) ))
                (lr l i) )))
      (apply max m) )))

```

Testing:

```
(f (list 1 4 3 6 0 3 7 0))
(f (list 9 4 9 0 9 0 9 15 -2))
(f (list -4 -6 -2 0 -9))
(f (list -11 0 0 0 0 0 -12 10))
(f (list 0 20 ))

```

Output:

```
7
9
-2
0
20

```
> 0 votes

# Answer
# C 132 bytes

Outputs using main's return code:

```
int main(int a,char**_){int i,m=0;_[0]=_[a]="1";for(i=1;i<a;++i){m=(*_[i-1]-48||*_[i+1]-48?m>atoi(_[i])?m:atoi(_[i]):m);}return m;}

```

I feel like I should be able to save a few bytes by saving one of the atoi calls, but I couldn't find an efficient way. (`,t` plus `t=` plus `,` plus `t` twice is too long). Also this *technically* uses undefined behaviour (setting \_\[a\] to "1") but every compiler I know of allows it by default.

Strategy: pad the start and end of the array with 1, then loop over the internal section checking each neighbor.
> 0 votes

# Answer
# PHP ~~69~~ 64 bytes

Some bytes on and off from Jörg Hülsermann and Titus. = `(-5)`

Requires register\_globals enabled. Usage: `http://localhost/notnull.php?i[]=9&i[]=-5i[]=...`

```
$x=$_GET['i'];
$y=0;
foreach($x as $j){
if($y<abs($j)){
$y=$j;
}
}
echo $y;

```

Golfed:

```
$x=$_GET['i'];$y=0;foreach($x as $j)if($y<abs($j))$y=$j;echo $y;

```
> 0 votes

# Answer
# YASEPL, 91 bytes

```
=1'±" "=l®1=h-99=i`1!o¥i,1}7,0,2!i]4!m$i-=s¥m,1}2,h,2|3`4!m$i+=s¥m,1}2,h,2`3!h$s`2!i+}2,l>h

```

explained:

```
=1'±" "=l®1=h-99=i`1!o¥i,1}7,0,2!i]4!m$i-=s¥m,1}2,h,2|3`4!m$i+=s¥m,1}2,h,2`3!h$s`2!i+}2,l>h                   packed
=1'                                                                                set var1 to user input
   ±" "                                                                                split A by every space
       =l®1                                                                                set L to the length of var1
           =h-99                                                                                set H to -99 (atorage for highest number)
                =i                                                                                set I to 0 (incrementer)
                  `1                                                              !i }2,l                     do while I < L ...
                    !o¥i,1}7,0,2                                                `2                               if(var1[i] == 0) ...
                                !i]4!m$i-=s¥m,1}2,h,2|3`4                 `3                                         and if(i != 0 and if(var1[i-1] > h) ...
                                                         !m$i+=s¥m,1}2,h,2                                           or if(var1[i+1] > h) ...
                                                                            !h$s                                        set H to S and continue (found higher number)
                                                                                +                            increment I and loop.
                                                                                >h                   print H once done.

```
> 0 votes

# Answer
# Uiua SBCS, 14 bytes

```
/↥≡/+▽=0≡/×.◫2

```

Try it!

```
/↥≡/+▽=0≡/×.◫2
            ◫2  # overlapping pairs
           .    # duplicate
        ≡/×     # products
     ▽=0        # keep those equal to zero
  ≡/+           # sums
/↥              # max

```
> 0 votes

---
Tags: code-golf, number
---


title: Remove falsy rows and columns

text:
# Question
Title: Remove falsy rows and columns
Your challenge is to, given a matrix of nonnegative integers, remove all rows and columns that contain a 0.

For example, with this matrix:

```
[[5, 3, **2**, 4, **1**],
 [**3**, **2**, **0**, **4**, **7**],
 [7, 1, **9**, 8, **2**],
 [3, 2, **1**, 5, **7**],
 [6, 4, **6**, 1, **2**],
 [**9**, **3**, **2**, **4**, **0**]]

```

Columns 3 and 5, along with rows 2 and 6 (in bold), contain a 0, so they should be removed, leaving:

```
[[5, 3, 4],
 [7, 1, 8],
 [3, 2, 5],
 [6, 4, 1]]

```

You may assume the input and the output are nonempty. This is , shortest wins!

## Testcases

```
[[1, 2, 3], [4, 5, 6]] -> [[1, 2, 3], [4, 5, 6]]
[[1, 2, 3], [4, 5, 0]] -> [[1, 2]]
[[3, 6, 19], [4, 0, 18], [2, 19, 3]] -> [[3, 19], [2, 3]]
[[5, 3, 2, 4, 1], [3, 2, 0, 4, 7], [7, 1, 9, 8, 2], [3, 2, 1, 5, 7], [6, 4, 6, 1, 2], [9, 3, 2, 4, 0]] -> [[5, 3, 4], [7, 1, 8], [3, 2, 5], [6, 4, 1]]
[[4, 9, 4, 1], [2, 0, 6, 0], [3, 4, 1, 2], [9, 7, 8, 5], [3, 5, 2, 0]] -> [[4, 4], [3, 1], [9, 8]]

```

# Answer
# , 35 bytes

```
\(x,`?`=\(d)apply(x,d,all))x[?1,?2]

```

Attempt This Online!

---

Alternative solution if the input contained `NA`s instead of `0`s:

### , 34 bytes

```
\(x,`?`=complete.cases)x[?x,?t(x)]

```

Attempt This Online!
> 8 votes

# Answer
# Python 3, ~~82~~ ~~74~~ ~~65~~ 60 bytes

*-13 bytes thanks to Mukundan314. -9 bytes thanks to att.*

```
lambda m:[q for*q,r in zip(*filter(all,zip(*m)),m)if all(r)]

```

Try it online!

I wasn't going to post two answers but since nobody else is posting a Python answer that *doesn't* rely on NumPy... Port of my Haskell answer, but I can't really take any credit for the final result. It all goes to Mukundan314 and att. I'll try my best to explain this wizardry.

## Explanation

Said wizardry *really* takes advantage of Python's splat operator `*`. What it does essentially is unpack an iterable (in this case a two-dimensional list) into separate arguments for a function call. Let's start with a simple matrix `m`, and I'll document the transformations that happen to it along the way.

```
[[4, 9, 4, 1],
 [2, 0, 6, 0],
 [3, 4, 1, 2],
 [3, 5, 2, 0]]

```

First, `zip(*m)` transposes the list. Instead of passing `m` to the `zip` function as the list of rows it is, it's passed as separate arguments, effectively zipping the rows of the matrix together to create a list of the columns.

```
[(4, 2, 3, 3),
 (9, 0, 4, 5),
 (4, 6, 1, 2),
 (1, 0, 2, 0)]

```

Next, `filter(all, ...)` removes every column that has a zero in it by checking `all` of the column against Python's boolean logic: 0 is falsy and every other number is truthy. (Hey, that's half the challenge sorted!)

```
[(4, 2, 3, 3),
 (4, 6, 1, 2)]

```

Cool, that's the truthy columns. After that, `zip(*..., m)` is once again splatting the previous result and zipping it together with the original input. This basically transposes it back to the rows, except without the falsy columns, and then prepends it to the original rows.

```
[(4, 4, [4, 9, 4, 1]),
 (2, 6, [2, 0, 6, 0]),
 (3, 1, [3, 4, 1, 2]),
 (3, 2, [3, 5, 2, 0])]

```

Here comes an interesting bit. Remember what I said about the splat operator? Yeah, it does more than that. Kinda. `for *q, r in ...` effectively groups the rows-without-falsy-columns together, while keeping the original rows separate. The splat operator "collects" elements into `q` when iterating over something until another argument `r` is required.

```
[([4, 4], [4, 9, 4, 1]),
 ([2, 6], [2, 0, 6, 0]),
 ([3, 1], [3, 4, 1, 2]),
 ([3, 2], [3, 5, 2, 0])]

```

Now all that's left to do is get rid of the falsy rows and to do this, `q ... if all(r)` employs a similar trick to when the falsy columns were removed. While iterating over the previous result, if and only if `r` (or the original row) is truthy, keep `q`.

```
[[4, 4],
 [3, 1]]

```
> 6 votes

# Answer
# Python \+ numpy, 32 bytes

```
lambda a:a[a.all(1)][:,a.all(0)]

```

Attempt This Online! -6 bytes thanks to att
> 5 votes

# Answer
# Jelly, 11 bytes

```
¬ŒṪZœP@ẎZɗƒ

```

A monadic Link that accepts the matrix and yields the reduced matrix.

**Try it online!**

### How?

```
¬ŒṪZœP@ẎZɗƒ - Link: list of lists of integers, M
¬           - logical NOT (vectorises)
 ŒṪ         - truthy multidimensional indices
   Z        - transpose -> [zero row indices, zero column indices]
          ƒ - start with {M} and reduce {that} by:
         ɗ  -   last three links as a dyad - f(Current, Indices):
      @     -     with swapped arguments:
    œP      -       partition {Current} at {Indices}
       Ẏ    -     tighten
        Z   -     transpose

```
> 5 votes

# Answer
# K (ngn/k), ~~18~~ ~~16~~ 15 bytes

-1 thanks to coltim

```
{x.&'1&/''+:\x}

```

Try it online!

```
     1&/''+:\x      row-,column-wise zero-free?
   &'               indices where true
 x.                 submatrix

```
> 5 votes

# Answer
# MATL, 10 bytes

```
t!XAyXA3$)

```

Try at MATL online! Or verify all test cases.

### How it works

```
t      % Implicit input. Duplicate
!      % Transpose
XA     % Vertical-all: gives a logical vector containing true
       % for columns without zeros, or false otherwise
y      % Duplicate from below: pushes copy of input
XA     % Vertical-all
3$)    % 3-input indexing: keeps the selected rows and columns
       % Implicit display

```
> 5 votes

# Answer
# JavaScript (ES6), 62 bytes

*-2 thanks to @l4m2*

```
m=>(g=a=>a.filter((v,x)=>(+v?m:v).every(v=>v[x]|v)))(m).map(g)

```

Try it online!

### Commented

```
m => (               // m[] = input matrix
  g = a =>           // g is a helper function taking an array a[]
  a.filter((v, x) => // for each value v at index x in a[]:
    (+v ? m          //   if v is atomic, we use m[] (2nd pass on columns)
            : v)     //   otherwise, we use v (1st pass on rows)
    .every(v =>      //   for each value v in the array chosen above:
      v[x]           //     test either v[x] (when removing columns)
      | v            //     or v (when removing rows)
    )                //   end of every()
  )                  // end of filter()
)(m)                 // invoke g on m[] to remove rows
.map(g)              // invoke g on each row to remove columns

```
> 4 votes

# Answer
# APL (Dyalog Extended), 15 bytes

```
((⍸0≠∧/)¨⊢⍮⍉)⌷⊢

```

Try it online!

# APL (Dyalog APL), ~~19~~ ~~18~~ ~~17~~ 16 bytes

-1 byte thanks to @att

```
⊢⌷⍨B∘⍉,B←⊂∘⍸0≠∧⌿

```

Attempt This Online!

```
⊢⌷⍨B∘⍉,B←⊂∘⍸0≠∧⌿
       B←⊂∘⍸0≠∧⌿  ⍝ B = Monadic function to get indices of columns without zeros:
              ∧⌿  ⍝   reduce each column on lcm
            0≠    ⍝   check if not equal to 0 (vectorized)
           ⍸      ⍝   get indices of true values
         ⊂        ⍝   enclose
   B∘⍉            ⍝ Apply B on transpose (first result)
      ,           ⍝ catenate with
       B          ⍝ Apply B on argument (second result)
⊢⌷⍨               ⍝ Keep only rows and columns in first and second result respectively

```

Created with the help of Luminespire.
> 4 votes

# Answer
# Matlab, ~~74 bytes(?)~~ 52 bytes

*-22 bytes thanks to Luis Mendo because my first attempt was too readable.*

Try it online! Input for first test case would be `F([1,2,3;4,5,6])`

To be honest, I just wanted to try the challenge and am pleasantly surprised to how neatly it can be solved Matlab, so I just wanted to share it.

```
function[m]=F(m);[r,c]=find(~m);m(r,:)=[];m(:,c)=[];

```
> 4 votes

# Answer
# Haskell, ~~81~~ ~~63~~ ~~62~~ 59 bytes

*-3 bytes thanks to Wheat Wizard.*

```
n=notElem 0
f m=[[c|(x,c)<-zip[0..]r,n$map(!!x)m]|r<-m,n r]

```

Try it online!

~~I *really* want to use the fact that Haskell has `product` in Prelude but... Never mind, I did it. :P~~ Never mind, the original approach allows for code shorter by a byte due to syntactical rearrangement.

## Explanation (slightly outdated)

```
f m                            -- define function f that takes matrix m
  | n <- notElem =             -- alias notElem (element not in list) to p
    [[c                        --     store c
      | (x, c) <- zip [0..] r  --   for every pair of index x and value c in r...
      , n 0 $                  --   if 0 is not in the...
      map (!! x) m)            --   ...xth element of every row in m (column)
    | r <- m                   -- for every row r in m...
    , n 0 r]                   -- if 0 is not in r (truthy)

```
> 3 votes

# Answer
# Google Sheets, 72 bytes

```
=let(a,A1:E6,_,lambda(x,min(x)),filter(filter(a,byrow(a,_)),bycol(a,_)))

```

Put the array in cells `A1:E6` and the formula in cell `G1`.

In Google Sheets, a formula cannot return a *completely empty* 2D array. When all rows or columns contain a zero, the formula will error out.
> 3 votes

# Answer
# APL (Dyalog Extended), 11 bytes

```
(×∧/⍮∧⌿)⍛/⍨

```

Try it online!

using the argument as both parameter (list of masks, one per dimension) and data

`/` filter the data using the parameter

`(``)⍛` first pre-processing the paramter as follows:

`×` signum of

`∧/` row-wise LCM

juxtaposed with

`∧⌿` column-wise LCM
> 3 votes

# Answer
# Haskell \+ hgl, 38 bytes

```
f y=cr<<fn(e 0<(tx y!)<st)<eu<fn(e 0)y

```

Attempt This Online!

## Alternate, 43 bytes

```
cr<<<g st<g cr<m(sQ<oti mn)

```

```
g=tx><fn<e 0<<m

```

Attempt This Online!

I kind of understand how it works but it's not easy to explain. First it tags each value with the minimum in its row, then it removes every column with a zero, then it removes every row with a zero tag.

* `m(sQ<oti mn)` is the part that adds the tags.
* `g cr` is the part that removes the columns (it also transposes the matrix)
* `g st` is that part that removes the rows (it also transposes the matrix back)
* `cr` removes the tags.

# Reflection

* There should be a non-infix version of `(!)`.
* There should be precomposed versions of `e` and `ne`.
* `oti` should probably have a 2 byte name.
* The precendence of `@!` makes it incompatible with composition. I should tweak this.
* There is already an "index map" a couple of index filters would be nice.
> 2 votes

# Answer
# Charcoal, ~~15~~ 14 bytes

```
⭆¹ＥΦθΠλΦλ⬤θ§πξ

```

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

```
    θ          Input array
   Φ           Filtered where
      λ        Current row
     Π         Product (is truthy if the row contains no zeros)
  Ｅ            Map over remaining rows
        λ       Current row
       Φ        Filtered where
            π   Inner row
           §    Indexed by
             ξ  Current column
         ⬤      Are non-zero for each row of
          θ     Input array
⭆¹              Pretty-print the result

```
> 2 votes

# Answer
# , 15 bytes

```
*@*/#"1*@*/"1#]

```

Try it online!

* `*@*/"1` Boolean multiply across columns...
* `#]` and use that to filter rows.
* `#"1` then filter each of those remaining rows...
* `*@*/` by the boolean filter obtained by multiplying all the rows together
> 2 votes

# Answer
# APL+WIN, 17 bytes

Prompts for input of matrix

```
(×/×m)⌿(×⌿×m)/m←⎕

```

Try it online! Thanks to Dyalog Classic
> 2 votes

# Answer
# 05AB1E, 10 bytes

```
øDĀPÏøIĀPÏ

```

Try it online or verify all test cases.

**Explanation:**

```
ø           # Zip/transpose the (implicit) input-matrix; swapping rows/columns
 D          # Duplicate this
  Ā         # Check for each value whether it's NOT 0 (0 if 0; 1 otherwise)
   P        # Take the product of each inner row
    Ï       # Only leave the rows of the transposed matrix at the truthy (==1) positions
     ø      # Zip/transpose the remaining rows back
      I     # Push the input-matrix again
       ĀPÏ  # Do the same
            # (after which the filtered matrix is output implicitly as result)

```
> 2 votes

# Answer
# , 32 bytes

```
\(x)x[!rowSums(!x),!colSums(!x)]

```

Attempt This Online!

Test suite stolen from pajonk's answer.
> 2 votes

# Answer
# Husk, 8 bytes

```
fm▼¹Tf▼T

```

Try it online!

### Explanation

```
fm▼¹Tf▼T
       T  Transpose the input
     f▼   Filter out those rows (were columns) with a falsy minimum value
    T     Transpose back
f         Filter the rows based on
 m▼¹       the minimum values of the rows in the original input

```
> 2 votes

# Answer
# Uiua SBCS, ~~15~~ 14 bytes

```
⍉▽⊙⍉⊙▽∩/↧⟜⍉≠0.

```

Try it!

-1 thanks to the new `⟜ on` modifier that dropped this morning.

Keeps two masks on the stack of which rows should be kept on each axis, and filters the input matrix based on these.
> 1 votes

# Answer
# APL(NARS), 43 chars

```
{(c d)←1⍴⍨¨⍴⍵⋄c[↑¨k]←d[2∘⊃¨k←⍸0=⍵]←0⋄d/c⌿⍵}

```

test:

```
  arr←3 3⍴⍳10⋄arr1←6 5⍴5 3 2 4 1 3 2 0 4 7 7 1 9 8 2 3 2 1 5 7 6 4 6 1 2 9 3 2 4 0
  g←{(c d)←1⍴⍨¨⍴⍵⋄c[↑¨k]←d[2∘⊃¨k←⍸0=⍵]←0⋄d/c⌿⍵}
  g arr1
5 3 4
7 1 8
3 2 5
6 4 1
  g arr
1 2 3
4 5 6
7 8 9

```
> 1 votes

# Answer
# Perl 5 `-MList::Util=product`, 88 bytes

```
sub{map{[@$_[grep{//;product(map{$$_[$']}@_)}0..$#$_]]}@_[grep{product@{$_[$_]}}0..$#_]}

```

Try it online!
> 1 votes

# Answer
# Nekomata, 9 bytes

```
Z:Ť‼Ť$ᶻ¿‼

```

Attempt This Online!

```
Z:Ť‼Ť$ᶻ¿‼   Take [[3,6,19],[4,0,18],[2,19,3]] as an example
Z           Check if nonzero
                [[3,6,19],[4,0,18],[2,19,3]] -> [[3,6,19],[4,Fail,18],[2,19,3]]
 :          Duplicate
                [[3,6,19],[4,Fail,18],[2,19,3]] -> [[3,6,19],[4,Fail,18],[2,19,3]],[[3,6,19],[4,Fail,18],[2,19,3]]
  Ť         Transpose
                [[3,6,19],[4,Fail,18],[2,19,3]] -> [[3,4,2],[6,Fail,19],[19,18,3]]
   ‼        Remove rows that contain Fail
                [[3,4,2],[6,Fail,19],[19,18,3]] -> [[3,4,2],[19,18,3]]
    Ť       Transpose
                [[3,4,2],[19,18,3]] -> [[3,19],[4,18],[2,3]]
     $      Swap
                [[3,6,19],[4,Fail,18],[2,19,3]],[[3,19],[4,18],[2,3]] -> [[3,19],[2,3],[4,18]],[[3,6,19],[4,Fail,18],[2,19,3]]
      ᶻ     Zip with
       ¿        a, b -> if b contains Fail then a else Fail
                [[3,19],[2,3],[4,18]],[[3,6,19],[4,Fail,18],[2,19,3]] -> [[3,19],Fail,[4,18]]
        ‼   Remove rows that contain Fail
                [[3,19],Fail,[4,18]] -> [[3,19],[4,18]]

```
> 1 votes

---
Tags: code-golf, array
---


# Question
Title: Floating point numbers... dar nu-mă, nu-mă iei!
When you leave, my challenges fade to grey, 0A0AE16, 0A0A0AE16...

A while ago, I made this programming language (https://esolangs.org/wiki/Dragostea\_din\_tei) which uses an interesting number system. It is base two for integers, but for decimals it divides a base two integer by a power of ten.

The input should be a floating point number, negative, positive or zero.

The output should be "the" standard representation for, that number, in the programming language, which should follow these steps:

1. Start with the absolute value of that number. Now multiply the result by the smallest power of ten to make it an integer (for example, 123.45 -\> multiply by 100 to make 12345) and call it *a*.
2. Write `Ma-ia hii` \+ a newline (literally, push the number zero).
3. Write *a* in base two, with `Ma-ia huu` \+ a newline for ones, and `Ma-ia hoo` \+ a newline for 0's.
4. Now, if the original number (not *a*) has any decimal places, write `Ma-ia haha` \+ a newline for every digit after the decimal point, for example twice for 123.45.
5. If the original number is negative, write `Vrei sa pleci dar`.

You can add or omit trailing and leading newlines if you want.

DONE. Now, here are some good ol' examples: -10 is:

```
Ma-ia hii
Ma-ia huu
Ma-ia hoo
Ma-ia huu
Ma-ia hoo
Vrei sa pleci dar

```

256 is:

```
Ma-ia hii
Ma-ia huu
Ma-ia hoo
Ma-ia hoo
Ma-ia hoo
Ma-ia hoo
Ma-ia hoo
Ma-ia hoo
Ma-ia hoo
Ma-ia hoo

```

And 3.14 is:

```
Ma-ia hii
Ma-ia huu
Ma-ia hoo
Ma-ia hoo
Ma-ia huu
Ma-ia huu
Ma-ia huu
Ma-ia hoo
Ma-ia huu
Ma-ia hoo
Ma-ia haha
Ma-ia haha

```

And finally for -3.14:

```
Ma-ia hii
Ma-ia huu
Ma-ia hoo
Ma-ia hoo
Ma-ia huu
Ma-ia huu
Ma-ia huu
Ma-ia hoo
Ma-ia huu
Ma-ia hoo
Ma-ia haha
Ma-ia haha
Vrei sa pleci dar

```

This is code-golf, so fewest bytes wins!

# Answer
> 2 votes
# Charcoal, ~~65~~ 59 bytes

```
⁺Ma-ia h⁺×²⁺⟦i⟧Ｅ↨ＩΦθ‹.ι²§ouιＥΦθ№…θκ.¦aha¿№θ-”(/◧êºcS﹪Ｚ↑Ｍ▶#↓

```

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

```
⁺Ma-ia h⁺×²⁺⟦i⟧Ｅ↨ＩΦθ‹.ι²§ouιＥΦθ№…θκ.¦aha

```

Remove non-digits from the input, convert from base `10` to base `2`, and replace `0`s with `o` and `1`s with `u`. Prefix `i` to the resulting list, then double the letters. Append `aha` to the list for each digit after the `.` (if any), prepend `Ma-ia h` to each element of the list, and output the result.

```
¿№θ-”(/◧êºcS﹪Ｚ↑Ｍ▶#↓

```

If the input contained a `-` then output `Vrei sa pleci dar` using a compressed string.

If an extra `Ma-ia hoo` is acceptable for an input of `0`, then for 55 bytes:

```
⁺Ma-ia h⁺×²⪪⁺i⍘ＩΦθ‹.ιou¹ＥΦθ№…θκ.¦aha¿№θ-”(/◧êºcS﹪Ｚ↑Ｍ▶#↓

```

Attempt This Online! Link is to verbose version of code. Explanation: When converting `0` to a string base the version of Charcoal on TIO always returns `0` but the version of Charcoal on ATO returns the first character of the string. (For a numeric base conversion both versions would return an empty list.)

# Answer
> 2 votes
# JavaScript (ES6), 103 bytes

Recursively builds the output from bottom to top.

```
f=x=>x<0?f(-x)+`
Vrei sa pleci dar`:x%1?f(x*10)+m+`aha`:x?f(x>>1)+m+(x&1?`uu`:`oo`):(m=`
Ma-ia h`)+`ii`

```

Try it online!

# Answer
> 2 votes
# Python, ~~194~~ ~~189~~ ~~186~~ ~~172~~ 171 bytes

```
def f(i):d=max(0,f"{i:g}"[::-1].find('.'));*map(print,["Ma-ia h"+x for x in["ii"]+["uo"[b<"1"]*2for b in f"{int(abs(i)*10**d):b}"]+["aha"]*d]+["Vrei sa pleci dar"]*(i<0)),

```

*-3 bytes thanx to Neil*

I expect some fancy recursive method to make it below 100 bytes.

Attempt This Online!

# Answer
> 2 votes
# Perl 5 `-n`, 106 bytes

```
s/\.//;say"Ma-ia h$_"for ii,(oo,uu,aha)[(sprintf"%b%s",abs,$'=~y//2/cr)=~/./g];say"Vrei sa pleci dar"if/-/

```

Try it online!

# Answer
> 1 votes
# Retina 0.8.2, 104 bytes

```
-(.+)
$1Vrei sa pleci dar¶
\.(.+)
$1$.1$*h
h
aha
\d+
ii$&$*
+`(1+)\1
$1oo
o?o?1
uu
\Ga?[a-z].
Ma-ia h$&¶

```

Try it online! Link includes test cases. Explanation:

```
-(.+)
$1Vrei sa pleci dar¶

```

Handle negative numbers.

```
\.(.+)
$1$.1$*h
h
aha

```

Handle decimals.

```
\d+
ii$&$*
+`(1+)\1
$1oo
o?o?1
uu

```

Convert to unary, but using `oo` and `uu` instead of `0` and `1`, and prefixing `ii`.

```
\Ga?[a-z].
Ma-ia h$&¶

```

Expand `ii`, `oo`, `uu` and `aha` to the full text.

# Answer
> 1 votes
# PowerShell Core, 145 bytes

```
filter f{$q="Ma-ia h"
if($_-lt0){-$_|f
"Vrei sa pleci dar"}elseif($_%1){$_*10|f
$q+'aha'}elseif($_){$_-shr1|f
$q+('oo','uu')[$_%2]}else{$q+"ii"}}

```

Try it online!

A recursive filter

Non recursive

```
param($a) # input in variable $a
($q="Ma-ia h")+"ii" # output Ma-ia hii and store `Ma-ia h` in a variable
if($a-lt0){$s=,"Vrei sa pleci dar";$a=-$a} # if $a is negative, make it positive and initialise the list of output with Vrei sa pleci dar
for(;$a%1;$a=$a*10){$s+=,"${q}aha"} # while $a has decimals, multiply it by 10 and add Ma-ia haha to the list of output
for(;$a;$a=$a-shr1){$s+=,($q+('oo','uu')[$a%2])} # convert $a to binary and for each bit, append either Ma-ia hoo or Ma-ia huu to the list of output
$s|%{$s[-++$i]}  # reverse and print the list of output

```

# Answer
> 0 votes
# 05AB1E, 56 bytes

```
þ„ouÅв'išºI'.¡¦Jg…ahaи«"Ma-ia h"ì.•1Ć¹bWÖYþï§{•.ªIDÄÊи«»

```

Try it online or verify all test cases.

**Explanation:**

```
þ                      # Only leave the digits of the (implicit) input-number
 „ouÅв                 # Convert it to custom base-"ou", which will basically converts
                       # to base-2, and indexes the result into "ou"
      'iš             '# Prepend an "i"
         º             # Double each character in the list
I'.¡                  '# Push the input again, and split it on "."
    ¦                  # Remove the first item
     Jg                # Take the length of what remains
       …ahaи           # Repeat "aha" that many times as list
            «          # Merge it to the earlier list
"Ma-ia h"ì             # Prepend "Ma-ia h" before each string in the list
.•1Ć¹bWÖYþï§{•         # Push compressed string "vrei sa pleci dar"
              .ª       # Sentence capitalize the leading "V"
                ID     # Push two copies of the input
                  Ä    # Take the absolute value of the copy
                   Ê   # Pop both, and check whether they are NOT equal
                       # (aka 1 if the input is negative; 0 otherwise)
                    и  # Repeat "Vrei sa pleci dar" that many times as list
                     « # Merge this to the list as well
»                      # Join the list with newline delimiter
                       # (after which the multiline string is output implicitly as result)

```

See this 05AB1E tip of mine (section *How to compress strings not part of the dictionary?*) to understand why `.•1Ć¹bWÖYþï§{•` is `"vrei sa pleci dar"`.

---
Tags: code-golf, number
---