title: Implement the hyperfactorial

text:
# Question
Title: Implement the hyperfactorial
# The objective

Given the non-negative integer \\$n\\$, output the value of the hyperfactorial \\$H(n)\\$. You don't have to worry about outputs exceeding your language's integer limit.

# Background

The hyperfactorial is a variant of the factorial function. is defined as $$ H(n) = 1^{1} \cdot 2^{2} \cdot 3^{3} \cdot \\: \cdots \\: \cdot n^{n} $$

For example, \\$H(4) = 1^{1} \cdot 2^{2} \cdot 3^{3} \cdot 4^{4} = 27648\\$.

# Test cases

```
n   H(n)
0   1
1   1
2   4
3   108
4   27648
5   86400000
6   4031078400000
7   3319766398771200000
8   55696437941726556979200000

```

# Rules

# Answer
# Jelly, 3 bytes

```
*)P

```

Try it online!

## How it works

```
*)P - Main link. Takes n on the left
 )  - Over each integer 1 ≤ i ≤ n:
*   -   Raise i to the power i
  P - Product

```
> 14 votes

# Answer
# Wolfram Language (Mathematica), 19 bytes

```
Product[n^n,{n,#}]&

```

Try it online!

also as @att mentioned there is a built-in for this...

# Wolfram Language (Mathematica), 14 bytes

```
Hyperfactorial

```

Try it online!
> 9 votes

# Answer
# APL (Dyalog Classic), 5 bytes

```
⍳×.*⍳

```

Try it online!

Monadic fork train

First it evaluates range of the input, and dots the power and takes the product.
> 8 votes

# Answer
# Gaia, 3 bytes

```
*†Π

```

Try it online!

vectorizes the operator on its left, integer arguments are implicitly cast to ranges. `*` is exponentiation and `Π` the product of a list.
> 8 votes

# Answer
# JavaScript (ES7), 20 bytes

```
f=n=>n?n**n*f(n-1):1

```

Try it online!
> 6 votes

# Answer
# Python 3, 28 bytes

```
f=lambda n:n<1or n**n*f(n-1)

```

Try it online!
> 6 votes

# Answer
# Nibbles, 2 bytes

```
$*@^

```

Note that this problem influenced how nibbles decides to use implicit args from implicit ops. I'm currently thinking of getting rid of implicit fold since it is uncommonly used though.

```
     # implicit fold since accumulator is used
     # implicit range from 1 since there's things after an integer
$    # first input integer
 *   # mult
  @  # accumulator from fold
   ^ # exponentiation
     # implicit $ since need another arg to ^
     # implicit $ since need another arg to ^

```
> 6 votes

# Answer
# Kotlin, 59 bytes

```
fun h(i:Double):Double=if(i<1)1.0 else Math.pow(i,i)*h(i-1)

```

Try it online!

Longest submission yet, but thought I might as well give Kotlin a shot. Used the `=` format for functions to eliminate 2 brackets as well as the `return`.
> 5 votes

# Answer
# tinylisp, 51 bytes

```
(load library
(d H(q((N)(i N(*(pow N N)(H(dec N)))1

```

Try it online!

## Ungolfed

```
(load library)            ; for *, pow, and dec

(def hyper                ; name something
  (lambda (n)             ; a lambda function that takes one parameter n
    (if n                 ; if n...
      (*                  ; ...is non-zero, multiply...
        (pow n n)         ; ...n raised to itself...
        (hyper (dec n)))  ; by the hyperfactorial of n-1
      1)))                ; otherwise if n is zero, return 1

```
> 5 votes

# Answer
# Husk, 5 bytes

```
Πm´^ḣ

```

Try it online!

```
Π       # product of
 m      # mapping across all values of
     ḣ  # 1..input
  ´^    # x to the power of x

```
> 4 votes

# Answer
# Factor \+ `math.factorials`, 15 bytes

```
hyper-factorial

```

Try it online!

Built-in.

# Factor \+ `math.unicode`, ~~33~~ 27 bytes

```
[ [1,b] [ dup ^n ] map Π ]

```

Try it online!

This could have been 26 bytes, but `^` returns NaN for 0^0. Factor is the only language I know of that doesn't just return 1 for that. So I had to use `^n` instead, which is a helper word used to implement `^` that hasn't been 'fixed' yet.

* `[1,b]` A range from 1 to whatever is on top of the data stack, inclusive.
* `dup ^n` Raise an integer to itself.
* `[ ... ] map` Apply a quotation to each element of a sequence, collecting the results in a new sequence of the same length.
* `Π` Product of a sequence.
> 4 votes

# Answer
# , 20 bytes

```
prod((x=1:scan())^x)

```

Try it online!
> 4 votes

# Answer
# Haskell, 20 bytes

```
h 0=1
h n=n^n*h(n-1)

```

Try it online!
> 4 votes

# Answer
# TI-Basic, ~~19~~ ~~17~~ 14 bytes

```
prod(seq(I^I,I,1,Ans+not(Ans

```

sadly `0^0` or an empty list errors, so `0` has to be turned into `1`
> 4 votes

# Answer
# jq, 42 bytes

```
[range(.+1)]|reduce.[]as$i(1;.*pow($i;$i))

```

Try it online!
> 4 votes

# Answer
# Java (JDK), 51 bytes

```
n->{var r=1;for(;n>0;)r*=Math.pow(n,n--);return r;}

```

Try it online!
> 4 votes

# Answer
# C (gcc), 28 bytes

```
H(n){n=n?pow(n,n)*H(--n):1;}

```

Try it online!
> 3 votes

# Answer
# Wren, 43 bytes

```
var F=Fn.new{|n|n<1?1:n.pow(n)*F.call(n-1)}

```

Try it online!

Alternate:

# Wren, 44 bytes

```
Fn.new{|n|(1..n).reduce(1){|a,b|a*b.pow(b)}}

```

Try it online!
> 3 votes

# Answer
# Vyxal, 4 bytes

```
ɾ:eΠ

```

Try it Online!

Obligatory answer

```
ɾ              # Range
:              # Dup
e             # Power
Π            # Product

```
> 3 votes

# Answer
# dc, 24 bytes

```
?[1+[d1-d1<xr1-d^*]dsxxp

```

### Explanation

This is a complete program, that reads input from stdin and writes the result to stdout.

```
?                       # input
1+                      # avoid H(-1)
[                       # function x
  d1-                   #
  d1<x                  # recurse       : n n-1 ... i+1 H(i-1)
  r1-                   #               : n n-1 ... H(i-1) i
  d^*                   #               : n n-1 ... H(i)
]dsxx                   # define and execute
p                       # output

```

### Output

H(n) for n = 0..12

```
0
1
4
108
27648
86400000
4031078400000
3319766398771200000
55696437941726556979200000
21577941222941856209168026828800000
215779412229418562091680268288000000000000000
61564384586635053951550731889313964883968000000000000000
548914237009501581804104224704637116078267727827959808000000000000000

```

My machine takes almost 0.7 seconds to compute H(200), but it does produce the correct result:

