43
\$\begingroup\$

"The Nobel Prize in mathematics was awarded to a California professor who has discovered a new number! The number is bleen, which he claims belongs between 6 and 7." --George Carlin

In this challenge, you will print all Integers, inclusive, within the given input range. Print numbers ascending or descending according to their input order. That is, for input [n1, n2], print ascending if n1 < n2, descending if n1 > n2.

Since bleen is now an Integer number it may be used as input. It must also be included in the output, between 6 and 7 where applicable. Also note that -bleen exists between -7 and -6.

Input

Two Integers [n1, n2] in the range [-10, 10], inclusive, via your programming language's input of choice.

(Input may also contain bleen and -bleen!)

Output

Print all Integers starting at n1 and ending with n2, including the newly discovered bleen between 6 and 7. Output can be a range of character separated numbers in some form your language supports - that is, comma or space separated. One trailing space of output is okay.

Examples

Input:  1 10
Output: 1 2 3 4 5 6 bleen 7 8 9 10 

Input:  -9 -4
Output: -9 -8 -7 -bleen -6 -5 -4

Input:  -8 bleen
Output: -8 -7 -bleen -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 bleen

Input:  9 1
Output: 9 8 7 bleen 6 5 4 3 2 1

Input:  2 -bleen
Output: 2 1 0 -1 -2 -3 -4 -5 -6 -bleen

Input:  -bleen 0
Output: -bleen -6 -5 -4 -3 -2 -1 0

Input:  bleen bleen
Output: bleen

Input:  2 2
Output: 2

Additional notes

You may write a program or function and use any standard method of receiving input and providing output.

You may use any programming language, but standard loopholes are not allowed.

This is , so the shortest valid answer – measured in bytes – wins.

\$\endgroup\$
18
  • 16
    \$\begingroup\$ Is bleenteen between 16 and 17 also? (and is bleenty-bleen between bleenty-six and bleenty-seven?) \$\endgroup\$
    – Joffan
    Aug 3, 2016 at 18:07
  • 5
    \$\begingroup\$ @Joffan ... and bleenty between 60 and 70? \$\endgroup\$
    – Adám
    Aug 3, 2016 at 18:08
  • 5
    \$\begingroup\$ @Joffan How much is (bleen + 7) / 2 ? \$\endgroup\$
    – Adám
    Aug 3, 2016 at 18:10
  • 10
    \$\begingroup\$ In mathematics there is only the Field's medal, no Nobel Prizes there.... \$\endgroup\$
    – Graipher
    Aug 4, 2016 at 7:48
  • 8
    \$\begingroup\$ @Graipher That's why you shouldn't rely on a comedian's standup bit as hard news ;) \$\endgroup\$
    – Geobits
    Aug 4, 2016 at 9:45

16 Answers 16

12
\$\begingroup\$

Python 3, 132 130 bytes

r=round
bleen=6.1
m=1.08
a,b=eval(input())
d=1-2*(a>b)
print(*[[r(i/m),"-bleen"[i>0:]][i*i==49]for i in range(r(m*a),d+r(m*b),d)])

Takes input in the following example format:

-8, bleen
\$\endgroup\$
6
  • \$\begingroup\$ Does this work outside of [-10,10]? \$\endgroup\$
    – mbomb007
    Aug 3, 2016 at 21:33
  • \$\begingroup\$ @mbomb007 Nope. \$\endgroup\$
    – orlp
    Aug 3, 2016 at 21:33
  • \$\begingroup\$ Very ingenious solution with bleen and eval there, nice one. Another suggestion: use bleen=7/m for clearification without character penalty \$\endgroup\$ Aug 3, 2016 at 23:32
  • \$\begingroup\$ @orlp is there a reason you named the variable bleen and not just a single digit char? \$\endgroup\$
    – Blue
    Aug 4, 2016 at 7:46
  • \$\begingroup\$ @muddyfish Yes, it's necessary for the eval to translate bleen into the correct value. \$\endgroup\$
    – orlp
    Aug 4, 2016 at 8:01
