54
8
Description
Here's a very superstitious hotel elevator in Shanghai:
It avoids the number 13, because thirteen is unlucky in the Western world, and it avoids the digit 4, because four is unlucky in parts of Asia. What if this hotel was taller?
Read a positive even integer n
from STDIN, representing the number of floors, and print what the button layout would look like to STDOUT: -1
, followed by the next n-1
positive integers that aren't equal to 13 and don't contain digit 4. Arrange these numbers in two columns such as in the above image: print two floor numbers per line, separated by a horizontal tab, so that reading the lines in reverse order from left-to-right yields the sequence in ascending order. (You may optionally print a trailing newline character, too.)
Test cases
For the input 14
, output should be as in the above image:
15 16
11 12
9 10
7 8
5 6
2 3
-1 1
where the whitespace in each line is a single horizontal tab character.
For the input 2
, you should print -1 1
.
For the input 100
, you should print:
120 121
118 119
116 117
113 115
111 112
109 110
107 108
105 106
102 103
100 101
98 99
96 97
93 95
91 92
89 90
87 88
85 86
82 83
80 81
78 79
76 77
73 75
71 72
69 70
67 68
65 66
62 63
60 61
58 59
56 57
53 55
51 52
39 50
37 38
35 36
32 33
30 31
28 29
26 27
23 25
21 22
19 20
17 18
15 16
11 12
9 10
7 8
5 6
2 3
-1 1
Goal
This is code-golf. Shortest answer in bytes wins.
Wouldn't they also avoid
n13
? – Conor O'Brien – 2016-01-08T03:12:58.5931I don't think anyone considers e.g.
6138
an unlucky number over here. Either way, you should print integers that contain13
but aren't equal to it. – Lynn – 2016-01-08T03:25:01.710Okay, cool! (filler) – Conor O'Brien – 2016-01-08T03:25:31.280
2@Mauris 6138, maybe not, but 113? I think the key would be whether you say "thirteen" when you read the number out loud. – Random832 – 2016-01-08T05:41:17.983
Also, how tall can the hotel get? What about floor 666 (which occurs at 456 floors in the "standard" version, and 449 in the more aggressively 13-avoiding version) – Random832 – 2016-01-08T05:46:32.897
12@Random832 What you suggest are effectively arbitrary changes to the spec. The PPCG etiquette discourages such changes after answers have been given, especially if existing answers are effectively invalidated, which they would be in this case – Digital Trauma – 2016-01-08T06:08:30.307
8FWIW, 4 isn't unlucky. 4 just sounds very similar to "die" or "death" in the various chinese dialects/languages. – slebetman – 2016-01-08T07:44:23.660
Is it acceptable if the numbers within each column are right-aligned? I guess yes, because the challenge doesn't say anything about it, but just to double check. Also, will the inohut number always be even? What if it's odd? – Luis Mendo – 2016-01-08T09:39:22.157
@Mauris is there a limit of the number of floors we have to be able to process? Are the chinese going to build a space elevator? – x13 – 2016-01-08T12:10:34.567
@Random832, I'm not changing the spec. Only avoid 13 or numbers containing 4. – Lynn – 2016-01-08T15:04:50.893
2@ThisNameBetterBeAvailable: If your program is limited by something like integer overflow, that's fine, but if your language of choice handles arbitrary-precision integer arithmetic, your code should theoretically work for any input size. – Lynn – 2016-01-08T15:07:10.467
@LuisMendo I'm not sure what you mean: I assume you are working in some programming language that can format the output for you and print a nice two-column table. In the interest of fairness, I would like everyone's output to be exactly of the form
15\t16\n12\t11\n...
, so what you write would not be allowed. – Lynn – 2016-01-08T15:08:51.74310@slebetman: Well, yes, that's why 4 is unlucky. It's still superstition, whatever the origin is! But that's getting a bit off-topic. – Lynn – 2016-01-08T15:12:15.800
1@Mauris my submission can calculate just enough floors to get around the earth, but it can't reach the moon... yet. Time to bring out the ULL's – x13 – 2016-01-08T15:22:31.683
13Wait! Counting the buttons I see that hotel has exactly 13 floors (excluding the basement.) There's no way I'm staying there! – Level River St – 2016-01-08T18:42:10.647
And apparently, zero is unlucky somewhere as well. USA, I think. – orion – 2016-01-11T10:20:59.127
1How should odd inputs be treated? – Black Owl Kai – 2019-01-19T20:55:54.353
@BlackOwlKai The problem says, “Read a positive even integer
n
from STDIN”… Here on PPCG, that means you can assume the output is indeed a positive even integer. Your solution may handle invalid inputs (odd, negative, zero…) in whatever way it likes. – Lynn – 2019-01-21T16:30:47.547