```
114256002424540571298977792354054343003217988447353197803701128087779\
727310773544883222069862169886712875089569689613436517195625058699339\
831616247967378727547253765461789388643475674400611735920545310021028\
378006078740483920058608872101517118552137511462765664553099379243826\
960171887170750794198373595289872526218671094534622811250467573078955\
097722440499909299236803909456886903559422482755722874996888761181995\
575299415208051459908113833797191408981585936952677202993799475038316\
559629150663378834397372775965856682894873495939410259095804412984759\
376802645433107086846121910224544820403394942396165166503784543183923\
373316267239065885057694972898540625272750046246522113004186914354002\
967536413371473458112220769020094756837578527902012213205896270144393\
863599279497755781359466901673079326909202551645285985747551170700716\
842425698975536766498808553756048408306339794216494138288030784286578\
757511579359563917784149939178533514638276262178221710320662541522716\
166268310550789650887610134719729891484651131282509122835031254510412\
859215509732637002095449585308892098589802359045914197581197309643963\
042570582527203047381981490652454323893038445041694758990588984561508\
024977520153869302479414855203541538559245994267482585355022642863859\
784222422005021616964777696793772349735028255170680455712484791660880\
381133647422166704047722699070109094074510187247343055332257496929374\
982064491045838594959100552218107373079642910265887514107042314387137\
231583168255471546888411138370063211060324585902513206145493958317539\
840648935101056767774783896580016743810934173275647035655085909723344\
400585286826414068777563965071196389690941135698863589037499407785370\
931798703443963281315725441703395909623807818562899480337755459429222\
263976154559801703132418440141220192063353095047779835936440544198953\
496106173470542538936478118001519398934406367850808122800102137273226\
951723289344106737093183594520201847490204826536442751006791251960765\
409736570349501810834880546030444722460505622335562771218876927864732\
533831989277488466279926764165356648286028875357501991394907871736473\
399337480995325006099531629623628775557151039011468601336589825839738\
631718648726576082486937471392562052316112813773965598704019732181766\
979636498126699138316658703065343361486555049963171513229287190102366\
294038070909517003192684859103788524924734600167422726737999487560861\
040910125441478016464932490390352767808126453168977619717961242515337\
678589841167345358713873500430963639031923908700261694508782150681050\
006111529466925629252138641356979249757548377531461415227595617743646\
019706623647306680452085764528828628378729906162793797766057848324098\
880977726680150730390074716141211796155230858668012021940942979991319\
892197094655756666501455192326506825509530719155451676296396102560013\
841584265351485313695020472184192704099107932797640710173835532960606\
518538605516574602321430208034314359982648827905481627199797808702727\
344458806167205608568625797981988480548489292548067131307825217362115\
487277151573038609637079476077578954700658210221211043513144482137132\
113794287001433270940578127570053434695653912547579202493901871464470\
764410974150819235945558607363556467922279391141836922743541233760821\
871365085257243448039467666652724537269128483841450819722610910449669\
667767218934240840176992473839442233550613463850853485560398554469357\
611537501209062167152021399590356213475289096528949653047033419077429\
299028564676171187099901772701404490557158793484243417114875079809449\
627812693323373523747772814832161656651663374496734064538978915783865\
719064174822864696226655708942852177545994665514849721267519945794503\
019098476165255673401283399976325921222555982464845071082560857852257\
814145566478967899059920204170727945409097495154492869672134459786294\
588119159908191561922643839816897827104225462279731830827250471252105\
289727169676968836275320004859466161656331082081074381176816967370602\
357442772694553727911750007625712888624429904817070697897964886832493\
345528030314492840383966128843659735252693645758721744757267671336699\
697149807573431757428427239466529780150411631632066022100098544057533\
387989402082327607683479023952713064900546185006785478600337149539296\
663361814407606344949829339294479920368454331595871231338484805775737\
339268396124977267103545541977669058589689418363091692719790628856414\
752071432633359549389607990792617571221154257026279901828952182073374\
160861868734416746968494659933958156742463652295106500468210780119125\
220209380290875380832470409648848082808663586942813054685601333888677\
903229796350639694587698272283080314334773653111218034106708436851163\
056715554656438061557864316343565021443951504379532417965485201636186\
463813912432724675905548790267512971651098333554063940806626704854532\
678674167073399666603479497096163139406079292169446126287164855437310\
733645103657687054384245612640135453530729419221334723538721255762469\
348656691594173954864816605371367857438364854545334435452281244641153\
702780834293385080202596856941397712010881729069210455124793116543955\
764287224835926198843406678698041913931641907309743017824157088832657\
515931712589921404995250184506019056203133181617154100069201866951525\
300872664323283710970049931600220543834155799207559964184227001086729\
978318247276684554857576596547291291791522751007585853793360225113135\
450501518599762144278325251060114811491521595770223299394208499421070\
133134002376834102080109021979719187115415860089714599508435221834288\
106979134790461271826466644755668937746875390891835581995388195707703\
666919259484508094626586130500902421761233473185812236823727560637765\
353284587005782503482049179577624131003496831794473409129318251405306\
686312023625090599797707676764002997295491901065845799891148513188011\
750255365930732717166438760960930254270355434958193721008813937013342\
442685357933848612269061232591941511207731095268816549202309436856983\
863709498625968309204249579255954213842990272453525630818763597799543\
593087313268427793519216838584166922708627220843209392429847694078662\
627081045478537054881042974186251081449455396030353464966077751989172\
967094495553235926368816821576526232804884953832820814720565106292278\
677023212354425827714341638534116865568614053180685437672841412518894\
098874469347176584909301684501882789675804879960815875737873223894302\
068322229857523890186183543936935430404240034004709340156823935334504\
280773088422757352262015925135936299428100399162508993701323816640249\
317502708643002177380916843121414525377166307214659890456197078789358\
755908958395704605757659385312957851526639927217127812638621838046618\
256249655670855709886714485145533985086443137064765377391996261567764\
614649944571049532129160422595979803302687452962711606329612008212827\
794401494192040770665411078681415279435060816655175330979102977082874\
632330444354061833803759173996116082517816249241467318683953133297949\
696966800597273657946143827878859661836812064102045501830604467916228\
427069899293175548188750078304435399590540700476604483395383697312578\
097710820312329606242276447140831589400706797160881537904137892646388\
261066966454548869342350130453494223912785614903507340787315001904795\
688540272824396638149906352594040357284385938277509795452746883194274\
390009993333838096016899929412160162615538212444522338199878096100853\
638701901085648519985630176886727084180895587065782329076867465210575\
281386375663556976026065633532489743239889186305075304808560243262432\
658085969412020827902073591982408638009516334902222599715386120602437\
678310010096587347186053193158239648969456170841664624039286167247669\
514436308002065354268316000349861095951926759431651589488622884486382\
277854033455441602586071384379537383305706042265499575026224506704860\
688406915452474511683218154440889210555179680616817271305312473155544\
143262273531331795805472254371401019589348634412412286987413907792718\
329915124784729596566415082748529970796499261705982501268401723583887\
701661443797764811659857704733113125011378104100970585073283674392976\
859476816730766230843992524449084734798618995888731548845560723062966\
192859122943220390909175950182057052843622022554828023378885550828117\
382718195394157370910647482474167099695486548360631460470999045477378\
132717331452335714187924997815103638622262298849924210205241176668405\
490741524219253278664341011210099915988552406343854573062664870584245\
103886217277906440977065037168659090059763288778505082007530932618466\
494869181704099810631362022702089755491800061458537467852967380851010\
908862739733011423332473338496528317600181547938903583970178021411350\
504107353290656971578124200774189092891257270280529095290550988723728\
135603533746551804333320307013973767695324099720923379543683864817974\
710553868201698590292895333412491357784173524677821074492989035878523\
065616904294807445990638805797254482102285949882214670841897742949328\
311659987640881568459282440548451135162773664037389258355421285035420\
999699985577663763700005757941427315733197266168699581396576204803981\
473126870934075898120336661598190205939756443947057710182924789850055\
001425654550118743113257624420824183938997656885814673594734917916409\
078995498945642404630814171603046441105445059249548610322842910754951\
846627795460490833776103956049657955540015291032378840531042472594532\
860423319860149058941766354088020712438608204454072807575885575852839\
180700772630347090579280688794361068997524503617691544202365939291565\
645671286667544529026174876789733907296960576178709446195376983454472\
164584703777117244823990537583736958740841562740244004026203727555258\
450538750500484541128688250020648123312909872053878444932137569761105\
646598390520596957373979148797644934213546809772428508682350740007209\
819026797315661258929751889448192710982091237434909749464078055542925\
758110822533573122134535676028907089176208169078890508131338313078120\
366292092748543956445763451239618092200751801948183924253225759130045\
402864771211838018815605401626689028050384789832787839775255721097218\
181110343132212865937413848154233885501099705968645937079387543236067\
419341630111614913910492435024464166688710987099886511583318895948003\
248879615736644901850078099348201377864691386256283320069993735388706\
880978227943386880372348195108338420348643722382324037845214076409223\
421605406326543434017961739452074663199250414741826344527959432512472\
288051981715822955586322044373144003885900746941921709703799672502350\
065363701967267734865903791650802227123544971675955949787985267374530\
847885039570559135088894718198400171730871289918834134265582501872441\
817474408532347174649197682421484732565030830602652775869842343897079\
665618967792517232732353781319861024635289426450784800702094918520783\
421946020173070856497710123531146795959596308032645673704792463483238\
508003336793688645287713354332253474988554262325815954309909567664567\
573258648500395650173170779959337702622396455572300230300768415812431\
943010715240963679596296486831129989681871718230599580037772017117033\
315832399335703122496145800075686154721432794663618613863892627375137\
366428360989986599340414088453536386107561090367699159184439260424635\
745591597059093633912447921539583960069923796416538679234874262062410\
163002664653721804674990501848569881038943775993261621385733027297067\
083554262375476401287244101149052235300084299630703460854961311971283\
087073208822293226528612144677097325474675212863261753395272291201243\
727063158190087578787154328368369458561245784693838304278572756604546\
510952636210910525436103646773871458339800106430023155717178920396687\
520423472846663370278770127553170373437626792023727289514355087037311\
140097772419377161850139650623158006220407602434802036169803932182144\
364560440183502624140166248069772217517658503727605438952409331108997\
938796887451122008271640565975335203086775806001724195485708936422425\
137056283019622940342042757720398404950656311129102072111491775765939\
145688292407278548040314549680511643911856331584703069002009015743434\
987416878546802024548849006779822873402507748917427021579312534569977\
361861231854091421381548376451031427272315824402714317215823133557566\
630570188995812896381696487597394215612003133922998761317879400375340\
125754172678973925934340294567607771195422852830929279465841874639010\
009888808918675285586746078546918806973510720653329464320497985376475\
514652191137288767301110502250694677101081566428326927525440430403867\
468662023769524677616162779798242348230999586692878495342514713764186\
714882538090458901781712475105348027738734745293498558256040405894803\
195991677041814864565397732062450568265762161106477446853681187477778\
726005451422916487453440941705450833165526732124577290035369815857754\
177651321505099564890184890808449589507960017238091650940272579801976\
012553611294392411698525056432475991421017871033115166544672308666931\
153046458808727931683807887236625749116358879625843911889493775696035\
689596716234107636539958765668585942904085430988801703856400119630376\
274574597769512867580730016556216727676744713487993170219184593464999\
311291112749880481896882356531818314812757939997704540854301634559210\
168428005707651884236890080120885190924260622549699781701215291431456\
641474519410935152273699234442085712020314906414846783096378915749837\
313543205699498699058727247319542037049467226655708039331544604104781\
409084183109899592118979816757807977852975258979779416901404268104909\
705348928232083022795123709882664565805802427977177013536930315406074\
119798700228696233155965389441167947547520301277280800708044768115830\
471568118316963537054375894947474149197268583279951389007580911096150\
587642304998165318585620851425172746769477143145386873345481245188537\
754898143742686352644071418948819336880282491363012186422360754575220\
279448092609828602552016180377773970908025714516279864286548174974082\
714686202892658851979133054341592863444445185327463440688040605716405\
067027534367643153032569517666086981280522416245349519983986846967214\
042882273846333605336087299637431797991108127634339718858236191873607\
992145012212007858822784503266193271141131224661074334214839250271667\
726722076785306858810448052589267984702881718156816842983856068663911\
962262395537169886395290931248461646122637458717832878921862044114375\
961223925897580056403294305693475540045578718469567147106404825130645\
182596807474482717319438314466506464297165104699880281509113101964645\
644113558063277536948464800478797709703629400329162780840501627821037\
796082859331312091625314594124914131496550405427389764417029031881865\
161566844591130624668157039150013878652923170474308357677476499519615\
694247353253258416153487129434125741231110906666192911231143233291672\
330355835909139214586207813893211012425324068478627916498679629380977\
726349923696052885626801312565943741488193855513659470521916364497140\
595263059255234991151676056428157949653159230890433842121335826208388\
342905112604728437774206247314145114208160560382868989175460790477221\
890350677890961281703135082791138001520406832403763549570484116412249\
411630340091247083693144122332355091861372457253352008769217588001288\
849717267814951643081139792036726924049299132057170441936528548540420\
064033867805971560358101657671048958681419753322017701206905396234428\
135916258956179250871059395091929250943571633006872870216908850580206\
492968748602862989200240660330463405184596960622742947121148050963122\
321259337631048134291686503286606869138604813871549760164086721913518\
637749340223861847791025891443679650627984525254307030025638348279163\
760184818981923247501359438277271636232964640495952052708147067280051\
510417155618166064646769348176921156031703472238576803756454461973221\
654819493213203649089803381920320331786258749203931226197991150138418\
412665064324591666915076933446777039262089089651109035566583869738578\
597506761075170629480218974597816082666310188595749958551973619906326\
148650712257007357155244818379632436183006582758626649517236510683006\
346083500259745147176189562743231550874298895062648811402347137583548\
675098905750258174262052682531224862649985350791958712521075292922368\
595003093091774703254502960834476169407594973424845628114251412090192\
033055714360450494006595575968666327901355614408397215867467966118019\
576690302025344757113309733262077331055580267485085990493403505787838\
624566370526779488899761016359956759522270200707135958413154679827569\
258052868584822095448301696499657831845970412520110100094933597023662\
316700009222296695302631294120144631256162943881147670342787558109037\
638373998645356492446988510858843413188523534457356161957326654858590\
170373845392894491611342691003506990032562657375834824358150900255718\
212803029008165248772179611829216450388154836261406465215609533903379\
234291823957337623177899123066407939187764831440259804897780532314294\
187768806308300849997380071853436999411397630694458010440206190084920\
364271955929368660748369995712502790615902991832507744246091795838698\
522769638481677935709999820969951468648542838681273677603394509504240\
308953934844440452041183172657724693700991437857142495426882365464490\
656305106674560342135144470557427634289016433075831708395587229518538\
740345784633830858370131443824184367717767852454910547209118651010344\
170278635519515658320221573860591898378883482625668496205501948380927\
655730907380466792089697431597474868907457592287486991817027217936644\
429039036949024880832634934485778971951179199938014320341094585037431\
867897462971290143952624609863752298357851890137576299456918192514413\
801163490330448708940809800295269673370776121695018917895759267103596\
712356385972690041695981952213401668647553788833494484654483704349068\
176379519514076345587421597137517924620994702202104196503077589303867\
675313731830281021790349204147751254681000976845402199926482744440837\
651540373296876407741833859447282118791613435919658716973720823338943\
594717898120853679633629496999886962089450217817683016051641978808086\
090736723556850600235255229245277419993691387427177263341235769365551\
729834695110679831584857749889217164198358411783052421365582162149360\
307993926083432465922185547437809273782150112676800043051133743848179\
507430041789107391336645174236054478492193980551977769361095960852905\
792648589491408260015780133323805313428641785267726788361163481200596\
667926844213028421995386505994266261197953159903842353647124717058462\
606195804456403148297397645768181232545874395373205289680341525417879\
379518455846428797752945668078353519178914505729375052075208668206727\
272592661778659138782753383579531751393302026177424043932380082134112\
304097178637741662710535952129056797743416787671115007825195113544105\
800414762132647003564766945538753743418953135801326760189012574025757\
396710397610011038820702402557513848062197209126418415099387964034761\
398231093033942795839030074337011701661581636846153029980618680958260\
742308998894462132581019648670875157214719847690770798407251574511107\
814179573150171473104112574681707827850658431097893612857747330174826\
263221914068851894736118756496739125630025657215461297066696668503577\
183582733041405309694827396016703300218438917954326780070156715389166\
252811797028538773333761911582321084851330319089805968859787814026573\
646629476563087343556603423340827325523779940913099871860140934516188\
332561209093937145532655355122173625611654611354926043249724145062395\
052073403358582466376317856821760549451408367635975857240939403560193\
544160535875531196735080632931626952143747529382108053685709281128550\
909871592283732369684212053409742502659002594127711109142543712695800\
964668096317273980595863102507908763243035048734467097315273670192716\
453090615295589332917732324135882790481157233370637919417730168802570\
745512158460173430843355794887960375318350278147166774927332518782329\
275386354748592633069853120237345941910229584677639028790677553936767\
813561547451464211027958830776412462906122376937072679758250598400339\
993262606250183184159965386752505918305062458782151287361652904255522\
543747897277759806217530894994343172655413398182581681612121938496736\
246719088985499608274563513876622367779465393373781088492229210720940\
639881067172035481989280366082376941532976834093527635529401514366330\
480920065589598817482347629673178135543148398941148123840436738906568\
689721644562620605431787705716472884630393001383812923459261978914853\
520746731592548434175828751037428755037026486707839111075059327125186\
760809267843888455412978048743136553565305004514936125754311545290038\
133113476411189830181873166563424701146947953889262645190552239014423\
479186724429640510640861075472230063648938881018870060968494482689516\
470150615336695757696184691763777764571491211746536525826581200382784\
605048388142804433635261164053724449418044162892154965646897057026861\
825789232153560082382586610167238788922139435234549283511836608514919\
974792081235167878301494357826304603864897832044708820907368556324046\
004658209312689805738179663008251252674020278832364456345461955022865\
901541110979739876238776312716778351664263063148749685831874832132016\
935035662777717441736545169081531353892410317684943418619599602983211\
424184625311114459460166018052595314630063133375510973311332443179025\
430071437113318883337924946520194725946143840301669209247618491596869\
860173921931370251854462447254511938184185608158210889650209973353848\
709587977807510498484825736181853375451441884380345067688458992092705\
201032496281343674420762320800084135089658792761869184762558806726676\
722458885523590174826474588896231438620097505667947655896718595462296\
073149666204192795203339103128540827107637425053771608250143437698557\
563602741277179793953927426431484612463294041151573622436307805492181\
876291160640064431719636789472314597957573238616645867471630699310482\
878202680466808957828942443566435405022152223504211815437604019790140\
352872467602517381951971882961416597409274884152966514052697974929452\
665027793695015778955965479075442935816241693073367882618572751594589\
233332763571199270073344864323556528614492269184498420264356194305615\
857727851288186636797024506940862150561080428526864057887939002534833\
217825476912788772547258529042674975441187757934184514203802802167837\
147392045462453011001438365392835225710572890221334777983092342949532\
868689408224926079952260855610448736367597882931687183102425507238269\
350671010537707473483269683444914211617226098220802284536428111841021\
355314413825525092408785132949971412943096362996439440725692261405299\
307258200399719962027229993095100541076413611352139497423587018295295\
733263490522360083662929196544565837957602047504540075089561711238004\
034860643130645844174467891334579002129171400079540258966611530625073\
574579537699621459654573062084740258612527512591500081306982149777410\
740290148147295694078336177308080249486577913410339219097486516457786\
845544171494564298759086142864890534059376979463906901088806630448353\
636096572871854504331730452532484411175697139592881541769738473473501\
712004493344258375971665263709468683587321755927947969108354410237014\
622630703966864710147906778218511531246507803307199958593420532473567\
565338941629308172125890217096302195764174165228707151304339280199397\
308288128401592847641643775412416310732509438568791320603475823678213\
022091118173309854694279041928766771888599086244343677301891998549396\
563784328741226437673040978842688696069460803264848555813028336564909\
915911729088504504385439303693869743774004188440858489234825773966439\
034787945703214397718612107720992665600929489208194882429934865386410\
161115173865982683536124076579147099148505092826111112162726946323923\
139510572435234258930966885308790903440842746447356148569569613011866\
216181017947765400323520849488099226865879685849795232175081223157195\
558113479584013517247486158682510281822439736394004394576804296311483\
351867976357203923346203000720371078664247477194715030805264065168164\
569150139879569137943947304661266767151775830577387052301128796128178\
850612741616402622378092347975800584931763715144855238926949360664959\
901934960478488277241384228916947176273846643398938259717770068619213\
014487628266764663292361016953761364719861839113749885418576027074151\
042227017329247056848702075777200168698630056385228682662050087522766\
447910673436514156005878826955500834129864964744197436204252897718702\
140935816928099490760288979327872784783800062445180868891140814201746\
324920232428770583016061424533155666267075515886721407197157139617172\
925490167869130332346357795391916572750248424895052516323326428107724\
137758314910463829058203923431106387112309788487602414624710825158177\
964114057894343181183813244756477920394161657833992924683207226012989\
176214196381796431783415316737367036887146793201669533134930615758349\
947223575783239017366550781734221690665045190947669486016226383725404\
770500226241189927619067594575715556154029052556931773345332242188757\
583235984278742603970474190403890130765749990367903252262002072587910\
429054774362068368774173941070297008442489294012009854536258830415862\
001026233601932344280848478311160293863396081520870580210115748436524\
657593623927560968681489580983408355730739817090564200452344480956466\
381973804084046550012066308187061061100110433589729129116029838272092\
901063648710371584105178456534823033698557959547864668022626855435088\
024359991640953946734473401247145052161022214741899909693164691548573\
821785788946845900456932321418241684343132825893391173058763344836847\
561532940469059613092910143220708525884711120599623251659635879284306\
638801656363654771702535511935418881751805284684639099720239245439664\
571842387562222732097503344638539281322245536316693520241269544702385\
049026321864386637211322748517569828937467849864554760880814644586902\
817967247583917815946609090107550203264295298049898171083475299519485\
282963287445433963699470262712938411098771816976399495400566249571554\
094495292701957093458478414339743747576653696376752337387560862213437\
171824313862829623700800362750977008073325563635225466282360187411791\
004460727184883484132079024845042715007472443596920902083444577226102\
532571137758684844047433693020711502451132357889672168805441775716452\
471223267485604392625754951730382003113622464055081487391284375971238\
853510627596734712602568020285819183336971657562681282095948698659234\
622044625115938725879037169105695234784581029833751973597798676995302\
820884283310795836154247808946969995709972175704217930343337176372368\
862218152343059149076729388531979947396606020581038592064065753946089\
640553006735037214127820206440877419296330789981018521912638631997758\
154425722605472882333085781306809018684379163283706047649566390105938\
809942463192339285589573741721981180866761153351707263614777114324027\
136937248695379341939585067028628395598691094985690489914777669408583\
746705372076602176542601034547167613728331521534397507629206646312256\
534389673241695353105144035296082219501881690212574125509794054226513\
021405438270518614391742936205107159583300586830731485581286071874470\
727979146719804857783111177975437027458797939861069790512476711658674\
604230600339893922108479411334570557026813885541027537801880370343641\
023092718791324902103002359243661089565315113361994869576663697256249\
871813213413860690428249292925393115314038327834441363912113929007244\
105471054120698871274356091169876130969421130575239706338621628737248\
013101040294797899746928168358267493688407646225609161528591367536543\
750216752349842458665061074845656012652829943203210569645609847648814\
464710028370158307713272436594791806761106756447396480204361732530948\
047135168932828677349682361477634216624699993497496226478447072051536\
537255860545682337598542734838920307113252752500355434131067856495860\
013015939155932613207379195719908219623615714946387317825854512782265\
937569392814353157780475720686522817497914676681978626797926015043212\
826447031437776044826145179616020689954105388440566444703570607428452\
666825975085482722275544761731568680350317329391266355823582648567151\
947184773262263887240258693650257727510270752946231093646966589567787\
620541476932789987792695230980505405781968028822750078627313420324636\
601974910918848756407395140464009616507265266662863541465532812264494\
701633405156590660566452973010384370953314634322907040294450198353359\
957924325079183731192016465188487102068495632766765696940620843045103\
075957849189229063712905056032682667355175647119287597317113053888818\
341747269372365744795936558893311837335313287268687137649853296271832\
132369232948513470597966489726144074597206798929415298656496523421111\
438648338467916198955418864697867358689690541049939526892432203616666\
140157354244656146942523547307257405470211487674868073790307956335298\
035604188659325178691582979462715732209779303725246839056014094195154\
353820392910656204599835271073979873482650919077963655893924294796451\
071058930326741588268399079872254763237331178544518654879897999507167\
887498691051777847315585246832306484530047575270468824468839052404478\
471209601574499599308373476806751619934920860932630254791766257400546\
678194740441580832758218048544328980079529926710475069635876888842466\
467601583225867324238379637406226419707584550480244266279922404975917\
076093198953314433166768787654670557582769176583516340512714290053869\
488503951481971926825225950809407051148355971332272041694340467202263\
110935023726355678876173054870475696464256078760528321123516989048437\
905956100976188680575762923547321486475620783046279082273767387016824\
192792115286420878195296354046581539918274861338294922615905787217630\
753697407328812404074746964527035054665330473788617312281599693667903\
884726439880556302179216802454355012570038449126286996206666650775493\
528788476341408273837500438601870416699570809752085526061727790246214\
345643727730520403638924836303813927425447168031067163854295638774643\
166925696428378811144048893909874892635249403446686352691414736194313\
298767484562415849033332860270431449712286909235097808003929552365629\
010360548150077790573248056575513757799999890275575803774798799936015\
705905616634068871497563319841541352544107825662325607124684540278874\
608498624966561241559324542726007033114316454480672240712785896185764\
018459995360582270280586015978104402627028899003008502473747055638994\
967693615667231861323852556312680406367619704217960527830076328909665\
965806712800730336437160882833491675135268112563043378424238104782680\
959602102200424228996956152636857516180424517857400628028239135084923\
094773283114860671676978258922786514794732997721390398253472889571181\
542100313183931206138889694321740603908008622135736073752391733441636\
975148234408515167723600503139787211196698575465893988829247150988295\
132937089264063096302850653741709786986733436740774656976239880063657\
116155268958086159207748442275467563439789929514686396554465496658320\
223447220380884994806499212763873883811980450535445134692803972297225\
867200805366193198427695091115005764789732413669084712930690653442040\
106813786879863642703849455004180398239402073854230429039162641031954\
629435099190465441189701444312997824242458302224265488820857153390295\
433793663904480181503821987893778163121705707885184807286156520157629\
597511728693723440564167397261196843175017576158234990810817702896131\
719777996015606434124732743140927899396903532009620709667134228528325\
848706155364762181691764906498404995473573942979224307302520686325900\
288588511145953186978555460750414834235036978817588590166303626158325\
467769294871096811226986831480934663697186308993101874698672583904437\
163465158962552331778051757595797546950242290952793645521079004895039\
692767591940245446458333450596276630537891924213895070280398426097844\
530715344299379556436113658378942976207843994805006705871918214642436\
109945838548091417431928423665728188757851328090987241230795008197684\
315848649413968970776608596456806202072136369956191814042287222372420\
376209481097924531222327898301388536719301209812529374055978383161560\
402366674953377258306488393460543898212575858060374138609143943928859\
421499452693460735272584637554217829456324966124714620484172913424446\
250636641856678652492289914229876278180893702329869197654678473185792\
094874734672934868913884518473192107135666898214464737134834616023649\
053147415067806966481952994992502849916799522073929134809911363179677\
895671189148802338738965744455969389857438105112202482394405648155050\
107148182005207110004872831031995654451276551356170911494177294990239\
706406481375465466239414677940243242307424235254719725545446624971669\
702152385191708483627545184792059676994807387702668551969466174546191\
070089976167204039385542807339087642680041473305403563782932907930025\
137631116987099138156108731309442818766102387852144495815142081633981\
632881697289008544444602806582589282128339148425329485634849848220805\
882301325917949871098113905536521369117102228224267823573270306372102\
733761111537455389558353499292211244045077468444864626142113431527586\
522286466400715414584503504772063203681892773106418220004132714081774\
597491999689729300930217473244191652387960550998436458561695613745236\
001166814296581318010803425510340274430917394158798175053338323409296\
895304078316728847185492126230467648404918731759558489275204921648189\
641334613191196227133110671760170019469237970548463261174795407272273\
522594027490266679150920541151365410195788704615740727927544780544422\
598110239988012126879177000540770749825882570260436809736803340431649\
136968190510191903550704362810196734029394585868150873111624960230230\
557742069350224866922860141599641459998468635023793968673951162897119\
728086035656539953320600711628909574730519685523709373470327540705653\
335220915475511410416276072511187233012726872585473193916894040338571\
374438826193136849996054292140905498913040046174642438233669539176310\
583789607407253512180368844437606025278249024331609799279741279611616\
861322584297518411616294781785530343484052036928017813197714542874623\
893104213468783249037341094505389577141052425828443310012958430792311\
727117988346582534694572112528868607300926008059143735064550160993534\
371893959294190897252785800898998220518312815414328282874244854542483\
084144884284661147300876442953535032740155789184698983999831384346153\
983006391197340820087681150346256250121310000144506507275816653211852\
630981975984817089090736179427993067512616781166472204275999534793553\
617322021833089272400054973894297458318063353685017787841264474553106\
360829049698395091798134340765126619660886558810014489484062709914663\
708741730650944920828694430958398777612704295668727426847767255490582\
442679545627467864278473335035173682763601472415196578002079707749577\
314107135213271993728277051735738264251975836466432512732611786689972\
608699337829948196681354684107480481385484849536484464106863440975075\
994217657465056219979904595946381966476849760448223076261701459070061\
687625054331070175625148912661262855682533836542470290189307124949454\
672111611301805004282852900469603204454324036160696770568960944006915\
594827374701825793755790511037718231065384570551424914193952437022019\
147130808230140601516999108348126846206887388610494786068336045545230\
386547383991447354800219696499145798056154296637585126096623520286444\
288305461145769481278589644578052606086180987165823906712158053404792\
980245030450164180495915810341531071371713245374578291912729968835571\
659825921274987410512270834924930038942448094826206189084393728747672\
357486250170830682722765817202938882549637223733854649840690650685232\
211002887389219217763704500338914117582617774854375481599185641152046\
183882661395114967337515949838169059628528759746112017143381482333240\
207636582516552896998276786656377571917952133344673723723199179946376\
062254968796003889455221680129540086287321979565069006140531343219593\
747069127462641245536369725942802473102446619255641348424461524297528\
641759974893850890344358331952587334415026185630433554813105770680276\
206280811154949857037528958921963356897630116085109662629658178710778\
798507677725507889134611505315019012251749685690615365792458854857564\
533772662584359952011155264798453844727367592264801349010155252265810\
515246872918204705203793356728720160385276922933864379463998271968011\
571842050057502044481500963066684456034610372353292476835007171599185\
633205112254564334103161056277370091676704684362484674751703624041192\
483451798952663197567989367387817982243873922712260253289081890271484\
747615351738812175971046116046683715704512701857342532265087086607996\
935283737670167056570125886297302351164891412546399612213734288573556\
707802998705475256939453877325826737570250328135497596341563973604069\
510058749824467593715612892797143945980953495801551897876585896910826\
657340220056000137661513683486183600171373811125423027860468400737050\
207216308417605601896328260029394054079292835908268096879154275973758\
803537767265303505542897864749285971624839089144357359776006475483809\
144785869118854493414954429886053110057911071312486249141267331932731\
443170671560086590341048521718826157724599080397854324398250330127048\
599828584475615760524773238222102476324281852003060478889467087936064\
942127015543352629999555455572774241802799902310803374356753670810717\
627142023717059360295954738858332133152053518410378971332898862617963\
385643221635046420724460061022318008822037969715733460287810128018162\
609928288493671713129317148472599626406209968454082954389237826444459\
758905973724812897657188701627543464370788843117544465505781860719350\
587987395303959379133404503898926022219829986363314693902502804136730\
055576160428616527247857010585845882973679162782760983001119225850793\
470860387219780160062333082975943454952693122775459243261504221260853\
490483200000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000000000\
00000000000000000000000000

```