9
\$\begingroup\$

Ruby, 114 100 98 bytes

Input is an array with [n1, n2]. (If it must be two seperate arguments, +1 byte to change the function arg from g to *g. Bleen must be a string, "bleen". Outputs an array of the range. Suggested by @Jordan with his (?) initial version granting -7 bytes, but I also golfed off 7 more after that.

Try it online.

->g{a=*-10..-7,?-+b='bleen',*-6..6,b,*7..10;x,y=g.map{|v|a.index v}
y<x ?a[y..x].reverse: a[x..y]}

Original full program version that reads input from ARGV:

b='bleen'
a=[*-10..-7,?-+b,*-6..6,b,*7..10].map &:to_s
x,y=$*.map{|v|a.index v}
puts y<x ?a[y..x].reverse: a[x..y]
\$\endgroup\$
6
  • \$\begingroup\$ If you make this a lambda you can get rid of .map &:to_s and save 6 bytes, and you can save one more by changing the initialization of a to a=*-10..10;a[4,0]=?-+b;a[18,0]=b. \$\endgroup\$
    – Jordan
    Aug 3, 2016 at 20:12
  • \$\begingroup\$ I.e. ->*g{b='bleen';a=*-10..10;a[4,0]=?-+b;a[18,0]=b;x,y=g.map{|v|a.index v};puts y<x ?a[y..x].reverse: a[x..y]} \$\endgroup\$
    – Jordan
    Aug 3, 2016 at 20:14
  • \$\begingroup\$ @Jordan thanks. Didn't need to use the slicing trick to insert the bleen, though; my array composition is still shorter by about 1 byte. \$\endgroup\$
    – Value Ink
    Aug 3, 2016 at 20:40
  • \$\begingroup\$ Ah, I was counting the brackets; forgot you could omit them. \$\endgroup\$
    – Jordan
    Aug 3, 2016 at 20:43
  • \$\begingroup\$ Should I upvote, or leave you at exactly 4k? \$\endgroup\$ Aug 31, 2016 at 1:10
8
\$\begingroup\$

Pyth, 35 bytes

K++L\-P_J++`M7"bleen"`M}7TJ@LK}FxLK

Test suite.

The first part, i.e. K++L\-P_J++`M7"bleen"`M}7TJ, generates this array:

['-10', '-9', '-8', '-7', '-bleen', '-6', '-5', '-4', '-3', '-2', '-1', '0', '1', '2', '3', '4', '5', '6', 'bleen', '7', '8', '9', '10']

and then stores it in K.

The second part, i.e. @LK}FxLK, finds the sublist indicated by the input.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I thought of such an approach too. Mure interesting if we had to take any int range... \$\endgroup\$
    – Adám
    Aug 3, 2016 at 18:56
  • \$\begingroup\$ ... and especially if we had to include bleenteen, and bleenty, etc. \$\endgroup\$
    – Adám
    Aug 3, 2016 at 18:57
8
\$\begingroup\$

Python 3, 157 145 123 108 115 139 161 158 153 bytes

Saved 22 thanks to Lynn. 17 saved thanks to shooqie. 3 saved thanks to ljeabmreosn. 5 saved thanks to Geoff Reedy.

a,b=eval(input())
s='-'
c='bleen'
d=a<b
l=list(map(str,range(-10,11)))[::[-1,1][d]]
x=l.insert
y=l.index
x(4,d*s+c)
x(18,(1^d)*s+c)
print(l[y(a):y(b)+1])

Input like '-10', '8'. Tips are welcome for a beginner.

Added 7 to account for -bleen. Added 15 to account for reversed input like '8','-10'. Added a large 21 to account for the reversed input signs for bleen vs -bleen.

