# Rapunzel, Rapunzel, let down your hair!

### Description

I guess everyone knows the fairy tale of Rapunzel and the prince. For those who do not: read it here. However, Rapunzel had just had her hair cut, so it might not be long enough to let her prince climb up! She may get very sad..

### Challenge

Your task is to write a function that evaluates what Rapunzel will be saying when the prince calls for her to let her hair down: When her hair is longer than or equal to the tower is tall plus an extra meter (safety guidelines), she becomes veeeery happy and says Aaaah!, with the number of as being the same as length of her hair - height of the tower. Otherwise, her hair does not have sufficient length, and she starts crying: Booho!, where the os before the h equal two thirds of height of the tower - length of her hair, and the os after the h being the rest. The number of os after the B must be rounded, so if you get 2.6, there will be 3 os, and the others must be after the h.

### I/O

You are given positive integers (including null) as arguments, as a list or as two single numbers, in the order you find it the most convenient, but you must state in which order you take them. As the output, print what Rapunzel will be saying.

### Test cases

In the test cases, the first number will be the hair length.

0, 0 -> 'Bh!' (probably a dry sob..)
2, 1 -> 'Aah!'
1, 2 -> 'Boh!'
1, 4 -> 'Booho!'
4, 1 -> 'Aaaah!'
2, 4 -> 'Boho!'


This is , so the shortest answer in bytes wins!

• So she can't get down if the height of the tower is 0? BTW, positive integers (including null) == _non-negative integers :) Jul 15, 2017 at 19:20
• I meant to do this on your first post, but I would like to tell you about the Sandbox, where you can post challenges to get feedback before posting them to main. This seems like quite an interesting challenge but people can get carried away. Jul 15, 2017 at 20:14
• @StewieGriffin Yep, assuming that her hair length is 0 too. Still, she has to get out of the window, and the restrictions for safety apply here too! There's no way she can marry him if she's got herself a broken neck. Jul 16, 2017 at 4:38

# Jelly,  43 41 40 38 34 33 32  31 bytes

There's probably a much Is there a shorter way though! ? ...this was quite some golfing!

‘:3;ạ¥⁸4ẋ+;€⁹¦7Ṛṭ;8ị“øŻPLC»
ạç>


A full program printing the result*.

Try it online!

### How?

‘:3;ạ¥⁸4ẋ+;€⁹¦7Ṛṭ;8ị“øŻPLC» - Link 1: number, abs(hair-tower); number, (hair > tower)?
‘                           - increment -> abs(hair-tower)+1
:3                         - integer divide by 3 -> (abs(hair-tower)+1)//3
-   ...the remainder amount after removing 2/3 rounded
⁸                     - chain's left argument, abs(hair-tower)
_                       -   subtract (yields the 2/3 rounded amount)
;                        - concatenate
4ẋ                   - repeat 4 (vectorises) (i.e. [[4,4,...],[4,...]])
+                  - add (hair > tower)? (vectorises) (i.e. 4s->5s if so)
¦              - sparse application:
;€  7             - of:  concatenate €ach with a 7
⁹               - to indexes: chain's right argument, (hair-tower)?
Ṛ            - reverse the list
ṭ           - tack (hair-tower)?
;8         - concatenate an 8
“øŻPLC» - compression of the word "Abroach" & the string "!B"
ị        - index into "Abroach!B" (1-indexed & modular, so 0->B)
- implicit (smashed) print

ạç> - Main link: number, hair; number, tower
ạ   - absolute difference -> abs(hair-tower)
> - greater than? -> (hair > tower)? (1 if so, else 0)


* As a monadic link it returns a list of characters and lists of characters e.g. ['B', [['o', 'o', 'h'], ['o']], '!'], as a full program the implicit print smashes this e.g. Booho!

• Yep, there is. :-) Jul 16, 2017 at 11:05
• Yeah I started with the idea of using AL€œs3 and found div by zero errors and then after I addressed that with the much longer code above found I still needed to special case the equal length case. I thought I'd try and implement a different way today, but looks like you did already. Jul 16, 2017 at 12:42
• ...mind you I was thinking 25-30 bytes :) Jul 16, 2017 at 12:48

# Python 3, 87 bytes

lambda l,h:["B"+"o"*round((h-l)*2/3)+"h"+"o"*round((h-l)/3),"A"+"a"*(l-h)+"h"][l>h]+"!"


Try it online!

Arguments to the function are taken in the order length of hair, height of tower.

# 05AB1E, 3835 32 bytes

Input order: length of hair, height of tower

‹i¹α'a×"Aÿh!"ë¹-x‚>3÷R'o×'hý…Bÿ!


Try it online!

Explanation

‹i                                  # if h < l
¹α                                # push absolute difference of h and l
'a×                             # repeat "a" that many times
"Aÿh!"                       # interpolate between "A" and "h!"
ë                                  # else
¹-                                # push h-l
x‚                              # pair with its double
>3÷                           # increment and integer divide by 3
R                          # reverse the list
'o×                       # for each, repeat "o" that many times
'hý                    # merge the o's on "h"
…Bÿ!                # interpolate between "B" and "!"