Larger values work fine, but exceed the maximum answer size allowed here.
> 3 votes

# Answer
# Scala, 40 38 bytes (supporting Big Integers)

```
1.to(_).map(x=>BigInt(x)pow x).product

```

Provides exact results up to crazy large numbers with several billions of digits, namely up to `Hyperfactorial(2^31-1)`.

Saved 2 bytes thanks to @user.

Try it online!
> 3 votes

# Answer
# Brachylog, 7 bytes

```
⟦gjz^ᵐ×

```

Try it online!

### Explanation

```
⟦            Range: [0, …, Input]
 g           Nest in a list: [[0, …, Input]]
  j          Juxtapose: [[0, …, Input], [0, …, Input]]
   z         Zip: [[0, 0], …, [Input, Input]]
    ^ᵐ       Map power: [1, …, Input^Input]
      ×      Multiply: 1 × … × Input^Input

```
> 3 votes

# Answer
# K (ngn/k), 6 bytes

```
*/&!1+

```

Try it online!

* `!1+` generate `0..x` (e.g., with an input of `4`, generate `0 1 2 3 4`)
* `&` take `n` copies of each `n`, e.g. zero copies of `0`, one copy of `1`, two copies of `2`, etc.)
* `*/` calculate (and implicitly return) the product
> 3 votes