\$\endgroup\$
16
  • 2
    \$\begingroup\$ l.index('-6') and l.index('7') should just be constants, no? \$\endgroup\$
    – Lynn
    Aug 3, 2016 at 19:25
  • 2
    \$\begingroup\$ l=[str(i)for i in range(-10,11)] -> l=list(map(str,range(-10,11))) \$\endgroup\$
    – shooqie
    Aug 3, 2016 at 19:31
  • 2
    \$\begingroup\$ Though I'm not sure why you need strings in the first place. l=list(range(-10,11)) works as well \$\endgroup\$
    – shooqie
    Aug 3, 2016 at 19:32
  • 2
    \$\begingroup\$ Lines 2, 4, 5 can be replaced with for i in(4,18):l.insert(i,'bleen'). \$\endgroup\$
    – shooqie
    Aug 3, 2016 at 19:34
  • 1
    \$\begingroup\$ @shooqie The for loop is missing the negative sign at index 4. e.g. the list contains two elements of 'bleen' rather than a '-bleen','bleen' \$\endgroup\$
    – Justin
    Aug 3, 2016 at 19:44
3
\$\begingroup\$

Ruby, 141 bytes

->*a{
l="bleen"
s=13
a,b=a.map{|n|2*n rescue s*(n<=>?b)}
b,a,r=a,b,1if b<a
o=(a..b).map{|n|n==s ?l:n==-s ??-+l:n/2}.uniq
puts r ?o.reverse: o}

Ungolfed

lambda do |*args|
  bleen = "bleen"
  subst = 13 # This will stand in for "bleen"

  a, b = args.map {|arg|
    begin
      # Double the number
      2 * arg
    rescue
      # It wasn't a number, so it's "bleen" or "-bleen"; replace it with 13 or -13
      subst * (arg <=> "b")
    end
  }

  if b < a
    # If the range isn't ascending, reverse it and remember that we did
    b, a, reverse = a, b, 1
  end

  # Step through the range, replacing 13 and -13 with "bleen" and "-bleen" and
  # halving everything else
  result = (a..b).map {|n|
    if n == subst
      bleen
    elsif n == -subst
      "-" + bleen
    else
      n / 2
    end
  }.uniq # Drop duplicates

  # Reverse the result if the range was descending
  puts reverse ? result.reverse : result
end
\$\endgroup\$
3
\$\begingroup\$

Batch, 239 186 bytes

@set/ableen=1431655772,a=%1*3,b=%2*3,c=b-a^>^>31^|1
@for /l %%i in (%a%,%c%,%b%)do @((if %%i==20 echo bleen)&(if %%i==-20 echo -bleen)&set/aj=%%i%%3,k=%%i/3&cmd/cif %%j%%==0 echo %%k%%)

Works by looping from 3*%1 to 3*%3 and then dividing by three and printing the numbers with no remainder, however setting bleen to that magic number causes integer overflow and the value 20 is used instead. This is then printed out at the appropriate point in the loop.

\$\endgroup\$
6
  • \$\begingroup\$ @edc65 When was the last time I read a question correctly first time... \$\endgroup\$
    – Neil
    Aug 3, 2016 at 20:18
  • \$\begingroup\$ @edc65 oh, and I forgot -bleen too. Bah. \$\endgroup\$
    – Neil
    Aug 3, 2016 at 20:22
  • \$\begingroup\$ Tried it but no output. Usage example? \$\endgroup\$
    – edc65
    Aug 3, 2016 at 20:51
  • \$\begingroup\$ @edc65 bleen.bat bleen -bleen perhaps? \$\endgroup\$
    – Neil
    Aug 3, 2016 at 20:59
  • \$\begingroup\$ No output, as I said. Is it dos/windows bat language? I use Windows 10 \$\endgroup\$
    – edc65
    Aug 3, 2016 at 21:05
3
\$\begingroup\$

JavaScript (ES6), 158

Nice challenge, hard to golf. Probably the range methods used in Python and Ruby answers could score better even in JS.

(a,b)=>(c=x=>x<-6?x-1:x>6?x+1:1/x?x:x<'b'?-7:7,a=c(a),b=c(b),d=b>a?1:-1,a-=d,e=x=>x-7?x-(x>7):'bleen',[...Array(d*(b-a))].map((x=a+=d)=>x<0?'-'+e(-x):e(x)))  

