# Vacancy or no vacancy?

We've all seen the signs on motels telling us if there's a vacancy or not:

Typically, these will permanently have the letters of VACANCY lit up, and have the letters of NO lit up if there isn't any room in the motel.

# The challenge

The average motel in the U.S. has 200 rooms.

You will write a program/function that takes an integer T (for taken rooms) as its only input.
Your program will then display the words NO VACANCY. The letters of VACANCY will be printed in red.
If T ≥ 200, the letters of NO will also be printed in red.

For example, assuming a.out is your program and "input" = command line argument:

(I typo'd and my system ignores case.)

# The rules

• Your program/function must display (or, if lambda, return) the exact string NO VACANCY, including case.
• Your program/function may only set the text foreground color to red and not the background.
• If you wish, you may use ANSI escape codes to print the red color - \x1b[31m will work.
• Your program/function may not change the text color of your shell after it finishes.
• Your program/function must terminate normally.
• Your program/function must print only to standard output.
• Your program/function must use your shell/terminal/IDE's default background color. (If you choose to have graphical output you may choose whatever color you like, except red.)
• If T ≤ 200, the letters of NO must be printed in your shell/terminal/IDE's default foreground color. (If you choose to have graphical output, once again you may choose whatever color you like)
• If for some reason your shell/terminal/IDE's default foreground/background color is red, you must print with a black background and a default white foreground.
• If you choose to use graphical output, red may only be used when specified in the program (e.g. your background color or default text color may not be red).

# The winner

As usual with , the shortest program wins! Brownie points for graphical output.
I'll accept the shortest answer in a week. Happy golfing!

# Leaderboard

var QUESTION_ID=123146,OVERRIDE_USER=61563;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

• There is a conflicting rule: in and above the screenshot, it says to print NO in red "If T ≥ 200". Later, you say to print in the default color "If T ≤ 200" – Arc676 May 28 '17 at 6:28
• @Arc676 Oops. Well, logically, if the hotel has 200 rooms then it must be the first description that is correct. – Ørjan Johansen May 28 '17 at 7:27
• For extra credit, do it for the Hilbert Hotel, which has an infinite number of rooms. – David Conrad May 29 '17 at 9:40
• Are these outputs valid: i.imgur.com/221Qxgj.png ? – sergiol Jun 16 '17 at 23:02
• @sergiol Yes, that's fine. – MD XF Jun 16 '17 at 23:20

# Jelly, 29 26 bytes

<200o-“NO“ɓ31m”m“=ȤŻ»Œu“ɓm


This uses <CSI> (0x9b), which is shorter than <ESC>[ (0x1b 0x5b).

It resets the foreground color with <CSI>m instead of <CSI>0m, as the 0 is implicit.

### Verification

Note that your terminal emulator (e.g., Konsole) must be set to ISO 8859-1 or similar.

### How it works

<200o-“NO“ɓ31m”m“=ȤŻ»Œu“ɓm  Main link. Argument: n (integer)

<200                        Compare with 200, yielding 1 if true, 0 if not.
o-                      Logical OR -1; map 0 to -1 (and 1 to 1).
“NO“ɓ31m”             Yield ["NO", "\x9b31m"].
m            Take the list "modulo" 1 or -1, keeping it as is for 1,
reversing it for -1.
“=ȤŻ»       Implicitly print the previous result and yield the
string " vacancy". This is achieved by indexing into
Jelly's in-built dictionary.
Œu     Convert to uppercase.
“ɓm  Implicitly print the previous result and yield the
string "\x9bm", which is printed on exit.


# Javascript (ES6), 60 bytes

(Open your browser's console while running the snippet to see the colored result.)

f=
n=>console.log((n>199?'%cNO':'NO%c')+' VACANCY','color:red')
<input oninput=f(this.value)>

• NO%c VACANCY color:red? – MD XF May 28 '17 at 2:45
• @MDXF check your actual browser console. the snippet console emulator doesn't support it. – nderscore May 28 '17 at 2:48
• Oh, good catch. +1 – MD XF May 28 '17 at 2:48
• Standard JS rules allow you to shorten this greatly. Remove console.log() as the rules specify that returns are fine, you do not have to define the function as well. – MayorMonty May 29 '17 at 0:35
• @MayorMonty this solution specifically takes advantage of console.log functionality to create the colored text, so I would feel weird not including it. – nderscore May 29 '17 at 6:44

# Ruby (*nix style terminal), 54484544 43 bytes

1 byte saved thanks to Value Ink

␛ stands in for a literal esc byte (ASCII 27)

->x{"#{x>199?"␛[31m":p}NO␛[31m VACANCY␛[m"}


A port of my python answer, that is a byte several bytes shorter. I'm new to ruby golf but eager to learn so feedback is appreciated.

• ->x{"#{x>199?"␛[31m":p}NO␛[31m VACANCY␛[m"} saves a byte. The trick is the fact that in string interpolation, "#{nil}" will evaluate to an empty string, and p can be used as a substitute for nil. – Value Ink Jun 17 '17 at 0:45

# Python 3 (*nix style terminal), 55 54 bytes

lambda x:"\033[31m"*(x-199)+"NO\033[31m VACANCY\033[m"


This uses ANSI escape codes. \033[31m Makes the terminal red, if x is less than 200 we will start with one making NO red, otherwise we will have one after NO making it red anyway. When we are done \033[m clears the color from the terminal.

• The multiplication of the color string instead of a condition is brilliant! – Hubert Grzeskowiak May 29 '17 at 15:17

# HTML, 72 71 bytes

<input min=200 type=number><x>NO <y>VACANCY<style>:valid+x,y{color:red}

• You can save 1 byte by using the correct wording... – Neil May 28 '17 at 8:32
• Oh my... I need a vacation. – GOTO 0 May 28 '17 at 14:12
• One of the other answers defines CSS separately. If you do that too, you could save 7 chars with "<style>" (pun intended) – Hubert Grzeskowiak May 29 '17 at 15:27

# Java (OpenJDK 9), 1028988 51 bytes

Yes, Java. :P This only works on *nix terminals.

x->(x>199?"\033[31m":"")+"NO\033[31m VACANCY\033[m"


# bash, 41 bytes

echo ␛[$[($1>199)*31]mNO ␛[31mVACANCY␛[0m


where ␛ represents a literal ESC character (ASCII \033).

• brilliant multiplication! – Ipor Sircer May 29 '17 at 9:45

# Go, 82 81 bytes

This only works on *nix terminals. I wonder how easy it would be to port this to Java... Done.

func f(x int)string{v:="NO\033[31m VACANCY\033[m";if(x>199){v=v[2:7]+v};return v}

• I see a Java port coming. – MD XF May 28 '17 at 2:59
• Ninja'd by 11 seconds. XD – totallyhuman May 28 '17 at 2:59

## BASH / MKSH, 48 47 46 bytes

(($1>199))&&a=^[[31m;echo$a^MNO ^[[31mVACANCY^[[m


Note: ^[ means 1 byte wide ESC character: 0x1b or decimal 27.

^M means 1 byte wide CR character: 0x0d, decimal 13.

# Excel VBA, 76 73 72 Bytes

Anonymous VBE immediate window function that takes input of expected type Integer from cell [A1] and outputs a (NO) VACANCY sign across cells A2:B2

[A2]="NO":[B2]="VACANCY":Range([If(A1>199,"A2:B2","B2")]).Font.Color=255


-3 Bytes for changing rgbRed to 255

• Sorry if this is incorrect, I'm not fluent with Excel. But did you mean to write iif, and does this return the correct value if the input is equal to 200? [A1]>200 makes me think otherwise. – MD XF May 28 '17 at 21:57
• @MDXF Yes, I did mean to write iif (abbreviated from inline if) however, you are right that should be >199rather than >200 good catch! – Taylor Scott May 28 '17 at 23:11

# HTML + CSS + JavaScript (ES6), 74 59 bytes

Takes input as function argument of f, like f(100).

### HTML

<x id=n>NO <j id=r>VACANCY


### CSS

#r{color:red


### JavaScript (ES6)

f=a=>a>199?n.id="r":0


## Test Snippet

f=a=>a>199?n.id="r":0

f(prompt("Enter a number"))
#r{color:red
<x id=n>NO <j id=r>VACANCY

• Gah that unclosed curly bracket is awful... – Beta Decay May 28 '17 at 8:34
• @BetaDecay HAHA! LOL! :D – Arjun May 28 '17 at 9:06
• @BetaDecay I feel with you.... It hurts deep down in your <s>heart</s> assembly level code... – Roman Gräf May 28 '17 at 18:12
• -1: f=a=>n.id=a>199&&"r" – nderscore May 28 '17 at 18:47
• Get rid of second element's id and set the CSS rule selector to j,#r to save 3 bytes. – Hubert Grzeskowiak May 29 '17 at 15:36

# Haskell, 54 53 bytes

EDIT:

• -1 byte: From @Dennis's Jelly answer, the 0 argument in the final escape sequence can be dropped.

f takes an integer and returns a string. Use as putStrLn$f 200. f t|t>199="\27[31m"++f 0|0<1="NO \27[31mVACANCY\27[m"  Try it online! Alas, the colors don't show up in TIO, but you can see that the ANSI codes are correctly placed. Golfing seemed to peter out pretty quickly with this one - not even naming the escape strings seems to save anything. The cleverest bit is recursing with f 0 to use the other branch as a substring. Three different attempts at using list comprehensions all turned up one byte longer. Perhaps the nicest I found: f t=foldr drop"\27[31mNO \27[31mVACANCY\27[m"[5|t<200]  • 54 byte alternative: f t=concat["\27[31m"|t>199]++"NO \27[31mVACANCY\27[0m". – Laikoni May 28 '17 at 7:07 • @Laikoni Oh! I was so close to that but somehow never noticed concat was shorter than id=<< because of the parentheses. – Ørjan Johansen May 28 '17 at 7:15 • @Laikoni With Dennis's tip that's also 53 bytes. – Ørjan Johansen May 28 '17 at 7:30 # Bash script, 60 bytes c="\e[1;31m";((199<$1))&&printf $c;printf "NO$c VACANCY\e[m"

• Just so you know, the downvote was cast automatically by the Community user when your answer was edited. I consider this a bug. – Dennis May 28 '17 at 3:57
• @MDXF Input is via command-line arguments. – Dennis May 28 '17 at 3:59
• @Dennis Ah, my bad. You may want to change the header to Bash script, 64 bytes. – MD XF May 28 '17 at 4:00
• Unless you literally make hundred of edits, you can edit your answer every time you get an idea. Edits within the same 5-minute window get grouped into a single revision anyway. – Dennis May 28 '17 at 4:07
• This doesn't reset the terminal color at the end, which is required. – Sriotchilism O'Zaic May 28 '17 at 20:22

## Mathematica, 67 bytes

Print[s=Style[#,FontColor->Red]&;If[#>200,s,#&]@"NO",s@" VACANCY"]&


or (60 bytes, but may be considered cheating)
This is actually Times["NO","VACANCY"], but appear to be correct.

(s=Style[#,FontColor->Red]&;If[#>200,s,#&]@"NO")s@"VACANCY"&


if(($1<200));then echo -n NO else echo -ne '\033[31mNO\033[0m' fi echo -e '\033[31m VACANCY\033[0m'  This can be probably be golfed, but I'm low on time. I'll come back to this later. -5 bytes thanks to @R. Kap • Replacing if [$1 -le 200 ] with if(($1<200)) saves 5 bytes and fixes the bug of the output not appearing in all red with an input of 200. – R. Kap May 28 '17 at 3:56 • @R.Kap Thanks. OP requested default color for less than or equal to 200 though. – Arc676 May 28 '17 at 5:15 • No, OP asked for all red ouput for inputs more than or equal to 200. – R. Kap May 28 '17 at 5:54 # Mathematica, 47 bytes (If[#>199,Style[NO,Red],NO]Style[VACANCY,Red])&  # C (*nix style terminal), 505552 51 bytes -1 thanks to Wheat Wizard f(t){printf("␛[%dmNO ␛[31mVACANCY␛[m",t>199?31:0);}  ␛ stands for the literal ESC byte, ASCII 27. Call with f(200), 200 being the number. Prints NO VACANCY colored to the spec. • In my terminal, that breaks your rule that it shouldn't change the text color of the shell. – Ørjan Johansen May 28 '17 at 3:26 • @ØrjanJohansen Fixed. I forgot that I run a custom shell which automatically sets the color. – MD XF May 28 '17 at 3:26 • You can change ␛[0m to ␛[m – Sriotchilism O'Zaic May 28 '17 at 11:35 # PHP, 41 bytes ␛[<?=$argn<200?31:''?>mNO␛[31m VACANCY␛[m


␛ represents the Escape character.

# shortC, 48 bytes

f(t){R"␛[%dmNO ␛[31mVACANCY␛[m",t>199?31:0


Where ␛ stands for ASCII 27, the ESCAPE byte.

# GW-BASIC, 7874 65 bytes

-12 thanks to Orjan Johansen

1INPUT X:IF X>199THEN COLOR 4
2?"NO ";:COLOR 4:?"VACANCY":COLOR 7


Prompts user for an integer. Output:

• Hm can't find an online interpreter, but can't line 1 and 2 be joined with :? – Ørjan Johansen May 30 '17 at 2:26
• @ØrjanJohansen Wow... can't believe I completely missed that. Thanks, and yeah, there are no online interpreters. However, you can use the first emulator on pcjs.org and type BASICA to get something close enough, although it may not have color. – MD XF May 30 '17 at 2:29
• Assuming that emulator is good enough: You need a new line before the first PRINT. However, you don't need spaces after the line numbers, and PRINT can be abbreviated to ?. – Ørjan Johansen May 30 '17 at 2:45
• @ØrjanJohansen NO WAY. I've used Microsoft BASIC for eight years and I never new about ?=PRINT. Updating... – MD XF May 30 '17 at 2:48
• You missed the line number spaces, and seem to have a stray lower case x. – Ørjan Johansen May 30 '17 at 2:50

# Tcl/Tk, 96 bytes

grid [label .n -text NO -fg [expr \\$argv>199?"red":"tan"]]
grid [label .v -text VACANCY -fg red]