# Answer
# Thunno 2, 4 bytes

```
RD*p

```

#### Explanation

```
RD*p  # Implicit input            6
R     # Push the one-range        [1, 2, 3, 4, 5, 6]
  *   # Each to the power of...
 D    # ...itself                 [1, 4, 27, 256, 3125, 46656]
   p  # Product of the list       4031078400000
      # Implicit output

```
> 3 votes

# Answer
# BLC, 8 bytes (61 bit)

```
0000010101110000001011010011100000010111101100111010001100010

```

Works for Church encoded numerals with `1=i`. The code is derived from the common `fac` function. Degolfed to bruijn:

```
fac [[1 [[id (1 [[2 1 (1 0)]])]] [1] [0]]]
    id 0

hyperfac [[1 [[exp (1 [[2 1 (1 0)]])]] [1] [0]]]
    exp (0 0)

```
> 3 votes

# Answer
# 05AB1E, 4 bytes

```
LDmP

```

Try it online or verify all test cases.

**Explanation:**

```
L     # Push a list in the range [1, (implicit) input-integer]
      # (note: input 0 will create the list [1,0])
 D    # Duplicate this list
  m   # Take the exponent of the two lists at the same positions
   P  # Take the product of this list
      # (after which the result is output implicitly)

```
> 2 votes

# Answer
# MATL, 4 bytes

```
:t^p

```

Try it online!

First MATL answer!

Uses the same range-dup-power-product
> 2 votes

# Answer
# Zsh, 33 bytes

```
for ((a=1;n++<$1;a*=n**n)):
<<<$a
```

Attempt This Online!
> 2 votes

# Answer
# Raku, 17 bytes

```
{[*] [\R*] 1..$_}

```

Try it online!

* `1 .. $_` is the sequence of numbers from 1 to the input argument.
* `[\R*]` is the "triangular reduction" (scan) of those numbers with the `R`eversed (and thus right-associative) multiplication operator, producing this list: , × (-1), × (-1) × (-2), ..., × (-1) × (-2) × ... × 1.
* `[*]` is the product of those numbers, which contains factors of , -1 factors of -1, etc, as required.

If the input argument is zero, `1 .. $_` is an empty range, `[\R*]` applied to that range produces an empty list, and `[*]` applied to that list returns the multiplicative identity element 1.
> 2 votes

# Answer
# Python 3.8 (pre-release), 59 bytes

```
from math import*
lambda n:prod(i**i for i in range(1,n+1))

```

Try it online!
> 2 votes

# Answer
# TI-BASIC, 13 bytes

(TI-84+ only, for `randIntNoRep(`)

```
max(1,randIntNoRep(1,Ans
prod(Ans^Ans

```

Takes input as the last expression entered, like so:

```
0:prgmH
               1
2:prgmH
               4
4:prgmH
           27648
5:prgmH
        86400000

```

NB: TI-BASIC is a tokenized language; that means the textual representation of bytes can be multiple characters. In fact, e.g., `randIntNoRep(` is a single character that cannot be edited as one might edit an ASCII string. This program is represented by the following hex bytes (if I translated it right):

```
19 31 2B EF 35 31 2B 72 3F B7 72 F0 72

```

Based off of this site. All tokens are one byte, with the exception of `randIntNoRep(`, which is represented with two bytes, `EF 35`. `3F` represents the newline.

## Explanation

`randIntNoRep(1,Ans` returns a range of numbers from `1` to `Ans`. This is, as far as I can tell, the shortest way to generate a range. This occupies 5 bytes. For `Ans = 0`, we get either `{0, 1}` or `{1, 0}` depending on the RNG. Since TI-BASIC errors out when trying to compute \\$0^0\\$, we need to remove the zeroes by taking the max of each element with `1` (`max(1,`. Even though we compute `1^1` twice for `Ans = 0`, this does not affect the overall product.

Next, we simply compute the hyperfactorial factors as `Ans^Ans`, raising the list to the power of itself. After, we take the `prod(` of this list, returning a single number.
> 2 votes

# Answer
# Pari/GP, 18 bytes

```
n->prod(i=1,n,i^i)

```

Try it online!
> 2 votes

# Answer
# Rust, ~~57~~ 45 bytes

@alephalpha gr8 m8 8 outta 8 (they use fold/reduce with a ~~clojure~~ closure instead of recursion to avoid function boilerplate)

```
|n:i128|(1..n).fold(1,|p,i|i.pow(i as u32)*p)

```

Try it online!

oeuf
> 2 votes

# Answer
# Python 3, ~~47~~ 41 bytes

**new code**

```
z=lambda k,a=1: z(k-1,a*k**k) if k else a

```

**old code (for python 3.8)**

```
lambda k,a=1:[a:=a*i**i for i in range(k+1)][k]

```

Try it here!

**Explanation:** ~~Looping through and getting each element, we assign and insert with the walrus operator (I love this thing haha), and return the last element (Which, here, is k saving one more byte instead of using -1!). I am also making use of the default value for the lambda to assign 1 to a, since I can't assign it inside the lambda. Note that i lose 2 bytes in range(k+1) since the range doesnt go to the last number, but I don't see a way around it.~~

Getting rid of both the walrus (rip) and the range (yes!), it is done with a recursive lambda, saving a whole 6 bytes! We multiply the values and store the result, which we send to the next iteration of the code until k = 1, when we can just ignore and return a since 1^1\*a = a.
> 2 votes

# Answer
# J-uby, 26 bytes

```
:+&1|:*|:*&->r{r**r}|:/&:*

```

Try it online!

I want to remove the inner lambda, but `~:**` doesn't seem to work in its place. Might be a bug or I'm missing some argument error.
> 2 votes

# Answer
# BQN, 10 bytes SBCS

```
{×´⋆˜1+↕}

```

Try it!

#### Explanation

<pre><code>{×´⋆˜1+↕}

{        }   # Anonymous function / block
       ↕    # 0..
     1+      # To 1...
   ⋆˜        # Raise to the power over itself (1*1,2*2,3*3...*)
 ×´          # Fold using ×
```

> 2 votes

# Answer
# Vyxal, 4 bytes

```
ƛe;Π

```

Try it Online!
> 2 votes

# Answer
# Swift 2.2, 57 bytes

In an unexpected twist, I'm putting the old version of Swift nobody uses anymore as my main answer.

```
func h(x:Double)->Double{return x==0 ? 1:pow(x,x)*h(x-1)}

```

## Swift \>=3.0, 77 bytes

In Swift 3, `Foundation/Foundation.h` is no longer exposed by default, and you have to explicitly `import Foundation`:

```
import Foundation
func h(_ x:Double)->Double{return x==0 ? 1:pow(x,x)*h(x-1)}

```

## Swift \>=5.1, 70 bytes

In Swift 5.1, the `return` keyword becomes optional:

```
import Foundation
func h(_ x:Double)->Double{x==0 ? 1:pow(x,x)*h(x-1)}

```

TIO doesn't support all these Swift versions, but I found this website which does: SwiftFiddle.
> 2 votes

# Answer
# Python 3.8 (pre-release), ~~34~~ 33 bytes

```
f=lambda n:not(n+1)or n**n*f(n-1)

```

Try it online!
> 2 votes

# Answer
## PHP 5.6 (50 chars)

Given *$argv\[1\]* as a command line argument :

```
$r=($n=$argv[1])**$n;for(;$n--;)$r*=$n**$n;echo$r;

```

## PHP 5.6 (42 chars)

To get the answer as a variable, the function *a($input)* return the answer recursively :

```
function a($n){return$n?$n**$n*a($n-1):1;}

```

## PHP 7 (38 chars)

The function **$\_ENV** is like it's PHP5.6 equivalent function.

```
$_ENV=fn($n)=>$n?$n**$n*$_ENV($n-1):1;

```

**Note** : The **$\_ENV** overwriting is a bad practice.
> 2 votes

# Answer
# Desmos, 19 bytes

```
f(k)=∏_{n=1}^kn^n

```

Try It On Desmos!

Try It On Desmos! - Prettified
> 2 votes

# Answer
# Fig, \\$4\log\_{256}(96)\approx\\$ 3.292 bytes

```
r^ua

```

Try it online!

Beats osabie and Vyxal, still longer than Jelly tho.

```
r^ua
   a # Range [1, n]
 ^u  # Exponentiate by self
r    # Product

```
> 2 votes

# Answer
# Charcoal, 8 bytes

```
ＩΠＥ⊕ＮＸιι

```

Try it online! Link is to verbose version of code. Explanation:

```
    Ｎ       Input `n` as a number
   ⊕        Incremented
  Ｅ         Map over implicit range
      ι     Current value
     Ｘ      Raised to power
       ι    Current value
 Π          Product
Ｉ           Cast to string
            Implicitly print

```
> 1 votes

# Answer
# Julia 1.0, ~~17~~ 16 bytes

```
!n=n<0||!~-n*n^n

```

Try it online!

-1 byte thanks to dingledooper \- I always forget about `~-n`
> 1 votes

# Answer
# MathGolf, 8 bytes

```
╒_m#ε*1╙

```

Try it online.

**Explanation:**

```
╒         # Push a list in the range [1, (implicit) input-integer]
 _        # Duplicate it
  m#      # Take the exponent of the two lists at the same positions
    ε*    # Reduce this list by multiplication
      1╙  # Leave the max of this value and 1 (for edge case input=0)
          # (after which the entire stack is output implicitly as result)

```
> 1 votes

# Answer
# CJam, 11 bytes

```
1ri,{)_#*}%

```

Try it online!

### How it works

```
1             e# Push 1
 ri           e# Read input and intepret as an integer, n
   ,          e# Range. Gives [0 1 2 -... n-1]
    {    }%   e# For each k in the range
     )        e# Add 1
      _       e# Duplicate
       #      e# Power
        *     e# Product
              e# Implicit display