Less golfed

(a,b)=>(
  c=x=>x<-6?x-1:x>6?x+1:1/x?x:x<'b'?-7:7,
  a=c(a),b=c(b),
  d=b>a?1:-1,
  a-=d,
  e=x=>x-7?x-(x>7):'bleen',
  [...Array(d*(b-a))].map((x=a+=d)=>x<0?'-'+e(-x):e(x))
)  

Test

f=(a,b)=>(c=x=>x<-6?x-1:x>6?x+1:1/x?x:x<'b'?-7:7,a=c(a),b=c(b),d=b>a?1:-1,a-=d,e=x=>x-7?x-(x>7):'bleen',[...Array(d*(b-a))].map((x=a+=d)=>x<0?'-'+e(-x):e(x)))  

function go(){
  var a=A.value,b=B.value
  // make them numeric if possible
  a=isNaN(a)?a:+a
  b=isNaN(b)?b:+b
  
  O.textContent=f(a,b)
}  
go()
A <select id=A onchange='go()'>
<option>-10<option>-9<option>-8<option>-7<option>-bleen<option>-6<option>-5<option>-4<option>-3<option>-2<option>-1<option>0
<option>1<option>2<option>3<option>4<option>5<option>6<option>bleen<option>7<option>8<option>9<option>10
</select>
B <select id=B onchange='go()'>
<option>-10<option>-9<option>-8<option>-7<option>-bleen<option>-6<option>-5<option>-4<option>-3<option>-2<option>-1<option>0
<option>1<option>2<option>3<option>4<option>5<option>6<option>bleen<option>7<option>8<option>9<option selected>10
</select>
<pre id=O></pre>

\$\endgroup\$
1
  • \$\begingroup\$ I think you missed -6. \$\endgroup\$
    – betseg
    Aug 3, 2016 at 21:11
3
\$\begingroup\$

Swift 2.2, 342 Bytes

func a(x:String,y:String){var k="bleen",a=Int(x) ?? (x==k ?(x==y ? -9:6):-6),b=Int(y) ?? (y==k ?6:-6),t=0,s=[Any](),f=Int(x)==nil ?x:"";if a>b{t=a;a=b;b=t};for i in a...b{if i==7 && a != 7{s.append(k)};s.append(i);if -i==7 && b != -7{s.append("-"+k)}};for v in t==0 ?s:s.reverse(){f+=" \(v)"};if Int(y)==nil&&b>0{f+=" \(y)"};print(x==y ?x:f)}

Test this using IBM's Swift Sandbox

Ungolfed

func bleen(x: String, y: String){
    var k = "bleen",
        a = Int(x) ?? (x == k ? (x == y ? -9 : 6) : -6),
        b = Int(y) ?? (y == k ? 6: -6),
        t = 0,
        s = [Any](),
        f = Int(x) == nil ? x : ""

    if a > b{
        t = a
        a = b
        b = t
    }

    for i in a...b{
        if i == 7 && a != 7{s.append(k)}
        s.append(i)
        if -i == 7 && b != -7{s.append("-" + k)}
    }

    if Int(y) == nil && b > 0{s.append(y)}

    for v in t == 0 ? s : s.reverse(){
        f+="\(v) "
    }

    print(x == y ? x : f)
}
\$\endgroup\$
0
2
\$\begingroup\$

Java, 271 bytes

int p(String w){if(w.contains("b"))return w.length()<6?7:-7;int i=Integer.decode(w);return i<-6?i-1:i>6?i+1:i;}void b(String s,String f){Integer l=p(s),r=p(f);for(r+=l<r?1:-1;l!=r;l-=l.compareTo(r))System.out.print(l==-7?"-bleen ":l==7?"bleen ":l+(l<-7?1:l<7?0:-1)+" ");}

Ungolfed with test cases:

