[Question]
  [
# Challenge
Your task in this question is to write a program or a named function which takes a positive integer `n` (greater than 0) as input via STDIN, ARGV or function arguments and outputs an array via STDOUT or function returned value.
**Sounds simple enough ? Now here are the rules**
* The array will only contain integers from `1` to `n`
* Each integer from `1` to `n` should be repeated `x` times where `x` is the value of each integer.
*For example:*
Input:
```
5
```
Output:
```
[1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]
```
The array may or may not be sorted.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so winner is shortest code in bytes.
**Bonus**
Multiply your score by `0.5` if no two adjacent integers in your output array are same.
For example for `n = 5`, one such configuration would be
```
[5, 4, 5, 4, 3, 4, 5, 2, 5, 3, 1, 2, 3, 4, 5]
```
  
[Answer]
# Ruby (recursive), 41 bytes \* 0.5 = 20.5
```
def n(n,i=1);i>n ?[]:n(n,i+1)+[*i..n];end
```
Or using a lambda (as recommended by histocrat and Ventero): 34 bytes \* 0.5 = 17
```
r=->n,i=n{i>0?[*i..n]+r[n,i-1]:[]}
```
(call using `r[argument]`)
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 9 bytes \* 0.5 = 4.5
```
smrhQhdUQ
```
With help from @FryAmTheEggman
[Try it online.](http://isaacg.scripts.mit.edu/pyth/index.py)
---
## Explanation
```
s             reduce + on list
 m            map
  rhQhd       lambda d: reversed(range(d+1, Q+1)), over
       UQ     range(Q)
```
where `Q` is the input.
[Answer]
# APL, 4 characters
[`/⍨⍳⎕`](http://tryapl.org/index.dyalog?a=/%u2368%u23735&run)
How it works:
`⎕` reads user input. As for output, APL by default prints the result from every line.
`⍳n` is the integers from 1 to `n`. Example: [`⍳3`](http://tryapl.org/?a=%u23733&run)`←→ 1 2 3`
`/` means *replicate*. Each element from the right argument is repeated as many times as specified by its corresponding element from the left argument. Example: [`2 0 3/'ABC'`](http://tryapl.org/?a=2%200%203/%27ABC%27&run)`←→ 'AACCC'`
`⍨` is the *commute operator*. When it occurs to the right of a function, it modifies its behaviour, so it either swaps the arguments (`A f⍨ B ←→ B f A`, hence "commute") or provides the same argument on both sides (`f⍨ A ←→ A f A`, a "selfie"). The latter form is used in this solution.
---
Bonus:
[`6-∊⌽⍳¨⍳⎕`](http://tryapl.org/?a=6-%u220A%u233D%u2373%A8%u23735&run) (8 characters, [thanks @phil-h](https://codegolf.stackexchange.com/questions/42536/create-an-array-with-repeated-numbers#comment-100978))
[`⍳5`](http://tryapl.org/?a=%u23735&run) (iota five) is `1 2 3 4 5`.
[`⍳¨ ⍳5`](http://tryapl.org/?a=%u2373%A8%20%u23735&run) (iota each iota five) is `(,1)(1 2)(1 2 3)(1 2 3 4)(1 2 3 4 5)`, a vector of vectors. *Each* (`¨`) is an operator, it takes a function on the left and applies it to each item from the array on the right.
`⌽` reverses the array, so we get `(1 2 3 4 5)(1 2 3 4)(1 2 3)(1 2)(,1)`.
`∊` is *enlist* (a.k.a. *flatten*). Recursively traverses the argument and returns the simple scalars from it as a vector.
[Answer]
# Haskell, 31 characters = 15.5 score
```
f n=[y|x<-[n,n-1..1],y<-[x..n]]
```
### 27 characters without the bonus
```
f n=[x|x<-[1..n],_<-[1..x]]
```
[Beaten by Proud Haskeller](https://codegolf.stackexchange.com/posts/42577/revisions)
[Answer]
# C, 22 = 44 bytes \* 0.5
The function `h` takes two parameters. The first is an `int` specifying *n*. The second is an `int*` which is the output buffer.
```
h(n,o)int*o;{for(n&&h(~-n,o+=n);*--o=n--;);}
```
**Test program**
```
main(){
int wow[999],*i;
memset(wow,0,sizeof(wow));
h(6, wow);
for(i=wow;*i;i++)printf("%d ", *i);
}
```
[Answer]
## [Pyth](https://github.com/isaacg1/pyth) - ~~15~~ 10 \* .5 = 5
```
smr-QdhQUQ
```
[Try it online.](http://isaacg.scripts.mit.edu/pyth/index.py)
Expects input on stdin. Independently discovered algorithm. Thanks @Sp3000 for helping me stick the last Q in there :P Also, irony? XD
Explanation:
```
Q=eval(input())       : implicit
s                     : The sum of...
 m      UQ            : map(...,range(Q))
  r-QdhQ              : range(Q-d,Q+1)
     
```
[Answer]
# Python 2, 53 bytes \* 0.5 = 26.5
```
i=n=input()
x=[]
while i:x+=range(i,n+1);i-=1
print x
```
Shamelessly borrowed @VisualMelon's idea
[Answer]
# CJam, ~~12~~ 15 bytes \* 0.5 = 7.5
```
li_,f{),f-W%~}`
```
This is full STDIN-to-STDOUT program. It concatenates increasing suffixes of the `1 ... n` range, which ensures that no two adjacent numbers are identical.
[Test it here.](http://cjam.aditsu.net/)
[Answer]
# Haskell, 34 bytes \* 0.5 = 17
```
0%n=[]
i%n=[i..n]++(i-1)%n
g n=n%n
```
That's the first time I've ever used Haskell for golfing. Call with `g <number>`.
[Answer]
# Bash + coreutils, 28/2 = 14
[Shamelessly stealing @pgy's idea](https://codegolf.stackexchange.com/a/42555/11259) and golfing:
```
seq -f"seq %g $1" $1 -1 1|sh
```
---
# Pure bash (no coreutils), 30/2 = 15
Eval, escape and expansion hell:
```
eval eval echo \\{{$1..1}..$1}
```
[Answer]
## GolfScript (14 bytes \* 0.5 = score 7)
```
 ~:x,{~x),>~}%`
```
[Online demo](http://golfscript.apphb.com/?c=Oyc1JwoKfjp4LHt%2BeCksPn59JWA%3D)
I think this is probably similar to some existing answers in that it builds up the array `concat( [n], [n-1, n], [n-2, n-1, n], ..., [1, 2, ..., n] )`
Sadly I wasn't able to golf any further the arguably more elegant:
```
~:x]{{,{x\-}/}%}2*`
```
which puts the input `x` into an array and then twice applies `{,{x\-}/}%`, which maps each element in an array to a count down of that many elements from `x`.
[Answer]
# Haskell, 14 = 28 bytes / 2
```
f n=n:[1..n-1]>>= \r->[r..n]
```
example output:
```
>f 5
[5,1,2,3,4,5,2,3,4,5,3,4,5,4,5]
```
# 24 bytes without the bonus:
```
f n=[1..n]>>= \r->[r..n]
```
[Answer]
# C# - 81 (161bytes \* 0.5)
Simple job in C#, hopefully gets the no-neibouring-numbers bonus. Reads an int from stdin, writes out an array like the example to stdout.
```
class P{static void Main(){int n=int.Parse(System.Console.ReadLine()),m=n-1,i;var R="["+n;for(;m-->0;)for(i=m;i++<n;)R+=", "+i;System.Console.WriteLine(R+"]");}}
```
More readable:
```
class P
{
    static void Main()
    {
        int n=int.Parse(System.Console.ReadLine()),m=n-1,i;
        var R="["+n;
        for(;m-->0;)
            for(i=m;i++<n;)
                R+=", "+i;
        System.Console.WriteLine(R+"]");
    }
}
```
Examples output:
```
n = 5
[5, 4, 5, 3, 4, 5, 2, 3, 4, 5, 1, 2, 3, 4, 5]
```
[Answer]
# JavaScript, ES6, 41 bytes
```
f=i=>[...Array(i).fill(i),...i?f(--i):[]]
```
This creates a function `f` which can be called like `f(6)` and it returns the required array.
This uses a recursive approach, where each iteration creates an array of `i` elements all valued `i` and concatenates an array returned by `f(i-1)` with stopping condition of `i==0`.
Works on latest Firefox.
[Answer]
# vba, 76\*0.5=38
```
Sub i(q)
For Z=1 To q:For x=q To Z Step -1:Debug.?x;",";:Next:Next
End Sub
```
[Answer]
# [Haxe](http://Haxe.org), 53 bytes
```
function l(v)return[for(i in 0...v)for(j in 0...i)i];
```
Works with l(6); because of array comprehension.  
Test online <http://try.haxe.org/#741f9>
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 26 \* 0.5 = 13
-8 bytes thanks to @att.
```
Join@@Range[#,Range@#,-1]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b73ys/M8/BISgxLz01WlkHTDso6@gaxqr9DyjKzCtxSHOw/A8A "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 3 × 0.5 = 1.5 bytes
```
rRF
```
[Try it online!](https://tio.run/##y0rNyan8/78oyO3///@mAA "Jelly – Try It Online")
## Explanation
```
rRF
r      Range from {input} to 
 R       each number from 1 to {input}
  F    Flatten
```
For example, with input 3, the `rR` gives us a range from 3 to 1 (i.e. `[3, 2, 1]`, then a range from 3 to 2 (i.e. `[3, 2]`), then a range from 3 to 3 (i.e. `[3, 3]`). Flattening that gives `[3, 2, 1, 3, 2, 3]`), which meets the problem specifications and has no adjacent numbers.
[Answer]
# [Husk](https://github.com/barbuz/Husk), 4 bytes \* 0.5 = 2
```
Σ↔ḣṫ
```
[Try it online!](https://tio.run/##ARUA6v9odXNr///Oo@KGlOG4o@G5q////zU "Husk – Try It Online")
### Explanation
```
Σ↔ḣṫ
   ṫ    range from input to 1, [5,4,3,2,1]
  ḣ     prefixes, [[5],[5,4],[5,4,3]...]
 ↔      reverse,  [[5,4,3,2,1],[5,4,3,2]...]
Σ       concat,   [5,4,3,2,1,5,4,3,2...]
```
[Answer]
## R, 44 \*.5 = 22
```
f=function(n){r=0;for(i in 1:n)r=c(r,n:i);r}
```
A quick test
```
> f(1)
[1] 1
> f(2)
[1] 2 1 2
> f(3)
[1] 3 2 1 3 2 3
> f(4)
 [1] 4 3 2 1 4 3 2 4 3 4
```
[Answer]
# JavaScript, ES6, 66 bytes \* 0.5 = 33
```
f=i=>(g=n=>[...Array(n).fill().map((v,x)=>i-x),...n?g(n-1):[]])(i)
```
Building on [Optimizer's recursive approach](https://codegolf.stackexchange.com/a/42541/7796), we can build descending runs of decreasing length, like `[4,3,2,1, 4,3,2, 4,3, 4]`.
Instead of making same-value subarrays with `Array(i).fill(i)`, we make `undefined`-filled subarrays of the appropriate length with `Array(n).fill()` and then change the values to a descending run using `.map((v,x)=>i-x)`. Also, we define and recurse over an inner function `g`; the outer function `f` exists only to store the value of `i` while `g` recurses.
[Answer]
## T-SQL, 176 \* 0.5 = 88
Since you seemed to miss the T-SQL @Optimizer, here it is in all it's verbose glory :). 
A couple of function options, a Scalar and a Inline Table Valued function. The Scalar function uses while loops to recurse and returns a string of numbers, where the Inline Table Valued function uses a recursive CTE for a sequence and returns a table. Of course these will never be competitive, so I haven't spent a lot of time golfing.
**Inline Table Valued Function, 176 \* .5**
```
CREATE FUNCTION F(@ INT)RETURNS TABLE RETURN WITH R AS(SELECT @ N UNION ALL SELECT N-1FROM R WHERE N>0)SELECT B.N FROM R CROSS APPLY(SELECT TOP(R.N)N FROM R A ORDER BY N DESC)B
```
Called as follows
```
SELECT * FROM dbo.F(5)
```
[SQLFiddle](http://sqlfiddle.com/#!6/b4f86/1/0) example
**Scalar Function, 220 \* .5**
```
CREATE FUNCTION G(@ INT)RETURNS VARCHAR(MAX)AS BEGIN DECLARE @S VARCHAR(MAX),@N INT=1,@I INT,@C INT WHILE @N<=@ BEGIN SELECT @I=@N,@C=@ WHILE @C>=@I BEGIN SELECT @S=CONCAT(@S+',',@C),@C-=1 END SET @N+=1 END RETURN @S END
```
Called as follows
```
SELECT dbo.G(5)
```
[SQLFiddle](http://sqlfiddle.com/#!6/00b75/2/0 "SQL Fiddle Example of use") example
[Answer]
# perl ,26 bytes
```
for(1..$n){print"$_ "x$_;}
```
[Answer]
### JavaScript(readable), 131 bytes
I'm new to Code Golf so this isn't the best
```
function f(n) {
    var arr = [];
    for(var i = 1; i <= n; i++) {
        for(var j = 0; j < i; j++) {
            arr.push(i);
        }
    }
    return arr;
}
```
### JavaScript(less readable), 87 bytes
Minified using [jscompress.com](http://jscompress.com)
```
function f(e){var t=[];for(var n=1;n<=e;n++){for(var r=0;r<n;r++){t.push(n)}}return t}
```
[Answer]
# TECO, 25 bytes \* 0.5 = 12.5
```
a\+1%a%b<qauc-1%b<-1%c=>>
```
The above barely beats the non-bonus version at 13 bytes:
```
a\%a<%b<qb=>>
```
[Answer]
## C#, ~~114~~ 99 \* 0.5 = 49.5 bytes
*(With a little help from VisualMelon's answer) Edit: and James Webster's comment*
```
int[]A(int n){int m=n,i,c=0;var a=new int[n*(n+1)/2];while(m-->0)for(i=m;i++<n;)a[c++]=i;return a;}
```
*Ungolfed:*
```
int[] FooBar(int n)
{
    int altCounter = n, i, arrayCounter = 0;
    var returnArray = new int[n * (n + 1) / 2];
    while(m-->0)
        for(i = altCounter; i++ < n; )
            returnArray[arrayCounter++]=i;
    return returnArray;
}
```
---
~~There is an unsafe version that I shamelessly took from feersum's C answer, but I'm not 100% sure it fits within the rules since you have to allocate the memory before calling the method.~~
**C# (unsafe), 82 \* 0.5 = 41 bytes**
```
unsafe void A(int n,int*p){int*z=p;int m=n,i;while(m-->0)for(i=m;i++<n;)z++[0]=i;}
```
Called as follows:
```
int n = 5, length = (int)((n / 2f) * (n + 1));
int* stuff = stackalloc int[length];
int[] stuffArray = new int[length];
A(n, stuff);
System.Runtime.InteropServices.Marshal.Copy(new IntPtr(stuffArray), stuffArray, 0, stuffArray.Length);
//stuffArray == { 5, 4, 5, 3, 4, 5, 2, 3, 4, 5, 1, 2, 3, 4, 5 }
```
Per VisualMelon's suggestion (thanks!), the unsafe code can be re-made with safe code which reduces the size even further! Still poses the question if the creation of the final result array is allowed to be done outside of the method.
**C#, 72 \* 0.5 = 36 bytes**
```
void A(int n,int[]p){int z=0,m=n,i;while(m-->0)for(i=m;i++<n;)p[z++]=i;}
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 4 bytes \* 0.5 = 2
```
L.s˜
```
[Try it online!](https://tio.run/##yy9OTMpM/f/fR6/49Jz//00B "05AB1E – Try It Online")
```
L                             # Inclusive range
 .s                           # Suffixes
   ˜                          # Flatten
```
[Answer]
### Bash with seq, expr and xargs = 59 / 2 = 29.5
Save it and run with the number as the first argument.
```
seq $1|xargs -n1 seq|xargs -n1 expr $1 + 1 -|sed 1d;echo $1
```
[Answer]
# C#, ~~116~~ 115 + 33 = 148 bytes
Not the shortest code, but... it works anyway :P
```
int[]l(int m){List<int>i=new List<int>();for(int j=1;j<=m;j++){for(int x=0;x<j;x++){i.Add(j);}}return i.ToArray();}
```
Requires this at the top of the file (33 bytes):
```
using System.Collections.Generic;
```
Un-golfed version:
```
int[] RepatedNumberList(int m)
{
    List<int> intList = new List<int>();
    for (int j = 1; j <= m; j++)
    {
        for (int x = 0; x < j; x++)
        {
            intList.Add(j);
        }
    }
    return initList.ToArray();
}
```
[Answer]
# J, 23 \* 0.5 = 11.5
```
   f=.-;@(<@|.@i."0@>:@i.)
   f 5
5 4 5 3 4 5 2 3 4 5 1 2 3 4 5
```
# J, 11
```
   f=.#~@i.@>:
   f 5
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
```
]