[Question]
  [
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
 
 
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/22975/edit).
Closed 3 years ago.
[Improve this question](/posts/22975/edit) 
Provided a digit between 0 and 9 (inclusive), your function/subroutine should print all numbers between -100 and 100 (inclusive) that contain the given digit.
For example:
```
Input: 9
Output: -99 -98 -97 -96 -95 -94 -93 -92 -91 -90 -89 -79 -69 -59 -49 -39 -29 -19 -9 9 19 29 39 49 59 69 79 89 90 91 92 93 94 95 96 97 98 99
```
**Rules:**
* You cannot use strings (in whatever way they are represented in your chosen language) or char arrays. (Except to print the answer to the console.)
* You cannot use arrays.
**Scoring:**
Score = length of subroutine/function (whitespace will not be counted)
The answer with the lowest score wins.
Whitespace will NOT be counted. Please format your code properly!
Some answers are using regular expressions, which may violate the no strings rule, as pointed out by some members. These answers will not be accepted.
Please test your code with `0` before posting.
  
[Answer]
## Whitespace, 834 characters (0 if you subtract whitespaces)
Used [this interpreter](http://ws2js.luilak.net/interpreter.html) to test it.
This took me some 4 hour of hard work and horrible debugging to create. But it is done!
```
   	    	 
   	    	 
	
	    	    	 
			   		    
	  			    	    		
  			   		
		    	     	
   
		    	    	 
			
	  	  	 		
   	    	 
			   	
	  	
	  	  	 		
   	   	  
   	    		
			 
    		  	  
	  	
	  	   	 	
 
   		
	  
		 	   			
  		
	  
   	   			
 
    	    	 
			
	  	  	   
   	 	 
	 	    	    	 
				  	
	  	  	  	
   	  	   
   	 	 
	 		   	    	 
				  	
	  	  	  	
 
 	  	 	 
   	  	  	
   	     	
			
	  	   		 
   	     
	
  
   	   		 
   	     	
   	
		    	    		
				
 	
   	  	 	 
   	    		
   	    		
			   	
	   		 
 
 	   	  
   	   	 	
   	    	 
			
	  	  		  
   	    	 
			   	
	  	
	  	  		  
   	  	 		
  			  	  
	
 	   	     
	
  
 
 	   	  
   	  		  
   	     
	
     		  	  
	
 	
```
**EDIT**: Selectable text provided with HTML tricks. If you copy and paste it from here to some other place, please check if you got exactly `[space][tab][linefeed][linefeed][linefeed]` at the end with 100 or 101 lines (depending if your editor counts or not a new line if the last one ends with a linefeed).
In the case that you can't use it this way, considering space as `S`, linefeed as `L` and tab as `T`, and breaking lines after the `L`'s, here it is:
```
SSSTSSSSTSL
SSSTSSSSTSL
TL
TSSSSTSSSSTSL
TTTSSSTTSSSSL
TSSTTTSSSSTSSSSTTL
SSTTTSSSTTL
TTSSSSTSSSSSTL
SSSL
TTSSSSTSSSSTSL
TTTL
TSSTSSTSTTL
SSSTSSSSTSL
TTTSSSTL
TSSTL
TSSTSSTSTTL
L
SSSTSSSTSSL
SSSTSSSSTTL
TTTSL
SSSSTTSSTSSL
TSSTL
TSSTSSSTSTL
SL
SSSTTL
TSSL
L
TTSTSSSTTTL
SSTTL
TSSL
L
SSSTSSSTTTL
SL
SSSSTSSSSTSL
TTTL
TSSTSSTSSSL
SSSTSTSL
TSTSSSSTSSSSTSL
TTTTSSTL
TSSTSSTSSTL
L
SSSTSSTSSSL
SSSTSTSL
TSTTSSSTSSSSTSL
TTTTSSTL
TSSTSSTSSTL
L
SL
STSSTSTSL
L
SSSTSSTSSTL
SSSTSSSSSTL
TTTL
TSSTSSSTTSL
SSSTSSSSSL
TL
SSL
SSSTSSSTTSL
SSSTSSSSSTL
SSSTL
TTSSSSTSSSSTTL
TTTTL
STL
SSSTSSTSTSL
SSSTSSSSTTL
SSSTSSSSTTL
TTTSSSTL
TSSSTTSL
SL
STSSSTSSL
L
SSSTSSSTSTL
SSSTSSSSTSL
TTTL
TSSTSSTTSSL
SSSTSSSSTSL
TTTSSSTL
TSSTL
TSSTSSTTSSL
L
L
L
L
SSSTSSTSTTL
SSTTTSSTSSL
TL
STSSSTSSSSSL
TL
SSL
SL
STSSSTSSL
L
SSSTSSTTSSL
SSSTSSSSSL
TL
SSSSSTTSSTSSL
TL
STL
L
L
```
[Answer]
**Bash+utils - 20**
```
seq -100 100|grep 9
```
Or 21 bytes if in a script
```
seq -100 100|grep $1
```
To run the script:
```
sh myscript 9
```
[Answer]
# JavaScript 133 - 1 = 132
Surely there couldn't possibly be anything wrong with this version now...?
```
for(k=prompt(),c=console,j=-100;100>=j;j++)if(i=j,0==j&j==k)c.log(0);else for(;i;)if(h=i%10,h=0>h?-h:h,i=i/10|0,h==k){c.log(j);break}
```
---
```
PROMPT: 2
CONSOLE.LOG:
-92
-82
-72
-62
-52
-42
-32
-29
-28
-27
-26
-25
-24
-23
-22
-21
-20
-12
-2
 2
 12
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 32
 42
 52
 62
 72
 82
 92
CONTROL, using zero
PROMPT: 0
CONSOLE.LOG:
    -100
    -90
    -80
    -70
    -60
    -50
    -40
    -30
    -20
    -10
      0
     10
     20
     30
     40
     50
     60
     70
     80
     90
    100
```
[Answer]
# GolfScript [24 bytes]
```
`:x;201,{100-}%{`x?-1>},
```
**Description:**
```
`:x;             - save input value to variable 'x' and remove from the stack
201,{100-}%      - create range from -100 to 100
{`x?-1>},        - filter the range by "index-of" condition
```
**DEMO:** <http://golfscript.apphb.com/?c=MwoKYDp4OzIwMSx7MTAwLX0le2B4Py0xPn0sYA%3D%3D>
[Answer]
# Ruby: 92 characters
```
s=gets.to_i
$><<(-100..100).select{|n|a=n.abs;loop{break""if a%10==s;break if 0==a/=10}}*" "
```
Readable version:
```
searchfor = gets.to_i
$><< (-100..100).select { |number|
  absnumber = number.abs
  loop {
    break "" if absnumber % 10 ==s
    break if 0 == absnumber /= 10
  }
} * " "
```
Sample run:
```
bash-4.2$ ruby -e 's=gets.to_i;$><<(-100..100).select{|n|a=n.abs;loop{break""if a%10==s;break if 0==a/=10}}*" "' <<< 9
-99 -98 -97 -96 -95 -94 -93 -92 -91 -90 -89 -79 -69 -59 -49 -39 -29 -19 -9 9 19 29 39 49 59 69 79 89 90 91 92 93 94 95 96 97 98 99
```
Test run:
```
bash-4.2$ for i in {0..9}; do diff -w <(ruby -e 's=gets.to_i;$><<(-100..100).select{|n|a=n.abs;loop{break""if a%10==s;break if 0==a/=10}}*" "' <<< $i) <(seq -100 100|grep $i|tr \\n \ ) > /dev/null; echo "$i : $?"; done
0 : 0
1 : 0
2 : 0
3 : 0
4 : 0
5 : 0
6 : 0
7 : 0
8 : 0
9 : 0
```
[Answer]
# K - 45 char
Not winning any awards, but K golfing is underrepresented. K doesn't get any prettier with proper spacing, so I'll just leave this as is, because K gets very picky about which whitespace is important and which isn't.
```
{|a@&x _in'@[10_vs'_ _abs a:100-!201;100;0,]}
```
Explained:
* `a:100-!201` - Make a list from 0 to 200 inclusive, then subtract it from 100. Now we have the numbers from -100 to 100 inclusive, but backwards from the question's specs. We can always fix that later, so for now we'll just assign this to `a`.
* `_ _abs` - Take the floor of the absolute value of these numbers, because for whatever reason K thinks that `_abs` should give floating point results. Thankfully, flooring them turns them back into integers.
* `10_vs'` - Expand each (`'`) integer as a base 10 number (`_vs` stands for "vector from scalar"). Note that we did not have to use the Each operator `'` on the functions above because they operate on atoms.
* `@[...;100;0,]` - Amend the item in our list at index 100 (an empty list, which is the result of expanding 0 into base 10) by the function `0,`, which prepends a zero to the front. Without this correction, this function will fail on the input 0.
* `&x in'` - Now, return the indices (`&`) where `x` is a digit in (`_in`) each (`'`) of the expansions we so carefully constructed above.
* `|a@` - Finally, use these indices to index `a`, and reverse the list into the right order.
Usage is obvious, though good luck getting your hands on a K interpreter. (There's an open source implementation at [on Github](https://github.com/kevinlawler/kona) that you can compile.)
```
  {|a@&x _in'@[10_vs'_ _abs a:100-!201;100;0,]} 0
-100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100
  {|a@&x _in'@[10_vs'_ _abs a:100-!201;100;0,]} 5
-95 -85 -75 -65 -59 -58 -57 -56 -55 -54 -53 -52 -51 -50 -45 -35 -25 -15 -5 5 15 25 35 45 50 51 52 53 54 55 56 57 58 59 65 75 85 95
```
[Answer]
## bash ~~55~~ 49 characters:
(not counting whitespace around `&&`)
```
for i in {-100..100}
do
  [[ $i =~ $1 ]] && echo $i
done
```
Executing it by saying:
```
bash filename 9
```
would produce:
```
-99
-98
-97
-96
-95
-94
-93
-92
-91
-90
-89
-79
-69
-59
-49
-39
-29
-19
-9
9
19
29
39
49
59
69
79
89
90
91
92
93
94
95
96
97
98
99
```
[Answer]
# PHP 67 bytes:
```
for($i=-100;$i<101;++$i)if(strpos($i,$_GET[n])!==!1)echo$i,PHP_EOL;
```
Yes, there is a 'strpos' call, but I'm using only numbers!
Here is a 'ungolfed' version:
```
for($i=-100;$i<101;++$i)
{
    if(strpos($i,$_GET[n])!==false)
    {
        echo $i,PHP_EOL;
    }
}
```
For this to work, you can test it here: <http://writecodeonline.com/php/>
Just remember to add `$_GET[n]='<number>';` to the beginning of the code.
Or, on a lamp or xampp server, you can create a page and then access it on the browser, with the parameter `?n=<number>` after the filename.
[Answer]
# Mathematica 28
Sorry, I just couldn't resist.
:)
The instructions are:
"Provided a digit between 0 and 9 (inclusive), your function/subroutine should print all numbers between -100 and 100 (inclusive) that contain the given digit."
---
The following prints all such numbers in order.
```
f@n_ :=Print/@Range[-100,100]
```
As a special bonus, it prints those numbers in the same range that do not contain the given digit. :)
[Answer]
My first attempt here, so maybe I am doing some things wrong, please excuse that ;)  
So, I wasn't sure if I had to add the whole class or just the logic within. 
# Java - 199 characters
```
intx=System.in.read()-48;for(inti=-100;i<101;i++){if((i<10&&i==-x)||(i>-10&&i==x)||(i<-9&&((i/100==x&&i<-99)||i%10==-x||i/10==-x))||(i>9&&((i/100==x&&i>99)||i%10==x||i/10==x)))System.out.println(i);}
```
Here a more readable form:
```
int x = System.in.read() - 48;
for(int i = -100; i < 101; i++) {
    if((i < 10 && i == -x) || (i > -10 && i == x)
        || (i < -9 && ((i / 100 == x && i < -99 ) || i % 10 == -x || i / 10 == -x))
        || (i > 9 && ((i / 100 == x && i > 99) || i % 10 == x || i / 10 == x)))
        System.out.println(i);
}
```
I guess the basic idea was not that bad, but needed too much exceptions, to finally work out for all cases... :/
[Answer]
# C - 104 107 114 characters - 0 = 104 107 114
```
a,b;main(i){i=getchar()-48;for(a=-100;a<101;a++){for(b=a;a&&abs(a%10)!=i;a/=10);if(a|!i&!b)printf("%i ",b);a=b;}}
```
Ungolfed:
```
#include <stdio.h>
int a, b;
int main(int i) {
    i = getchar() - '0';
    for( a = -100 ; a < 101 ; a++ ) {
        for( b = a ; a && abs(a % 10) != i ; a /= 10 );
        if( a | !i & !b )
            printf("%i ", b);
        a = b;
    }
}
```
[Answer]
## R 87 93
Here's an improvement:
```
a=scan();r=-100:100;s=abs(r);r[(!a&!r%%10)|a&(a==s%%10|a==floor(s/10)|a==floor(s/100))]
```
(Potentially) More readable, with notes:
```
a=scan() # take user input of selected digit
r=-100:100 # define our scanning range
s=abs(r) # copy the range as the absolute value for proper floor() calculation
#r[<criteria>] is functionally the same as subset(r,<criteria>)
r[ # when any of the criteria below are met, use that value from the range
    (!a & !r%%10) # case when input is 0, !a is evaluated as "a when a<>0 == true"
    | a & # all other digits below
    a==s%%10
    |
    a==floor(s/10)
    |
    a==floor(s/100)
    ] # R does not require a print command, so this as-is will display the corresponding values
```
[Answer]
**Javascript 116**
```
   a = 0
        for(i=-100;101>i;i++){
        m=Math
        f=m.floor
        j = m.abs(i)
        if((j>10&&f(j/10)==a)||j-f(j/10)*10==a||j/100==a){
             console.log(i)
        }
        }
```
[Answer]
# Prolog: 75
```
f(D) :-
  between(-100,100,N) ,
  number_chars(N,Ds) ,
  member(D,Ds) ,
  writeln(N) ,
  fail
  .
```
[Answer]
## C answer in 98 characters
This is one of the sexiest things I've ever coded
```
main()
{
    int t=getchar()-48,i=100,j=-i;
    while ((i=t-i%10?i/10:!printf("%d\n",j)) || (i=++j<0?-j:j)<101  );
}
```
The older version, with 104 non-whitespace chars:
```
int main()
{
    int t=getchar()-48,i,j=-101;
    while(++j<101)
    {
        i=j<0?-j:j;
        while(i = t-i%10?i/10:!printf("%d\n",j));
    }
}
```
"Works for me" using GCC and CLANG.
[Answer]
# GW Basic: 107 characters excluding whitespace
```
1 input n
2 for i=-100 to 100
3 j=abs(i):a=j mod 10
4 if a=n then 8
5 b=j\10
6 if (b=n) and b then 8
7 if (b<10) or n<>1 then 9
8 print i
9 next
```
Using single digits for the line numbers helps and stripping the whitespace means there isn't really a need for having multiple statements on a line more than once to keep numbers reaching 10.
[Answer]
# GNU coreutils (44)
```
read N
seq -100 100 | grep $N | tr '\n' ' '
echo
```
where `tr` is used to convert newlines to spaces, and `echo` provides one final newline.
```
$ bash ./script
9
-99 -98 -97 -96 -95 -94 -93 -92 -91 -90 -89 -79 -69 -59 -49 -39 -29 -19 -9 9 19 29 39 49 59 69 79 89 90 91 92 93 94 95 96 97 98 99
```
[Answer]
# J - 27 chars
All whitespace is safely removable, meaning 27 characters. Negative numbers in output will have `_` for a negative sign: this is just the way J writes its negative numbers.
```
((e. 10 #.^:_1 |)"0 # ]) & (i: 100)
```
Explained:
* `V & (i: 100)` - Bind (`&`) the set of numbers from -100 to 100 inclusive (`i:100`) as the right argument of the main verb (`V`). The single argument of the entire verb gets piped into the left side.
* `(U"0 # ])` - Use the result of the verb `U` over each number from the right argument (`"0`) to select (`#`) items from the right argument (`]`).
* `(e. 10 #.^:_1 |)` - Given the digit to test for as the left argument and the number to check as the right argument, expand in base 10 (`10 #.^:_1`) the absolute value of the number (`|`), and check if the digit is an element of that expansion (`e.`).
Usage:
```
   ((e. 10 #.^:_1 |)"0 # ]) & (i: 100) 0
_100 _90 _80 _70 _60 _50 _40 _30 _20 _10 0 10 20 30 40 50 60 70 80 90 100
   ((e. 10 #.^:_1 |)"0 # ]) & (i: 100) 5
_95 _85 _75 _65 _59 _58 _57 _56 _55 _54 _53 _52 _51 _50 _45 _35 _25 _15 _5 5 15 25 35 45 50 51 52 53 54 55 56 57 58 59 65 75 85 95
```
[Answer]
# Groovy, 127
```
def x = args[0].toInteger()
for (k in -100..100)
    if (k == x)
        print " ${k}"
    else
        for (n = Math.abs(k); n > 0; n = (int) n / 10)
            if (n % 10 == x) {
                print " ${k}"
                break
            }
```
No strings (except to output the spaces between the numbers), no char arrays or other arrays, no regexes. Tested with 0. Output:
-100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100
[Answer]
## Javascript - 108
Not sure if existing javascript answer will be taken into consideration because it uses regex, so I created one without it:
```
for(x=+prompt(i=-100);i<101;i++)if((j=i<0?-i:i)&&j%10==x||((j/100==x||(0|j/10)==x)&&x)||j==x)console.log(i)
```
Can also be shortened to 101 if x variable is put directly, like:
```
for(x=5,i=-100;i<101;i++)if((j=i<0?-i:i)&&j%10==x||((j/100==x||(0|j/10)==x)&&x)||j==x)console.log(i)
```
It basically checks if absolute values of div or mod operations are equal to the digit (which also works for 100).
[Answer]
**GROOVY, 71**
```
f={z->
  _=10
  (-_*_.._*_).grep {
    a=it.abs()
    b=a%_==z
    a<_?b:b||(int)(a/_)%_==z
  }
}
println f(0)
println f(9)
```
Results in
```
[-100, -90, -80, -70, -60, -50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
[-99, -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -79, -69, -59, -49, -39, -29, -19, -9, 9, 19, 29, 39, 49, 59, 69, 79, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]
```
[Answer]
**Javascript 96**
Using bitwise or:
```
b=Math.abs;
a=prompt();
for(i=-100;i<101;)
    if(!(b(i++/10)^a && b(i%10)^a)||b(i)/a==100)  console.log(i)
```
[Answer]
# Haskell, 86 75 (78 with necessary whitespaces)
```
f 0=[-100,-90..100]
f d=[b|b<-[-100..100],abs(b`quot`10)==d||abs(b`rem`10)==d]
```
Ungolfed:
```
f dig =
  if dig == 0
    then [-100, 90 .. 100]
    else [num | num <- [-100 .. 100], abs (num `quot` 10) == d || abs (num `rem` 10) == d]
```
[Answer]
# Python - 172 chars
```
def f(x,y,z):
    if x%10==y or (x>9 and x/10==y) or (x==100 and y==1):
        print z
def g(x,y):
    f(abs(x),y,x)
    if x<100:
        g(x+1,y)
def h(y):
    g(-100,y)
```
To test within Python:
```
>>> h(4)
-94
-84
-74
...
-49
-48
...
```
[Answer]
## VBA 121
(no whitespace or `Sub` definition counted):
```
Sub t(d)
For n = -100 To 100
m = Abs(n)
o = o & IIf(d = 0, IIf(d = n Mod 10, " " & n, ""), IIf(d = n Or d = m Mod 10 Or d = Int(m / 10) Or d = Int(m / 100), " " & n, ""))
Next
MsgBox o
End Sub
```
[Answer]
# perl, 117 with non-meaningful whitespace chars removed
I think you were looking for something more like this. Reads from stdin, outputs one line per match. No regexps, arrays (or sets or hashes or anything else that is an array under the covers) or strings, implicit or otherwise, except the strings passed to print:
```
chomp($x=<>); for($y=-100;$y<101;++$y) { $a=abs $y; print "$y " if $a % 10 == $x || $a > 9 && int( $a/10 ) == $x || $a==100 && $x==1}; print "\n"
```
eg:
```
ski@anito:~$ echo 0 | perl -e 'chomp($x=<>); for($y=-100;$y<101;++$y) { $a=abs $y; print "$y " if $a % 10 == $x || $a > 9 && int( $a/10 ) == $x || $a==100 && $x==1}; print "\n"'
-100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 
ski@anito:~$ echo 1 | perl -e 'chomp($x=<>); for($y=-100;$y<101;++$y) { $a=abs $y; print "$y " if $a % 10 == $x || $a > 9 && int( $a/10 ) == $x || $a==100 && $x==1}; print "\n"'
-100 -91 -81 -71 -61 -51 -41 -31 -21 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -1 1 10 11 12 13 14 15 16 17 18 19 21 31 41 51 61 71 81 91 100 
ski@anito:~$ echo 2 | perl -e 'chomp($x=<>); for($y=-100;$y<101;++$y) { $a=abs $y; print "$y " if $a % 10 == $x || $a > 9 && int( $a/10 ) == $x || $a==100 && $x==1}; print "\n"'
-92 -82 -72 -62 -52 -42 -32 -29 -28 -27 -26 -25 -24 -23 -22 -21 -20 -12 -2 2 12 20 21 22 23 24 25 26 27 28 29 32 42 52 62 72 82 92 
```
[Answer]
# F# 87 92 - 7
```
let f n = {-100..100}
|>Seq.filter(fun x->abs x%10=n||abs x/10=n&&n>0)
|>Seq.iter(printf"%d ")
```
added 5 chars because 0 wasn't handled correctly. (Single digit values would all be returned.)
[Answer]
This is my first time playing code golf. This looks pretty interesting. I can't win, but I tried and wanted to show what I could do.
**Python: 104 (89 if I can mulligan the import) - if the results must be printed exactly as shown in the example**
```
from math import *
def g(x):
    t = 10
    p = lambda i: x == i % t or i >= t and p(i / t)
    for i in range(-100, 101):
        if p(abs(i)):
            print i,
    print
# g(0)
# -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100
```
**Python: 71 - if the output can be done outside the function and the only restriction for the output is that no violating numbers are printed**
```
f = lambda x: [(-i, i) for i in range(101) for j in (10, 100) if i % j == x or i >= j and i / j == x]
# print f(0)
# [(0, 0), (0, 0), (-10, 10), (-20, 20), (-30, 30), (-40, 40), (-50, 50), (-60, 60), (-70, 70), (-80, 80), (-90, 90), (-100, 100), (-100, 100)]
```
[Answer]
**JavaScript 125 char**
Sorry for the several edits I've been having troubles doing this from my phone :)
```
function c(n,i){o=i||0;h=100;j=o-h;f=Math.abs(j);m=f/10|0;if((m==n&&m!=0)||n==f%10||f/h==n)console.log(j);if(o<h*2)c(n,o+1);}
```
[Answer]
# Dogelang, 42 non-whitespace characters
```
f=n->for i in(-100..101)=>if n in str i=>print i
```
Same as my Python solution, just converted to [dogelang](http://pyos.github.io/dg/).
]