class Bleen {
     static int p(String w) {
         if(w.contains("b"))
             return w.length() < 6 ? 7 : -7;
         int i = Integer.decode(w);
         return i < -6 ? i-1 : i>6 ? i+1 : i;
     }

     static void b(String s, String f) {
         Integer l = p(s), r = p(f);
         for(r += l<r ? 1 : -1; l != r; l -= l.compareTo(r))
             System.out.print(l == -7 ? "-bleen " : l == 7 ? "bleen ": l+(l < -7 ? 1 : l<7 ? 0 : -1)+" ");
     }

     public static void main(String[] args) {
         b("1","10"); System.out.println();
         b("-9","-4"); System.out.println();
         b("-8", "bleen"); System.out.println();
         b("9", "1"); System.out.println();
         b("2", "-bleen"); System.out.println();
         b("-bleen", "0"); System.out.println();
         b("bleen", "bleen"); System.out.println();
         b("2", "2"); System.out.println();
     }
}

Call b(start, end). Because the parameters are strings, it takes a lot of space to convert those into ints. Essentially the program treats 7 & -7 as bleen and -bleen.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Nice answer, +1. Was pretty hard to come up with something to golf you answer, but I did. ;) Your method p can be changed to the following to save 6 bytes: int p(String w){int x=w.length(),i;if(x>3)return x<6?7:-7;i=Integer.decode(w);return i<-6?i-1:i>6?i+1:i;}. Also, you might want to state this is Java 7 and perhaps add an ideone. \$\endgroup\$ Aug 4, 2016 at 8:26
  • \$\begingroup\$ Also, I've been able to make a shorter variant in Java 7 based on @LeakyNun's approach of first creating the complete list. \$\endgroup\$ Aug 4, 2016 at 9:07
2
\$\begingroup\$

Java 7, 251 bytes

import java.util.*;String b(Object...a){String q="bleen",r="";List l=new ArrayList();int j=-10,i,z,y,t;while(j<11)l.add(j++);l.add(4,"-"+q);l.add(18,q);z=l.indexOf(a[0]);y=l.indexOf(b[1]);if(y<z){t=z;z=y;y=t;}for(i=z;i<=y;)r+=l.get(i++)+" ";return r;}

Different approach which is shorter than the already existing Java 7 answer.
Also, it's unfortunate that the parameters are potentially not in order, which adds some bytes to swap them around.

Ungolfed & test cases:

Try it here.

import java.util.*;
class Main{
  static String b(Object... a){
    String q = "bleen",
           r = "";
    List l = new ArrayList();
    int j = -10, i, z, y, t;
    while(j < 11){
      l.add(j++);
    }
    l.add(4, "-"+q);
    l.add(18, q);
    z = l.indexOf(a[0]);
    y = l.indexOf(a[1]);
    if(y < z){
      t = z;
      z = y;
      y = t;
    }
    for(i = z; i <= y; ){
      r += l.get(i++) + " ";
    }
    return r;
  }

  public static void main(String[] a){
    System.out.println(b(1, 10));
    System.out.println(b(-9, -4));
    System.out.println(b(-8, "bleen"));
    System.out.println(b(9, 1));
    System.out.println(b(2, "-bleen"));
    System.out.println(b("-bleen", 0));
    System.out.println(b("bleen", "bleen"));
    System.out.println(b(2, 2));
  }
}

Output:

1 2 3 4 5 6 bleen 7 8 9 10 
-9 -8 -7 -bleen -6 -5 -4 
-8 -7 -bleen -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 bleen 
1 2 3 4 5 6 bleen 7 8 9 
-bleen -6 -5 -4 -3 -2 -1 0 1 2 
-bleen -6 -5 -4 -3 -2 -1 0 
bleen 
2 
\$\endgroup\$
2
\$\begingroup\$

Scala, 223 bytes