```
> 1 votes

# Answer
# Ruby, 24 bytes

```
f=->n{n<1?1:n**n*f[n-1]}

```

Try it online!
> 1 votes

# Answer
# Japt, 6 bytes

```
õ_pZÃ×

```

Try it here
> 1 votes

# Answer
# PowerShell, 51 bytes

```
param($n)iex((1..$n|%{[math]::pow($_,$_)})-join'*')

```

Try it online!

It is rare to see Powershell answers without spaces
> 1 votes

# Answer
# Scala, 43 bytes

```
1.to(_)./:(1)((a,n)=>a*math.pow(n,n).toInt)

```

Try it in Scastie!

For comparison, the recursive solution is 56 bytes:

```
def f(n:Int):Int=if(n>0)math.pow(n,n).toInt*f(n-1)else 1

```
> 1 votes

# Answer
# Clojure, ~~104~~ 86 bytes

```
(defn h[n](->>(rest(range(inc n)))(map #(repeat %1 %1))(map #(apply *' %))(apply *')))

```

Try this version online!

Cut it down to 86 bytes by using the thread-after macro.

Un-golfed:

```
(defn hyperfactorial [n]
  (->> (rest (range (inc n)))
         (map #(repeat %1 %1))
           (map #(apply *' %))
             (apply *')))

```

Previous 104 byte answer:

```
(defn h[n](let[p(fn[c](apply *' c))m(rest(range(inc n)))f(map #(repeat %1 %1)m)q(map p f)](apply *' q)))

```

Try it online!

Ungolfed:

```
(defn hyperfactorial [n]
  (let [ pow      (fn [c] (apply *' c))
         nums     (rest (range (inc n)))  ; '(1 2 3 ... n)
         factors  (map #(repeat %1 %1) nums)
         powers   (map pow factors) ]
     (apply *' powers)))

```
> 1 votes

# Answer
# Pip, 9 bytes

```
Y\,a$*yEy

```

Takes input via command-line argument. Try it here! Or, here's a 10-byte equivalent in Pip Classic: Try it online!

### Explanation

```
 \,a       Inclusive range from 1 to command-line arg
Y          Yank that into y
      yEy  y to the power of y
    $*     Fold on multiplication

```
> 1 votes

# Answer
# PHP -F, ~~42~~ 39 bytes

```
for($r=1;$argn-$n++;)$r*=$n**$n;echo$r;

```

Try it online!

No PHP yet, well this is The Answer! Unfortunately I had to resort to incrementing first, because of a weird operator precedence when using `$n**$n--` (`$n` should decrement after the exponentiation if I RTM correctly, but actually it decrements first)

EDIT: nice improvement from Hydrazer, -3 bytes with a way to avoid using `$n` twice in the loop declaration
> 1 votes

# Answer
# Attache, 14 bytes

```
Prod@{1:_^1:_}

```

Try it online! Composes the `Prod`uct function with a function which computes `k^k` for `k in 1..n`.

Slightly more elegant, 15 bytes: `Prod@{_^_}@1&`:`

Less characters, more bytes (13ch/15b): `Prod«1:_^1:_»`, or the equivalent 15b program `Prod<~1:_^1:_~>`.
> 1 votes

# Answer
# Java (JDK), 51 bytes

```
double a(int i){return i<1?1:Math.pow(i,i)*a(i-1);}

```

Try it online!

returning a double saves bytes as you don't have the cast the Math.pow

Same byte-count as the other java answer but using recursion.
> 1 votes

# Answer
# , 14 bytes

```
[[j,;]{nn^}d]*

```

Try it online!

```
[                 # Open the array
 [j,;]            # Input range 1..n
      {nn^}       # Push a block to power by self
           d]     # Apply n close
             *    # Product

```
> 1 votes

# Answer
# Perl 5 `-p`, 27 bytes

*26 bytes for code; +1 byte for -p switch*

```
$.*=$_**$_ for 1..$_;$_=$.

```

Try it online!

Ungolfed (but somehow not any more readable):

```
for (1..$_) {
    # The built-in variable $. ($INPUT_LINE_NUMBER) defaults to 1
    $. *= $_ ** $_
}
$_ = $.

```
> 1 votes

# Answer
# Raku, 26 bytes

```
{[*] (0..*Z**0..*)[1..$_]}

```

```
      0..*                  # range from 0 to infinity
      0..*Z**0..*           # zip with exponent
     (0..*Z**0..*)[1..$_]   # slice from range 1 to default variable (var passed to function) inclusive
 [*] (0..*Z**0..*)[1..$_]   # reduce on multiplication
{[*] (0..*Z**0..*)[1..$_]}  # block

```

Try it online!
> 1 votes

# Answer
# F# (.NET Core), 46 bytes

(Only works up to `n = 5`, however.)

```
let rec h=function 0->1|n->(pown n n)*(h(n-1))

```

Try it online!
> 1 votes

# Answer
# Red, 40 bytes

```
func[n][a: 1 repeat i n[a: i ** i * a]a]

```

Try it online!
> 1 votes

# Answer
# Vyxal, 7 bytes

```
?ɾƛ:e;Π

```

Try it Online!

Will add an explanation soon.
> 1 votes

# Answer
# Excel, 33 bytes

```
=LET(x,SEQUENCE(A1),PRODUCT(x^x))

```

Link to Spreadsheet
> 1 votes

# Answer
# Python \+ `mpmath`, 28 bytes

```
from mpmath import*
hyperfac
```

Attempt This Online!
> 1 votes

# Answer
# Knight, 30 bytes

```
;=p=w 1;=qP;W<w q=p*p^=w+wTwOp

```

Try it online!
> 1 votes

# Answer
# Knight (v2.0-alpha), 27 bytes

```
;;=i^=n+0PnW=n-nT=i*i^n nOi

```

Try it online!
> 1 votes

# Answer
# Arturo, ~~29~~ 22 bytes

```
$=>[∏map..1&'x->x^x]

```

Try it
> 1 votes

# Answer
# , 11 bytes

```
[:*/1^~@+i.

```

Attempt This Online!

```
[:*/1^~@+i.
[:          NB. enforce f (g x)
  */        NB. product reduce
         i. NB. range 0..x-1
    1   +   NB. add one
       @    NB. then
     ^~     NB. raise each item to itself

```
> 1 votes

# Answer
# K (ngn/k), 15 bytes

```
+/*/'{x#x}'1+!:

```

Try it online!

Another quick answer.

Explanations:

```
+/*/'{x#x}'1+!:  Main function. Takes implicit input with :
             !   Range from [0..input-1]
           1+    + 1 to turn it into [1..input]
          '      For each number...
     {   }       Execute a function that...
        x        Takes the number as implicit variable x
      x#         And duplicate them x amount of times
    '            For each of the lists inside...
  */             Fold and multiply them
+/               Sum

```
> 1 votes

# Answer
# \>\<\>, 42 bytes

```
1$01.11-1<
>:>:?v~:?^~l1=?n*a1.
1-^  >$:}$

```

Try it online

**Explanation**

Initializes product as **1** to handle the **n=0** special case.
Loops over **x** from **n** down to **1** and puts **x** copies of **x** on the stack.
Ex: **n=3** results in `3,3,3,2,2,1`
Then takes the product of all numbers on the stack to get the result.
> 1 votes

# Answer
# Lua, 38 bytes

```
a=1 for i=1,...do a=a*i^i end print(a)

```

Try it online!
> 1 votes

# Answer
# Uiua, 7 bytes

```
/×ⁿ.+1⇡

```

Try it!

```
/×ⁿ.+1⇡
    +1⇡  # 1..n
   .     # duplicate
  ⁿ      # power
/×       # product

```
> 1 votes

# Answer
# Rust, 40 bytes

```
|n|(1u32..=n).map(|n|n.pow(n)).product()

```

Attempt This Online!

Staightforward functional approach. Follows the rules for type inference. As the program takes and returns a u32, only calls up to H(5) are supported. This is because {integer}::pow takes a u32, and casting would cost five bytes.
> 1 votes

# Answer
# Arn, 5 bytes

Uses the slightly older online version

```
O«▒¹Ù

```

Try it!

# Explained

Unpacked: `*{^}\~`

```
         _    Implied variable, initialized to input
        ~    Range 1..
   *…\  fold with multiplication after mapping
  {   block with key of _, initialized to current number
 ^  raise _ to the power of _
} end block

```
> 0 votes

# Answer
# Assembly (NASM, 32-bit, Linux), 85 bytes

```
H:mov ebx,eax
or ax,0
mov ax,1
je z
n:mov ecx,ebx
x:mul ebx
loop x
dec bx
jnz n
z:ret

```

Try it online!

The argument to the `H` function is passed in the `eax` register. The result is also in the `eax` register. The input has to be lower than 65,536.
> 0 votes

# Answer
# Cognate, 36 bytes

```
(Let N;For Range 1 + 1 N(* ^ Twin)1)

```

Attempt This Online!
> 0 votes

# Answer
# Pyt, 3 bytes

```
řṖΠ

```

Try it online!

```
ř            implicit input (n); push [1,2,3,...,n]
 Ṗ           raise each element to the power of itself
  Π          take the product of all of them; implicit print

```
> 0 votes

# Answer
# SageMath, 35 bytes

**Without using NATIVE python module or syntax**

Golfed vesrion. Run it on SageMathCell!

```
f=lambda n:prod(i^i for i in[1..n])

```
> 0 votes

---
Tags: code-golf, math, combinatorics
---


title: Consolidate an Array

text:
# Question
Title: Consolidate an Array
The task is simple: consolidate an array of ints. Consolidating this array consists of the following:

* All instances of 0 need to be moved to the end of the array.
* There should be no 0s between the non-zero integers.
* All non-zero indices should retain their order.

# Challenge

Consolidate an array in the least amount of bytes.

You are consolidating an array of random length with a size up to your language's max with random integers. Input may be any natural way for your language.

# Examples

Input

```
0 5 8 8 3 5 1 6 8 4 0 3 7 5 6 4 4 7 5 6 7 4 4 9 1 0 5 7 9 3 0 2 2 4 3 0 4 8 7 3 1 4 7 5 1 2 1 8 7 8 7 7 2 6 3 1 2 8 5 1 4 2 0 5 0 6 0 3
```

Output

```
5 8 8 3 5 1 6 8 4 3 7 5 6 4 4 7 5 6 7 4 4 9 1 5 7 9 3 2 2 4 3 4 8 7 3 1 4 7 5 1 2 1 8 7 8 7 7 2 6 3 1 2 8 5 1 4 2 5 6 3 0 0 0 0 0 0 0 0
```

Input

```
-1 -7 -6 5 1 -5 -2 7 -3 -8 0 8 9 1 -8 -1 6 -4 1 -2 1 -7 5 4 -6 7 -3 9 8 3 -1 0 -5 -7 3 8 1 1 3 -3 -2 -2 0 -7 0 -4 8 6 -3 6 0 5 3 2 2 2 -2 -7 -3 9 -1 6 0 6 -7 9 4 -2 8 -8 -4 1 -8 4 3 7 3 5 1 0 3 3 7 -1 -5 1 -3 4 -7 0 3 2 -2 7 -3 0 0 2 -5 8 -3 -2 -7 -5 7 -3 -9 -7 5 8 -3 9 6 7 -2 4 7
```

Output

```
-1 -7 -6 5 1 -5 -2 7 -3 -8 8 9 1 -8 -1 6 -4 1 -2 1 -7 5 4 -6 7 -3 9 8 3 -1 -5 -7 3 8 1 1 3 -3 -2 -2 -7 -4 8 6 -3 6 5 3 2 2 2 -2 -7 -3 9 -1 6 6 -7 9 4 -2 8 -8 -4 1 -8 4 3 7 3 5 1 3 3 7 -1 -5 1 -3 4 -7 3 2 -2 7 -3 2 -5 8 -3 -2 -7 -5 7 -3 -9 -7 5 8 -3 9 6 7 -2 4 7 0 0 0 0 0 0 0 0 0 0
```

# Example Code (Java)

```
public class Consolidate {
    public static void main(String[] args) throws Exception {
        int[] toConsolidate = new int[args.length];
        for (int i=0; i<args.length; i++){
            toConsolidate[i]=Integer.parseInt(args[i]);
        }
        for (int i=0; i<toConsolidate.length; i++) {
            for (int k=0; k<toConsolidate.length-1; k++) {
                if (toConsolidate[k] == 0){
                    toConsolidate[k] = toConsolidate[k+1];
                    toConsolidate[k+1] = 0;
                }
            }
        }
        for (int i:toConsolidate)
            System.out.print(i+" ");
    }
}
```

# Answer
## Pyth, 3 bytes

```
!DQ

```

Explanation:

```
  Q    Input
!D     Sort by logical NOT

```

Try it here.
> 31 votes

# Answer
# Jelly, 3 bytes

```
¬Ụị

```

Sorts the list by the logical NOT of its values. Try it online!

### How it works

```
¬Ụị    Main link. Input: A (list)

¬      Compute the logical NOT of each element of A.
 Ụ     Grade up; sort the resulting list's indices by their corresponding values.
  ị    Retrieve the elements of A at that indices.

```
> 13 votes

# Answer
# Octave, 18 bytes

```
@(A)[A(~~A) A(~A)]

```

`sort()` takes too many bytes. I'll just use logical indexing.

Examples on ideone.
> 11 votes

# Answer
# R, ~~29~~ ~~23~~ 21 bytes

As noted by MarcoBreitig, we can shorten it to 21 bytes if we don't need to provide it as a function:

```
x=scan();x[order(!x)]

```

---

Previous versions:

```
function(x)x[order(!x)]

```

The function takes a vector as input and orders by the logical vector that results from negating the input.

Original answer:

```
function(x)c(x[x!=0],x[x==0])

```

The function takes a vector as input and the concatenates (`c()`) the non-zero values and then the zero-values.
> 10 votes

# Answer
# Retina, 15

Simple repeated regex substitution:

```
+`\b0 (.*)
$1 0

```

Try it online.
> 8 votes

# Answer
## Python, 32 bytes

```
lambda x:sorted(x,key=0..__eq__)

```

Takes argument as any iterable (list, tuple, etc.). Thanks to @xnor for teaching me a new trick!
> 8 votes

# Answer
## ES6, 23 bytes

```
a=>a.sort((x,y)=>!x-!y)

```

It used to be the case that `sort` wasn't stable, in which case you needed 41 bytes:

```
a=>a.filter(x=>x).concat(a.filter(x=>!x))

```
> 7 votes

# Answer
# Python byte code (2.7.9), 252 bytes, 33 opcodes, 0.0228 seconds

This was build when the contest was still a contest

Opens a file in the current directory called `'SourceArray'` for use

```
LOAD_CONST          ''
STORE_FAST          no_zeroes#  no_zeroes = ''

LOAD_NAME           open
LOAD_CONST          'SourceArray'
CALL_FUNCTION       0,1#  open('SourceArray')
LOAD_ATTR           read
CALL_FUNCTION       0,0#  .read()

LOAD_ATTR           split
CALL_FUNCTION       0,0#  .split()

DUP_TOP
DUP_TOP             #Start if
BUILD_LIST          0
COMPARE_OP          ==
POP_JUMP_IF_TRUE    35#  if list == [], GOTO 35
LOAD_ATTR           pop
LOAD_CONST          0
CALL_FUNCTION       0,1#  list.pop(0)
DUP_TOP
LOAD_CONST          '0'
COMPARE_OP          ==
POP_JUMP_IF_TRUE    28#  if list.pop(0) == '0', GOTO 28
PRINT_ITEM          #  print list.pop(0)
JUMP_ABSOLUTE       13

POP_TOP
LOAD_CONST          '0%_'#  '0 '
LOAD_FAST           no_zeroes
INPLACE_ADD
STORE_FAST          no_zeroes#  no_zeroes = no_zeroes + '0 '
JUMP_ABSOLUTE       13

LOAD_FAST           no_zeroes
PRINT_ITEM          #  print no_zeroes

LOAD_CONST          None
RETURN_VALUE

```

The `co_code` (The actual codey bit)

```
'd\x01\x00}\x00\x00\te\x00\x00\x83\x00\x00\tj\x01\x00\x83\x00\x00\t\x04\x04g\x00\x00k\x02\x00sG\x00j\x02\x00d\x02\x00\x83\x01\x00\x04d\x03\x00k\x02\x00s8\x00Gq\x15\x00\t\x01d\x04\x00|\x00\x007}\x00\x00q\x15\x00\t|\x00\x00G\td\x00\x00S'

```

Or a .pyc file version `03F3`

```
03 F3 0D 0A 40 FD B0 56 63 00 00 00 00 01 00 00 00 03 00 00 00 00 00 00 00 73 59 00 00 00 64 01 00 7D 00 00 09 65 00 00 64 02 00 83 01 00 6A 01 00 83 00 00 09 6A 02 00 83 00 00 09 04 04 67 00 00 6B 02 00 73 50 00 6A 03 00 64 03 00 83 01 00 04 64 04 00 6B 02 00 73 41 00 47 71 1E 00 09 01 64 05 00 7C 00 00 37 7D 00 00 71 1E 00 09 7C 00 00 47 09 64 00 00 53 28 06 00 00 00 4E 74 00 00 00 00 74 0B 00 00 00 53 6F 75 72 63 65 41 72 72 61 79 69 00 00 00 00 74 01 00 00 00 30 73 02 00 00 00 30 20 28 04 00 00 00 74 04 00 00 00 6F 70 65 6E 74 04 00 00 00 72 65 61 64 74 05 00 00 00 73 70 6C 69 74 74 03 00 00 00 70 6F 70 28 01 00 00 00 74 09 00 00 00 6E 6F 5F 7A 65 72 6F 65 73 28 00 00 00 00 28 00 00 00 00 74 09 00 00 00 70 79 6B 65 5F 63 6F 64 65 52 08 00 00 00 01 00 00 00 52 00 00 00 00

```

You can try to compile my source code yourself using my library on github. I just posted a commit to it that allowed comments so I hope this is still competing as far as goes ;)

Roughly equivalent to

```
no_zeroes = ''
unamed_variable = open('SourceArray').read().split()
while unamed_variable != []:
    unamed_variable_2 = unamed_variable.pop()
    if unamed_variable_2 == '0':
        no_zeroes += '0 '
    else:
        print unamed_variable_2,
print no_zeroes,

```
> 6 votes

# Answer
# Matlab: 21 bytes

```
@(a)[a(a~=0),a(a==0)]

```

Prints nonzero elements first, then concatenates with zero elements

`@(a)____` create an anonymous function with one input argument `a`

`[___,___]` concatenates horizontally vectors inside brackets, separated by commas

`a(a~=0)` returns vector with all nonzero elements of vector `a`

`a(a==0)` returns vector with all zero elements of vector `a`
> 6 votes

# Answer
# APL: 8 bytes

```
(⍴a)↑a~0

```

a~0 remove zeros from a (read "a without 0")
(⍴a) original length of a (read "shape of a")
↑ pad a without zeros to a's original length

Try it in http://ngn.github.com/apl/web/index.html

Test data: a←1 0 1 2 3 4 0 1 0 0 0 0 1 2 3 4 5
> 6 votes

# Answer
# Zsh, 22 bytes

(input passed as arguments to the script/function (`$@` aka `$argv` array), output on stdout as space separated list, newline terminated)

```
<<<${@:#0}\ ${(M)@:#0}

```
* `<<< string`: here-string here passed as stdin to the `$NULLCMD` command (`cat` by default).
* `${@:#0}` `$@` except elements being 0.
* `${(M)@:#0}` reverse of the above

That assumes (like several other answers here) that zeroes in the input are all expressed as `0` (no `00` nor `0x0` nor `36#0`).
> 6 votes

# Answer
## Haskell, 26 bytes

```
f x=filter(/=0)x++[0|0<-x]

```

Take all non-zero numbers followed by all zeros. Filtering constants (here: `0`) is quite short when using a list comprehension: `[0|0<-x]`.
> 5 votes

# Answer
# Mathematica, 14 bytes

```
Sort[#,#!=0&]&

```
> 5 votes

# Answer
# Javascript, ~~52~~ ~~54~~ 51 bytes

```
s=>s.replace(/\b0 /g,x=>++i&&'',i=0)+' 0'.repeat(i)

```
> 4 votes

# Answer
# Common Lisp, 46 bytes

```
(lambda(a)(stable-sort a(lambda(_ b)(= 0 b))))

```

Sort the array so that for each couple *(a,b)*, we have *a \< b* if *b* is zero. When neither *a \< b* or *b \< a*, the sort is stable: the original order between elements is retained.

I also tried with *adjust-array* and *remove*, but this was too long:

```
(lambda(a)(adjust-array(remove 0 a)(length a):initial-element 0))

```
> 4 votes

# Answer
## Java 7, 78 bytes

```
void g(int[]a){int c=0;for(int o:a)a[o==0?c:c++]=o;for(;c<a.length;a[c++]=0);}

```

I'm not sure why the other Java entries are using strings. If you want to filter an integer array, it seems best to use an integer array. This modifies the input in place by keeping two indices, then just filling the remaining slots with zeros.
> 4 votes

# Answer
# Vyxal, ~~3~~ 2 bytes

```
µ¬

```

Try it Online!

Sort by logical negation. The header puts the input into a list format.
> 4 votes

# Answer
# Perl 5, 26 bytes

23 plus three for `-an` (`-E` is free)

```
say for sort{!$a-!$b}@F

```

Thanks to Dennis for reminding me of `-a`, saving two bytes.
> 3 votes

# Answer
# PHP, ~~73~~ ~~71~~ ~~70~~ ~~52~~ ~~49~~ ~~48~~ 46 bytes - BIG thanks to Ismael Miguel

```
// Assuming
$a = array(4,8,6,1,0,8,0,0,0,0,0,-4,'-5',-1,564,0);

// Produces a notice-level error
foreach($a as$v)$v?print"$v ":$b.="0 ";echo$b;

```
> 3 votes

# Answer
# Bash + GNU utilities, 23

```
grep -v ^0 a
grep ^0 a

```

Assumes input is newline-separated entries in a file called `a`. Score includes +1 for this filename.
> 3 votes

# Answer
# JavaScript ES6, 16 bytes

```
x=>x.sort(t=>!t)

```

Works on firefox
> 3 votes

# Answer
# AWK, 34 bytes

```
{for(;a++-NF;c?$++b=c:0)$a-=c=$a}1

```

Try it online!

This code runs through all the commandline arguments, shifts non-zero values to the left and clears arguments as it processes them.

The top of loop "should we iteration" condition expression is:

```
a++-NF

```

which increments `a` until it hits the number of commandline arguments `NF`.

The body of the loop,

```
$a-=c=$a

```

saves the value of the current commandline argument in variable `c`, then sets the current argument to 0.

At the end of each iteration, the ternery:

```
c?$++b=c:0

```

checks to see if the current argument `c` is non-zero and if so, increments the `b` (the number of non-zero argument found so far) and stores the current argument value in that slot.

After the code block processes the commandline arguments, the only left to do is trigger AWK to print all the commandline arguments with a `truthy` test without a code block.

```
1

```
> 3 votes

# Answer
# Uiua, 5 bytes

```
⊏⍏=0.

```

Try it!

```
⊏⍏=0.
    .  # duplicate
  =0   # where is it equal to zero?
 ⍏     # rise (grade up)
⊏      # select

```
> 3 votes

# Answer
# MATL, 7 bytes

```
t~FT#S)

```

**Try it online!**

```
t      % input array. Duplicate
~      % logical negate: nonzero values become false, zeros become true
FT#S   % sort (false, then true) and output a vector with the indices of the sorting
)      % apply that vector of indices to original array

```
> 2 votes

# Answer
# CJam, 6 bytes

```
{{!}$}

```

An anonymous function. Sort using “whether or not an element is zero” as a key.
> 2 votes

# Answer
# Clojure/ClojureScript, 18 bytes

```
#(sort-by zero? %)

```
> 2 votes

# Answer
## Seriously, 12 bytes

```
4,n`Y`M@░)░+

```

Try it online!

Explanation:

```
4,n`Y`M@░)░+
4,n           push 4 copies of input
   `Y`M       map logical negate
       @░)    filter (take zeroes) and push to bottom of stack
          ░   filter (take non-zeroes)
           +  append zeroes

```
> 2 votes

# Answer
# Swift, 13 bytes

```
a.sort{$1==0}

```
> 2 votes

# Answer
## TeX (Plain format), 160 bytes

Make the `0` character active (that is, make the interpreter process it as a command), then define that command to skip the character and increment a counter. At the end of the string, print as many zeros as were counted.

Save this as `zero.tex` and give the input through the command line with this command:

```
pdftex "\def\I{0 1 0 3 2 0 0 8 0 5 0 1 9 4}\input zero"

```

```
\def\I{}\newcount\Z\def\L{\loop\advance\Z by-1\ifnum\Z>00 \repeat}
\begingroup\catcode`\013 \def0{\advance\Z by1}
\scantokens\expandafter{\I\empty}\endgroup\L\bye

```

(Newlines added for clarity)
> 2 votes

# Answer
# Perl6, 11 bytes

```
{.sort(!*)}

```

Produces a Block - which can be called on an array:

```
{.sort(!*)}.([1,2,0,3]).say

```

Although it would be more natural (and shorter) to write:

```
[1,2,0,3].sort(!*).say

```

How it works: if the perl6 sort routine is called with a block which accepts only one argument, the list elements are sorted according to `by($a) cmp by($b)`. In this case, the block is `!*`, i.e. a negation of the whatever operator.

I notice that:

* The example in the question is a class which provides a method, not including boilerplate required to read in
* The description of the task does not require printing, and, except for the fact that the example prints, implies that an array might be returned
> 2 votes

# Answer
# J, 4 bytes

```
/:0=

```

Explanation:

```
/:      NB. upward sort on
  0=    NB. equality to zero

```

The sort function in J is guaranteed to be stable by the specification.

Alternative solution, 6 bytes:

```
#{.*#+

```

```
   *#+  NB. replicate each item by its sign (removing zeroes)
#{.     NB. take as many items from this as the original list had
        NB.  (taking more items than there are in a list results in extra zeroes)

```
> 2 votes

# Answer
## Straw, ~~30~~ 29 bytes

```
<:([^0 ])()/,0()/ +,+( +) /}>

```

Use the CP437 encoding

### Explanation

```
<:([^0 ])()/,0()/ +,+( +) /}>
<                             Take input
 :                            Duplicate
  ([^0 ])()/                  Remove every character that is not a 0 or a space
            ,                 Swap the two items on the top of the stack
             0()/             Remove every 0 on the top of the stack
                  +           Push a space and concatenate
                   ,          Swap
                    +         Concatenate
                     ( +) /   Remove duplicate spaces
                           }  Get the 'tail' of the string
                            > Output

```

Try it online! (The added code is to test all test cases)
> 2 votes

# Answer
# K (ngn/k), 7 bytes

```
{x@<~x}

```

Try it online!

`{` `}` anonymous function with argument `x`

`~` "not" - turn 0s into 1s, and everything else into 0s

`<` return the permutation for a stable ascending sort

`@` indexing
> 2 votes

# Answer
# Ruby, 25 bytes

```
->a{a-[0]+[0]*a.count(0)}

```

Try it online!
> 2 votes

# Answer
# Brachylog, 6 bytes

```
{0∨>}ᵒ

```

Try it online!

Other languages' "sort by logical negation" approach doesn't work here, because 1. Brachylog doesn't even have a concept of a Boolean and 2.  applies the default sort to elements that produce the same output to the given predicate, rather than preserving their order. Although, if the output is unbound but constrained... this happens.

```
{   }ᵒ    Sort the input by:
 0        this element is 0
  ∨       and the output is whatever, or whatever
   >      is greater than the output.

```

The very first solution I attempted was simply `>ᵒ`, which didn't rearrange anything at all, and when it came time to include that as an aside in my explanation of my original solution, I found I couldn't quite explain the circumstances, which led me to this.

The original, which is not without its own share of magic to begin with:

# Brachylog, 10 bytes

```
~b{ȧ>≜}ᵍcb

```

Try it online!

I arrived at this solution by trying the longer `~b{ȧ>≜}ᵍ↔ck`, only to discover that ... I actually don't know how this works. Not a clue. Somehow, the unbound variable created by `~b` always ends up non-zero, causing the group of non-zero items to appear before the group of zeroes, as intended (since groups are sorted by first appearance of their earliest elements).

`~b{ȧṡ}ᵍ↔ck` has the same length, and works on the same principle, but involves only more understandable behaviors of CLP(FD)-- checks the case where its input and output are zero first, so the unbound variable created by `~b` simply ends up being zero:

```
~b            Un-behead the input, i.e. append something.
  {  }ᵍ       Group the elements by
    ṡ         sign of
   ȧ          absolute value.
       ↔      Reverse the groups, so that the one containing the first element is last,
        c     concatenate them,
         k    and remove the last element (the "something" from ~b).

```
> 2 votes

# Answer
# x86 machine code, 17 bytes

Hexdump:

```
57 8b fa 33 c0 86 02 42 84 c0 74 01 aa e2 f4 5f
c3

```

A `fastcall` function: receives pointer to array in `edx` and its length in `ecx`.

Disassembled code:

```
    doit:
00D815D0 57                   push        edi
00D815D1 8B FA                mov         edi,edx
    myloop:
00D815D3 33 C0                xor         eax,eax
00D815D5 86 02                xchg        al,byte ptr [edx]
00D815D7 42                   inc         edx
00D815D8 84 C0                test        al,al
00D815DA 74 01                je          myskip (0D815DDh)
00D815DC AA                   stos        byte ptr es:[edi]
    myskip:
00D815DD E2 F4                loop        doit+3h (0D815D3h)
00D815DF 5F                   pop         edi
00D815E0 C3                   ret

```
> 2 votes

# Answer
# ArnoldC, 3752 bytes

Input is a 16 bit positive integer, where the first digit is disregarded. Wrote my own 'power' function, but I used the stock standard example for modulo function as per the ArnoldC website. e.g. If you want to consolidate the array \[3,1,0,2\] you would do so as per the example below:

```
IT'S SHOWTIME
HEY CHRISTMAS TREE out
YOU SET US UP 0
GET YOUR ASS TO MARS out
DO IT NOW consolidate 13102
TALK TO THE HAND out
YOU HAVE BEEN TERMINATED

LISTEN TO ME VERY CAREFULLY consolidate
I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE n
GIVE THESE PEOPLE AIR
HEY CHRISTMAS TREE ZeroCount
YOU SET US UP 0
HEY CHRISTMAS TREE NewNumber
YOU SET US UP 0
HEY CHRISTMAS TREE Modulus
YOU SET US UP 10
HEY CHRISTMAS TREE Power
YOU SET US UP 0
HEY CHRISTMAS TREE Decimal
YOU SET US UP 0
HEY CHRISTMAS TREE Digits
YOU SET US UP 0
GET YOUR ASS TO MARS Digits
DO IT NOW modulo n Modulus
HEY CHRISTMAS TREE Loop
YOU SET US UP 1
HEY CHRISTMAS TREE Cond1
YOU SET US UP 1
HEY CHRISTMAS TREE Cond2
YOU SET US UP 1
HEY CHRISTMAS TREE Val1
YOU SET US UP 0
HEY CHRISTMAS TREE Val2
YOU SET US UP 0
HEY CHRISTMAS TREE Val3
YOU SET US UP 0
HEY CHRISTMAS TREE FinalZeros
YOU SET US UP 1
GET TO THE CHOPPER Loop
HERE IS MY INVITATION n
LET OFF SOME STEAM BENNET Digits
ENOUGH TALK
GET TO THE CHOPPER Cond1
HERE IS MY INVITATION Modulus
HE HAD TO SPLIT 100
LET OFF SOME STEAM BENNET Digits
HE HAD TO SPLIT 10
CONSIDER THAT A DIVORCE Digits
YOU ARE NOT YOU YOU ARE ME 0
ENOUGH TALK
STICK AROUND Loop
BECAUSE I'M GOING TO SAY PLEASE Cond1
GET TO THE CHOPPER ZeroCount
HERE IS MY INVITATION ZeroCount
GET UP 1
ENOUGH TALK
BULLSHIT
GET YOUR ASS TO MARS Val1
DO IT NOW pow 10 Power
GET TO THE CHOPPER Val1
HERE IS MY INVITATION Digits
HE HAD TO SPLIT Val1
ENOUGH TALK
GET YOUR ASS TO MARS Val2
DO IT NOW pow 10 Decimal
GET TO THE CHOPPER Val1
HERE IS MY INVITATION Val1
YOU'RE FIRED Val2
ENOUGH TALK
GET TO THE CHOPPER NewNumber
HERE IS MY INVITATION NewNumber
GET UP Val1
ENOUGH TALK
GET TO THE CHOPPER Decimal
HERE IS MY INVITATION Decimal
GET UP 1
ENOUGH TALK
YOU HAVE NO RESPECT FOR LOGIC
GET TO THE CHOPPER Modulus
HERE IS MY INVITATION Modulus
YOU'RE FIRED 10
ENOUGH TALK
GET TO THE CHOPPER Power
HERE IS MY INVITATION Power
GET UP 1
ENOUGH TALK
GET YOUR ASS TO MARS Digits
DO IT NOW modulo n Modulus
GET TO THE CHOPPER Val3
HERE IS MY INVITATION Digits
HE HAD TO SPLIT 10
ENOUGH TALK
GET TO THE CHOPPER Cond1
HERE IS MY INVITATION Modulus
HE HAD TO SPLIT 100
LET OFF SOME STEAM BENNET Val3
ENOUGH TALK
GET TO THE CHOPPER Cond2
HERE IS MY INVITATION Digits
YOU ARE NOT YOU YOU ARE ME 0
ENOUGH TALK
GET TO THE CHOPPER Cond1
HERE IS MY INVITATION Cond1
CONSIDER THAT A DIVORCE Cond2
ENOUGH TALK
GET TO THE CHOPPER Loop
HERE IS MY INVITATION n
LET OFF SOME STEAM BENNET Digits
ENOUGH TALK
CHILL
GET YOUR ASS TO MARS FinalZeros
DO IT NOW pow 10 ZeroCount
GET TO THE CHOPPER NewNumber
HERE IS MY INVITATION NewNumber
YOU'RE FIRED FinalZeros
ENOUGH TALK
I'LL BE BACK NewNumber
HASTA LA VISTA, BABY

LISTEN TO ME VERY CAREFULLY pow
I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE base
I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE exponent
GIVE THESE PEOPLE AIR
HEY CHRISTMAS TREE result
YOU SET US UP 1
STICK AROUND exponent
GET TO THE CHOPPER result
HERE IS MY INVITATION base
YOU'RE FIRED result
ENOUGH TALK
GET TO THE CHOPPER exponent
HERE IS MY INVITATION exponent
GET DOWN 1
ENOUGH TALK
CHILL
I'LL BE BACK result
HASTA LA VISTA, BABY

LISTEN TO ME VERY CAREFULLY modulo
I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE dividend
I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE divisor
GIVE THESE PEOPLE AIR
HEY CHRISTMAS TREE quotient
YOU SET US UP 0
HEY CHRISTMAS TREE remainder
YOU SET US UP 0
HEY CHRISTMAS TREE product
YOU SET US UP 0
GET TO THE CHOPPER quotient
HERE IS MY INVITATION dividend
HE HAD TO SPLIT divisor
ENOUGH TALK
GET TO THE CHOPPER product
HERE IS MY INVITATION divisor
YOU'RE FIRED quotient
ENOUGH TALK
GET TO THE CHOPPER remainder
HERE IS MY INVITATION dividend
GET DOWN product
ENOUGH TALK
I'LL BE BACK remainder
HASTA LA VISTA, BABY

```

Try it online!
> 2 votes

# Answer
# Julia, 22 bytes

```
l->[l[l.!=0];l[l.==0]]

```

Try it online!
> 2 votes

# Answer
# Thunno 2, 2 bytes

```
Þ~

```

Attempt This Online!

Sort the input (`Þ`) by logical NOT (`~`).
> 2 votes

# Answer
# 05AB1E, ~~15~~ 14 bytes

Code:

```
ED0¢r0KR`rFZ}|

```

Explanation:

```
E               # Evaluate input
 D              # Duplicate top of the stack
  0¢            # Count zeroes
    r           # Reverse stack
     0K         # Delete all zeroes
       R        # Reverse top of the stack
        `       # Flatten
         r      # Reverse stack
          FZ}   # For N in range(amount zeroes): push zero
             |  # Print full stack

```

Uses CP-1252 encoding. Takes an array like this:

```
[0, 5, 8, 8, 3, 5, 1, 6, 8, 4, 0, 3, 7, 5, 6, 4, 4, 7, 5, 6, 7, 4, 4, 9, 1, 0, 5, 7, 9, 3, 0, 2, 2, 4, 3, 0, 4, 8, 7, 3, 1, 4, 7, 5, 1, 2, 1, 8, 7, 8, 7, 7, 2, 6, 3, 1, 2, 8, 5, 1, 4, 2, 0, 5, 0, 6, 0, 3]

```
> 1 votes

# Answer
# Java, ~~131~~ ~~138~~ 136 bytes

Thanks to @t0r0X for pointing out a flaw in my code! (and @Mego for pointing out how to fix it!)

```
void x(String y){int z=y.length(),i=0;System.out.print(y=y.replaceAll("( 0)|(0 )",""));for(;i<z-y.length();i+=2)System.out.print(" 0");}
```

Expects input as a string in the format `"1 2 3 4 5 0 6 0 7 8 9"`.
> 1 votes

# Answer
# Groovy, 28 chars

Given input array `i`, e.g. `def i = [ 0, 5, -1, 3... ]`, the following delivers the solution:

```
i.findAll{it}+i.findAll{!it}

```
> 1 votes

# Answer
# Japt, 8 bytes

```
Un@!X-!Y

```

Test it online!

Joining the "sort by logical NOT" party, as that's literally all it is.
> 1 votes

# Answer
# Java 8, 84 ~~99~~ chars

Now even shorter than ever... based on **previous answer and suggestions by @VoteToClose** ;-)

```
y->{int z=y.length();for(y=y.replaceAll(" 0|0 ","");y.length()<z;)y+=" 0";return y;}

```

Java \<= 7 version, 99 chars:

```
String x(String y){int z=y.length();for(y=y.replaceAll(" 0|0 ","");y.length()<z;)y+=" 0";return y;}

```
> 1 votes

# Answer
# Mathematica 33 bytes

```
DeleteCases[#,0]~Join~Cases[#,0]&

```
> 1 votes

# Answer
## PowerShell, 31 bytes

```
param($a)($a|?{$_})+($a|?{!$_})

```

Takes input `$a`, then does a `Where-Object` (the `?`) for all elements that are true (i.e., not zero), and joins that with another `Where-Object` for all elements that are false (i.e., zero).
> 1 votes

# Answer
# 8th, 75 bytes

First create an array with elements not equal to zero. Then append all found zeros to resulting array.

SED (Stack Effect Diagram) is `a -- a`

**Code**

```
0 swap ( not if n:1+ false else true then ) a:filter ( 0 a:push ) rot times

```

**Example**

```
ok> [0, -3, 7, 0 ,0 , 14, -1] 0 swap ( not if n:1+ false else true then ) a:filter ( 0 a:push ) rot times .
[-3,7,14,-1,0,0,0]

```
> 1 votes

# Answer
# Tcl, 47 bytes

```
proc D L {proc S x\ y {expr !$x}
lsort -c S $L}

```

Try it online!

~~Tcl, 47 bytes
```
proc S x\ y {expr !$x}
proc D L {lsort -c S $L}

```
Try it online!<br>~~

---

~~Tcl, 53 bytes
```
proc D L {lsort -c [list apply {x\ y {expr !$x}}] $L}

```
Try it online!<br>~~

##

~~Tcl, 55 bytes
```
proc S x\ y {expr abs($x)<!$x}
proc D L {lsort -c S $L}

```
Try it online!<br>~~

---

~~Tcl, 61 bytes
```
proc D L {lsort -c [list apply {x\ y {expr abs($x)<!$x}}] $L}

```
Try it online!<br>~~

##

~~Tcl, 70 bytes
```
proc D L {concat [lsearch -al -inl -not $L 0] [lsearch -al -inl $L 0]}

```
Try it online!<br>~~
> 1 votes

# Answer
# Stax, 4 bytes

```
{!oJ

```

Run and debug it

Sort using `x!=0` as the key.

## 5 bytes

```
╦╤∩öµ

```

Run and debug it

Filter out zeros and pad to input length.
> 1 votes

# Answer
## Pyth, 2 bytes

```
o!

```

**Test suite**

Python 3 translation:
```
print(sorted(eval(input()),key=lambda x:not x))

```
> 1 votes

# Answer
## Python 2.7, ~~31~~ 30 bytes

-1 thanks to dennis

Takes input as array.

```
def f(i):i.sort(key=0..__eq__)

```
> 1 votes

# Answer
# Kotlin, 44 bytes

```
{i:List<Int>->i.sortedBy{if(it==0)1 else 0}}

```

Try it online!

## Explanation

```
{ i: List<Int> ->             // lambda taking a List<Int> i
    i.sortedBy {              // sort List by the result of function
        if(it == 0) 1 else 0  // if item is 0 return 1 else 0
    }                         // this will sort i ascending
}                             // while leaving 0s at the end

```
> 1 votes

# Answer
# 05AB1E, 2 bytes

```
ΣĀ

```

Try it online!
> 1 votes

# Answer
# Factor, 29 bytes

```
[ [ sgn abs ] inv-sort-with ]

```

Try it online!

Inverse sort with key function `0 -> 0, not 0 -> 1`.
> 1 votes

# Answer
# Japt, 3 bytes

```
ñ¶T

```

Try it

```
ñ¶T     :Implicit input of array
ñ       :Sort by
 ¶      :Is equal to
  T     :0

```
> 1 votes

# Answer
# Batch 93 bytes

Input is provided as arguments when running the script in windows cmd.exe

```
:l
@(Set/A1/%1 2>nul&&Set .=%.%%1 ||set t=%t%%1 )
@If not %1.==. Shift&Goto:l
@Echo %.%%t%

```

Explainer:

```
 @Set/A1/%1                   Attempt to Provoke divide by 0 error
 2>nul                        Redirect STDERR to nul
    &&                        If not 0
      Set .=%.% %1            Append to '.' list
    ||                        Else
      'Set t=%t%%1 '          Append to 't'rail list
 @If not %1.==. Shift&Goto:l  If argument remains, Shift Argument, repeat loop
 @Echo %.%%t%                 Output

```

Note:

```
@     Suppress command Echo

```
> 1 votes

# Answer
# Raku, 10 bytes

```
*.sort(!*)

```

Try it online!

An anonymous function that calls `sort` on its argument, where the sort-by function is `!*`, another anonymous function that boolean-inverts its argument.
> 1 votes

# Answer
# Desmos, 19 bytes

```
f(x)=sort(x,0^{xx})

```

Try it on Desmos!
> 1 votes

# Answer
# Erlang 86 bytes

```
f(L)->M=lists:filter(fun(E)->E /= 0 end,L),M++lists:duplicate(length(L)-length(M),0).

```
> 1 votes

# Answer
# Arturo, ~~36 29~~ 26 bytes

```
$=>[arrange&=>[&0compare]]

```

Try it

-7 bytes from Arturo 0.9.83 providing the `arrange` function (higher-order sort).

-3 more by using `compare` over `switch`.
> 1 votes

# Answer
# Go, 111 bytes, using `golang.org/x/exp/slices`

```
import."golang.org/x/exp/slices"
func f(I[]int)[]int{SortStableFunc(I,func(a,b int)bool{return b==0});return I}

```

Attempt This Online!

# Go, 199 bytes, using `sort`

```
import."sort"
type L[]int
func(l L)Len()int{return len(l)}
func(l L)Less(i,j int)bool{return l[j]==0}
func(l L)Swap(i,j int){l[i],l[j]=l[j],l[i]}
func f(I[]int)[]int{l:=L(I);Stable(l);return[]int(l)}

```

Attempt This Online!
> 1 votes

# Answer
## F#, 28 bytes

Based on the answers that use booleans:

```
let s=Seq.sortBy(fun x->x=0)

```

Try it online!

Another longer, but possibly more interesting way, is to use `Seq.mapFold` for **120 bytes**:

```
let m=Seq.mapFold(fun c n->if n=0 then None,c+1 else Some n,c)0>>fun(i,c)->Seq.concat[Seq.choose id i;Seq.replicate c 0]

```

which counts and strips out the zeros from the collection, then appends that number of zeros at the end of the collection.

Try this online too!
> 1 votes

# Answer
# Vitsy, 18 bytes

```
lDv\[}D(X]lv-i*\0r

l                  Get length of stack
 Dv                Duplicate and grab for later
   \[    ]         Do everything in the loop that many times.
     }             Rotate the stack right.
      D(X          If the item is 0, delete it.
          lv-i*    Get the value of original length - current length.
               \0  Push that many zeroes.
                 r Reverse the stack.
```

This leaves the sorted array on the stack.

\** Note that this no longer works for the current version! \**
> 0 votes

# Answer
# GNU Sed, 25

Score includes +1 for use of `-E` option.

(Almost) direct port of my Retina answer:

```
:
s/\b0 ([^0].*)/\1 0/
t

```
> 0 votes

# Answer
# `sed`, 16 bytes

```
$G
/[^0]/b
G
h
d

```

it expects a newline delimited stdin input array
> 0 votes

# Answer
# SmileBASIC, ~~77~~ ~~64~~ 62 bytes

```
DEF C A
DIM B[LEN(A)]ARYOP 2,B,A,A
ARYOP 6,B,B,2,1SORT B,A
END

```

Modifies input array in-place.

## Explanation

```
DEF CONSOLIDATE ARRAY
 DIM B[LEN(ARRAY)] 'create another array of the same length
 ARYOP #AOPMUL,B,ARRAY,ARRAY 'square each element in ARRAY and store the result in B
 ARYOP #AOPCLP,B,B,2,1 'clamp each element in B to be "between" 2 (min) and 1 (max)
 SORT B,ARRAY 'sort A and B, using B
END

```

`ARYOP` is a function that does simple operations to entire arrays at once.

My goal is to convert all `0`s into one value, and every other number into another value. It is important that `0` turns into a HIGHER value than the other numbers, so they will be placed at the end during sorting.

(It would be simpler to convert non-zero numbers to `1`, and leave `0` unchanged, but this doesn't work. There is a `RSORT` function, but it actually just sorts the array and reverses it, so it would not leave the order of other numbers unchanged.)

First, the negative numbers need to be made positive. The simplest way to do this is by squaring them. The result is stored in `B`.

Next, these values are clamped into the range `[2,1]`. Technically this is an invalid range, but it works due to the way clamping is implemented.

```
if (number >= start)
   number = start
else if (number <= end)
   number = end

```

Notice that it checks `>=` rather than `>`, and that if the first check happens, the second is skipped.

For example:
`0` is not greater than or equal to `1`, but it is smaller than `2`, so it is set to `2`.
`1` IS greater than or equal to `1`, so it is set to `1`.
(The second check is skipped, even though `1` is smaller than `2`)
`2` is greater than or equal to `1`, so it is set to `1`.
etc.

### So now, we have converted all `0`s into `2`s, and every other number into a `1`.

We can now use `SORT` to sort the input array by our modified array. This will put all the `0`s at the end, and leave the nonzero numbers in the same order (`SORT` uses a stable sorting algorithm)
> 0 votes

# Answer
# Husk, 2 bytes

```
Ö¬

```

Try it online!

order by negation.
> 0 votes

---
Tags: code-golf, array
---