• You seem to have forgotten a 3 which is shown on TIO. Jul 16, 2017 at 12:29
• @EriktheOutgolfer: Thanks for notifying. I've fixed the explanation to conform with the code :) Jul 16, 2017 at 12:53
• Oh, and you have spacing problems with your explanation. Jul 16, 2017 at 12:54
• @EriktheOutgolfer: I don't see it. If you mean the fact that they are in 2 diagonal lines, that's an intentional separation of if-else to decrease horizontal space used. If there's something else I must be blind. Jul 16, 2017 at 13:09
• Oh I was confused with the extraneous whitespace in it... Jul 16, 2017 at 13:12

# Javascript, 105 97 bytes

Thanks to Oki for helping save 7 bytes!

p=(t,s)=>(s||"o").repeat(t)
l=>h=>(d=l-h,o=d/3-.5|0,l>h?A${p(d,"a")}h:B${p(o-d)}h+p(-o))+"!"


Defines an anonymous currying function. Use like f(length)(height)

Try it online!

• Doesn't seem to be working for f(1)(4). Replacing p(o+d) with p(-o-d) could fix this. Also you can use o=-d*2/3+.5|0 to save 7 bytes.
– Oki
Jul 16, 2017 at 10:56
• @Oki thanks for pointing that error out and showing me the shorter rounding! Jul 16, 2017 at 14:58
• p=(t,s='o')=>s.repeat(t)
– tsh
Jul 17, 2017 at 8:11

# PHP>=7.1, 111 bytes

[,$h,$t]=$argv;echo BA[$b=$h>$t],($r=str_repeat)(oa[$b],$c=round(($a=abs($h-$t))*($b?:2/3))),h,$r(o,$a-$c),"!";


PHP Sandbox Online

• Argument order 1. hair 2. tower? Jul 16, 2017 at 13:25
• @racer290 Yes $h hair$t tower Jul 16, 2017 at 13:45

# Jelly, 32 bytes

_‘”aẋŒt;⁾h!ɓ_÷1.,3+.”oẋ“Bh!”żð>?


Try it online!

-1 thanks to Jonathan Allan.

Only works as full program.

Arguments are in order: hair, tower

• Save a byte by replacing ær0 with +. Jul 16, 2017 at 23:04
• @JonathanAllan Ooh it does indeed work. (damn two-byte builtin) Jul 17, 2017 at 6:41

# Julia, 101 bytes

g(h,t)=h>t?string("A","a"^(h-t),"h!"):string("B","o"^round(Int,(t-h)*2/3),"h","o"^round(Int,(t-h)/3))


Arguments to the function are taken in the order length of Hair, height of Tower.

• Typo: heigth of Hower Jul 16, 2017 at 13:46

# Jelly, 84 76 bytes

It's really rather long, but I spent too much time on this not to post it. Takes two integer arguments:

1. length of hair
2. length of tower

Any tips on golfing this would be appreciated.

³>⁴×111ð;ø³>⁴¬×97
97ðxø³ạ⁴
111ðxø¢L÷3×⁸ær0:1
2Çṭ2£“h”ṭµ1ÇṭµFḟ1£
>¬+65¥;¢;33Ọ


Try it online!

– Cœur
Jul 17, 2017 at 5:07

# R, 117 bytes

x=diff(scan());cat(if(x>0,paste0("A",rep("a",x),"h!"),paste0("B",rep("o",F<-round(-2*x/3)),"h",rep("o",-x-F),"!")))


A bit long, pretty sure this can be golfed down. Takes input from STDIN in the order Tower, Hair.

• uh-oh; this doesn't actually work for input 1 4 Jul 17, 2017 at 22:23
• Try this? (113 bytes, too) Jul 17, 2017 at 22:28

# Python 2, 77 bytes

lambda h,t:("BA"+(abs(h-t)*2+1)/3*"oa"+"h"+(abs(h-t)+1)/3*"ao"+"h!!")[h>t::2]


An unnamed function taking hair length, h, and tower height, t, and returning a string.

Try it online!

Builds a string starting with BA, followed by two thirds of the difference rounded of the string oa repeated, followed by a single h, then the remainder amount of ao repeated, and finally h!!. The return value is then every second character starting with either the B or A via the slice notation [h>t::2].

## Perl, 107 bytes

Takes hair length first, tower length second.

sub b{(($c=$_[0]-$_[1])>0?'A'.'a'x--$c.'h':do{$o=int(2/3*($c*=-1)+.5);'B'.('o'x$o).'h'.('o'x($c-\$o))}).'!'}

• You can get rid of the ` and intend your code by 4 spaces to make it look nicer.. Jul 17, 2017 at 17:27