object B extends App{val b="bleen"
val L=((-10 to -7)++List(s"-$b")++(-6 to 6)++List(b)++(6 to 10)).map(""+_)
val Array(s,e)=args.map(L.indexOf(_))
println((if(s<=e)L.slice(s,e+1)else L.slice(e,s+1).reverse).mkString(" "))}
\$\endgroup\$
2
\$\begingroup\$

JavaScript (ES6), 178 bytes

 (s,e)=>{q='bleen';t=[];for(i=-10;i<11;i++)t.push(i);t.splice(4,0,'-'+q);t.splice(18,0,q);s=t.indexOf(s);e=t.indexOf(e);s>e&&t.reverse()&&(e=22-e)&&(s=22-s);return t.slice(s,e+1)}

Try it

EDIT: Fix for reverse ordering.Thanks Patrick, missed this condition

\$\endgroup\$
0
2
\$\begingroup\$

Python 3, 126 bytes

Input is in the form -5, 'bleen'

l=list(range(-10,11))
c='bleen'
s=l.insert
t=l.index
s(4,'-'+c)
s(18,c)
i,j=map(t,eval(input()))
d=1-2*(i<j)
print(l[i:j+d:d])
\$\endgroup\$
2
\$\begingroup\$

R, 110 107 bytes

Thanks to Cyoce for golfing 3 bytes.

a=function(x,y){e=c(-10:-7,"-bleen",-6:6,"bleen",6:10)
b=function(d)which(e==as.character(d))
e[b(x):b(y)]}

Builds the whole list in order, picks out the relevant ones. Function in the middle named "b" seemed the easiest way to make that happen. Apply,etc

\$\endgroup\$
2
  • \$\begingroup\$ Is all that whitespace required? \$\endgroup\$
    – Cyoce
    Aug 24, 2016 at 0:01
  • \$\begingroup\$ No, and usually I wouldn't have had it. Thanks! Edit: I didn't even count much of it. Must have been half asleep. \$\endgroup\$ Aug 24, 2016 at 13:41
1
\$\begingroup\$

Javascript (using external library) (343 bytes)

(a,b)=>{r="bleen";s="-"+r;c=d=>d==r?7:(d==s?-7:d);i=c(a);j=c(b);m=Math.min(i,j);n=Math.max(i,j);w=i<=j?_.RangeTo(i,j):_.RangeDown(i,Math.abs(j-i)+1);g=i<j?6:7;if(n>-7&&m<-6){w=w.InsertWhere("-bleen",x=>x==-7)}if(m<8&&n>6){w=w.InsertWhere("bleen",x=>x==g)}if(a==r||b==r){w=w.Where(x=>x!=7)}if(a==s||b==s){w=w.Where(x=>x!=-7)}return w.ToArray()}

Link to lib: https://github.com/mvegh1/Enumerable

Screenshot:

enter image description here

\$\endgroup\$
-1
\$\begingroup\$

Python 2, 100 bytes

The first four lines generate the list [-10, -9, -8, -7, 'bleen', -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 'bleen', 7, 8, 9, 10]. The next line gets input and stores it in s and e. The last two lines use .index() and list slicing notation to get the correct range.

a=range(-10,11)
b="bleen"
c=a.insert
c(17,b)
c(4,b)
s,e=eval(input())
d=a.index
print a[d(s):d(e)+1]

Works in the same way as Leaky Nun's answer but developed independently. Stole an input method from orlp.

Ungolfed:

array = range(-10, 11)
array.insert(17, "bleen")
array.insert(4, "bleen")
start, end = eval(input())
print array[array.index(start):array.index(end) + 1]
\$\endgroup\$
2
  • \$\begingroup\$ This is incorrect - the number between -7 and -6 is -bleen, not bleen. Though we have found a new number, the basic rules of algebra must remain constant: 0 is the only number that is its own additive inverse, by virtue of being the additive identity element. Furthermore, eval(input()) is just input() in Python 2. \$\endgroup\$
    – user45941
    Aug 5, 2016 at 0:28
  • \$\begingroup\$ @Mego oh, oops.... \$\endgroup\$ Aug 5, 2016 at 0:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.