| Bytes | Lang | Time | Link |
|---|---|---|---|
| 076 | Tcl | 181128T151958Z | sergiol |
| 072 | AWK | 250304T192719Z | xrs |
| 010 | Husk | 250223T201523Z | Glory2Uk |
| 034 | Regenerate a | 220702T230945Z | Deadcode |
| 005 | Vyxal jM | 220702T151238Z | naffetS |
| 044 | Julia | 220702T154258Z | MarcMush |
| 072 | Regenerate a | 220702T051346Z | DLosc |
| 011 | Burlesque | 200208T103954Z | DeathInc |
| 072 | C# Visual C# Interactive Compiler | 181117T133242Z | dana |
| 047 | Perl 5 | 181116T202436Z | Xcali |
| 008 | Java | 190417T170350Z | Benjamin |
| 113 | C++ gcc | 190417T130954Z | X1M4L |
| 012 | Brachylog | 190311T053420Z | Unrelate |
| 081 | C gcc | 181117T233837Z | gastropn |
| 028 | APL Dyalog Extended | 190311T013434Z | voidhawk |
| 008 | Japt R | 181116T193304Z | Shaggy |
| 010 | MathGolf | 181128T154909Z | maxb |
| 131 | Kotlin | 181120T080732Z | Kromzem |
| 185 | TSQL | 181116T205325Z | BradC |
| 051 | PHP | 181126T181400Z | Titus |
| 163 | Oracle SQL | 181126T171733Z | Dr Y Wit |
| 025 | Perl 6 | 181116T195445Z | Sean |
| 064 | JavaScript REPL | 181116T230630Z | Shaggy |
| 083 | JavaScript | 181120T104331Z | Alvin Li |
| 039 | Ruby | 181120T091942Z | G B |
| 026 | K ngn/k / K oK | 181117T093121Z | mkst |
| 019 | K4 | 181120T074213Z | mkst |
| 052 | MATLAB | 181117T010706Z | Luis Men |
| 040 | PowerShell | 181116T193801Z | AdmBorkB |
| 036 | Wolfram Language Mathematica | 181116T195501Z | Kelly Lo |
| 057 | Bash + GNU Core Utilities | 181118T021303Z | markasof |
| 008 | Jelly | 181116T193154Z | ETHprodu |
| 007 | Jelly | 181117T170727Z | Jonathan |
| 055 | Python 2 | 181117T155959Z | xsot |
| 008 | 05AB1E legacy | 181117T144138Z | Mr. Xcod |
| 010 | Pyth | 181117T141350Z | Dennis |
| 015 | Pyth | 181117T134935Z | Erik the |
| 038 | Retina 0.8.2 | 181117T125742Z | Neil |
| 072 | Common Lisp | 181116T195932Z | Renzo |
| 059 | Red | 181117T043206Z | Galen Iv |
| 055 | Haskell | 181116T193808Z | nimi |
| 050 | Haskell | 181116T203747Z | xnor |
| 090 | Clean | 181117T013117Z | Οurous |
| 026 | J | 181116T200540Z | Jonah |
| 007 | Jelly | 181116T221536Z | Dennis |
| 008 | Stax | 181116T212137Z | recursiv |
| 049 | R | 181116T192851Z | Giuseppe |
| 019 | Charcoal | 181116T205943Z | Neil |
| 056 | Python 2 | 181116T200152Z | xnor |
| 041 | V | 181116T202149Z | DJMcMayh |
| 061 | Python 2 | 181116T194446Z | Triggern |
| 061 | Python 2 | 181116T200453Z | Chas Bro |
| 063 | Python 2 | 181116T194525Z | DJMcMayh |
Tcl, 76 bytes
puts 0
time {if {[set L [split [incr i] ""]]==[lsort -u $L]} {puts $i}} 9999
AWK, 72 bytes
END{for(;i++<1e4;printf j?i RS:X)for(j=k=split(i,a,X);k;)j*=a[k--]>a[k]}
END{for(;i++<1e4; # iterate
printf j?i RS:X) # print if j non-zero
for(j=k=split(i,a,X); # split i into array
k;)j*=a[k--]>a[k]} # if not > then j==0
Husk, 10 bytes
¶mdΣMṖŀ5ḣ9
Also: 10 bytes ¶mdṁ`Ṗḣ9ŀ5 and 11 bytes ¶fo<5LmdṖḣ9
MṖ -- make all subsequences,
ŀ5 -- having 0 to 4 elements
ḣ9 -- of all digits 1 to 9
-- (the result is grouped into sublists)
Σ -- unlist
md -- join digits together
¶ -- join by newlines
Regenerate -a, 36 34 bytes
0|(([2-9])$4{$1/$2}|$3![1-9]()){4}
This was directly inspired by the language's creator's answer, but I figured this big optimization building on that idea was worth its own post.
0 # Zero must be matched as a special case, because no other
# numbers have a leading '0' digit.
|
(
([2-9]) # \2 = a digit intended to be greater than the previous
# one ($1), but until being validated below, it can
# be any digit in [2-9].
# We could actually do ([0-9]) here and it'd generate the
# same output, but would run slightly less efficiently.
$4{$1/$2} # Repeat a nonexistent group $1/$2 number of times. $1 and $2
# are the literal contents of those captures interpreted as
# numeric values upon which arithmetic can be done in a
# quantifier, which we do here. $1/$2 will evaluate to
# zero iff $2 is greater than $1, which is the only thing
# that will allow it to match, because if it repeats more
# than zero times, it tries to match the nonexistent group
# $4 which can't match.
|
$3 # If the above fails to match, due to $1 containing the
# digit '9', the regex engine will try other matches, even
# if they use short-circuiting alternation. So we put a
# dummy match here, which can only match on iterations
# other than the first one. Once this matches, it will be
# the only thing that can match in all subsequent
# iterations, because the attempted math "$2-$1-1" will
# fail still - now due to $1 no longer being a number (it
# will be blank).
# Short-circuiting alternation - never try the following unless the all of
# the above failed to match.
!
[1-9] # Match the first digit. This can only happen on the first
# iteration, thanks to the short-circuiting alternation.
() # $3 = empty capture - lets subsequent iterations know that
# they are no longer the first iteration
) # $1 = whatever digit was matched above, for use by the next
# iteration
{4} # Repeat the above loop for exactly 4 iterations. This
# allows a variable number of digits, due to the "$3" dummy
# alternative.
Alternative 34 bytes:
0|(([2-9])$3{$1/$2}|{#1}![1-9]){4}
It might not be intended that this is possible, but Regenerate allows a quantifier to be preceded by nothing. This is what's happening with {#1} - it's impossible for it to match on the first iteration because $1 hasn't been captured yet and doesn't have a length. On subsequent iterations, a match of nothing gets repeated one time (the length of $1).
Regenerate -a, 72 bytes
0|([1-9])(([2-9])(){$3-$1-1}(([3-9])(){$6-$3-1}(([4-9])(){$9-$6-1})?)?)?
Appropriately, outputs the numbers in lexicographic order. Attempt This Online!
Explanation
0|
Match 0, or:
([1-9])
Match a digit 1 through 9 (capture group 1).
(...)?
Either stop there, or continue:
([2-9])
Match a digit 2 through 9 (capture group 3), and:
(){$3-$1-1}
Match an empty group X times, where X equals the second digit minus the first digit minus 1. If the second digit is not larger than the first digit, this quantity is negative, and using a negative number as a repetition count causes the match to fail. Thus, only matches where the second digit is larger than the first digit are included.
(...)?
Either stop there, or continue:
([3-9])
Match a digit 3 through 9 (capture group 6), and:
(){$6-$3-1}
Match an empty group Y times, where Y equals the third digit minus the second digit minus 1 (ensuring that the third digit is larger than the second digit).
(...)?
Either stop there, or continue:
([4-9])
Match a digit 4 through 9 (capture group 9), and:
(){$9-$6-1}
Match an empty group Z times, where Z equals the fourth digit minus the third digit minus 1 (ensuring that the fourth digit is larger than the third digit).
Burlesque, 11 bytes
1e4qsoFO:U_
Equivalently
1e4ro:so:U_
1e4 # 10000
qso # Boxed is sorted?
FO # Filter from 1..10000 if sorted
:U_ # Filter for unique digits
C# (Visual C# Interactive Compiler), 102 101 73 ... 72 bytes
-12 and -4 thanks @Dennis!
for(var i=0;i<7e3;i++)if((i+"").Aggregate((a,b)=>a<b?b:':')<58)Print(i);
Each integer from 0 to 7k tested by first converting it into a string. Leveraging the fact that C# treats strings as character enumerables and LINQ, an aggregate is calculated for each character enumerable as follows:
- compare the accumulated value with the current character
- if the current character is greater than the accumulation, return the current character
- otherwise return
:which is greater than9
If the result of this is less than : (ASCII 58), then the number has lexicographically increasing digits.
Java 8
Full program: 186 bytes
interface M{static void main(String[]a){for(int i=-1;i++<9999;System.out.print((i+"").chars().distinct().sorted().mapToObj(c->(c-48)+"").reduce("",(x,y)->x+y).equals(i+"")?i+"\n":""));}}
Function: 149 bytes
v->{for(int i=-1;i++<9999;System.out.print((i+"").chars().distinct().sorted().mapToObj(c->(c-48)+"").reduce("",(x,y)->x+y).equals(i+"")?i+"\n":""));}
C++ (gcc), 113 bytes
bool y(int a){return(a==0||a%10>(a/=10)%10&&y(a))?true:false;}void z(int i){while(++i<7e3)if(y(i))cout<<i<<endl;}
Pretty Layout:
#include<iostream>
using namespace std;
bool y(int a){
return(a==0||a%10>(a/=10)%10&&y(a))?true:false;
}
void z(int i){
while(++i<7e3){
!y(i)?:cout<<i<<endl;
}
}
int main(){
z(-1);
}
Brachylog, 12 bytes
7jj⟦{ẹ<₁cẉ}ˢ
ẉ Write on its own line
{ }ˢ every
c concatenated
<₁ strictly increasing
ẹ list of digits of
⟦ numbers from the range from 0 to
7jj 7777.
7jj⟦{ṫ⊆Ị&ẉ}ˢ also works.
C (gcc), 97 89 81 bytes
Thanks to ceilingcat for -8 bytes.
Another -8 thanks to Dennis
g(n){n=!n||n/10%10<n%10&&g(n/10);}f(i){for(i=-1;++i<7e3;g(i)&&printf("%u\n",i));}
APL (Dyalog Extended), 28 bytes
{(⍵≡∪⍵)∧⍵≡∧⍵:⎕←⍵⋄⍬}∘⍕¨⍳10000
Explanation:
{(⍵≡∪⍵)∧⍵≡∧⍵:⎕←⍵⋄⍬}∘⍕¨⍳10000 ⍝ Full program
⍳10000 ⍝ Generate integers from 1 to 10000
∘⍕¨ ⍝ For each number, convert to string and apply left function
⍵≡∧⍵ ⍝ If the string equals itself sorted...
(⍵≡∪⍵)∧ ⍝ ...and the string contains only unique elements...
⎕←⍵ ⍝ ...print the string to output with trailing newline
⋄⍬ ⍝ Otherwise, do nothing
Japt -R, 12 11 8 bytes
L²Ç¶ìüÃð
L :100
² :Squared
Ç :Map the range [0,L²)
ì : Split to a digit array
ü : For the sake of simplicity*, let's say: Sort & deduplicate
: Implicitly rejoin to an integer
¶ : Test for equality with original number
à :End map
ð :Get 0-based indices of truthy elements
:Implicitly join with newlines and output
*Or, to offer a better explanation: the ü method sorts an array and splits it into equal elements (e.g., [8,4,8,4].ü() -> [[4,4],[8,8]]) and then, in what seems to be a strange quirk and hopefully not a bug, the ì method, when converting the array back to a number, takes the first element of each nested array, rather than first flattening the array, which is what I expected when I tried this trick (e.g., [[4,4],[8,8]].ì() -> 48).
MathGolf, 10 bytes
♫rgÆ▒_s▀=n
Explanation
♫ push 10000
r range(0, n)
g pop a, (b), pop operator from code, filter
Æ start block of length 5
▒ split to list of chars/digits
_ duplicate TOS
s sort(array)
▀ unique elements of string/list
= pop(a, b), push(a==b)
n newline char, or map array with newlines
Kotlin, 132 131 bytes
Edit: -1 Byte thanks to @Giuseppe
fun main(){(0..9999).forEach{it.toString().let{var b=1;it.forEachIndexed{i,c->if(i>0&&it[i-1]<c)b++};if(b==it.length)println(it)}}}
T-SQL, 188 185 bytes
WITH a AS(SELECT 0n UNION ALL SELECT n+1FROM a WHERE n<9)
SELECT CONCAT(a.n,b.n,c.n,d.n)+0
FROM a,a b,a c,a d
WHERE(a.n<b.n OR a.n+b.n=0)
AND(b.n<c.n OR b.n+c.n=0)
AND(c.n<d.n OR c.n+d.n=0)
Line breaks are for readability only.
I'm certain there must be more efficient ways to do this in SQL, but this was the first thing I thought of. Explanation:
- Declare an in-memory table with values 0 to 9
- Cross-join 4 copies of this table for all possible values from 0000 to 9999
- Messy
WHEREclause to ensure the digits are strictly increasing (or both 0) - Smash the digits together (
CONCAT) and convert to integer (+0) - The resulting rows may or may not be sorted, but the challenge doesn't appear to require that.
PHP, 51 bytes
while($n<1e4)count_chars($n,3)-$n++||print~-$n."
";
Run with -nr or try it online.
count_chars($string,$mode=3) returns a string of all used characters in ascending order.
This equals the input if, and only if, its characters (in this case: digits) are strictly increasing.
$n is NULL in the first iteration; count_chars returns an empty string; NULL-"" is evaluated as 0-0.
Oracle SQL, 163 bytes
Various ways to generate combinations
with a(n)as(select level-1 from dual connect by level<11),r(i,x,s)as(select 1,n,n||''from a union all select i+1,n,s||n from r,a where(x<n or n+x=0)and i<4)select s+0 from r where i=4;
with a(n)as(select level-1 from dual connect by level<11)select a.n||b.n||c.n||d.n+0 from a,a b,a c,a d where(a.n<b.n or a.n+b.n=0)and(b.n<c.n or b.n+c.n=0)and(c.n<d.n or c.n+d.n=0);
with a(n)as(select level from dual connect by level<11)select unique replace(sys_connect_by_path(n-1,'#'),'#')+0 from(a)connect by level<5and prior n<n order by 1;
- Rec with (CTE), 184 bytes
- Self joins, 182 bytes
- Connect by, 163 bytes
Just for fun
with t(c)as(select ku$_vcnt(1,2,3,4,5,6,7,8,9) from dual)
select listagg(value(z)) within group (order by 0) + 0 n
from (select rownum r, value(r) v
from t, table(powermultiset(c)) r),
table(v) z
where cardinality(v) < 5
group by r union select 0 from dual
.
with a(n)as(select decode(level,10,null,level) from dual connect by level<11)
select nvl(a.n || b.n || c.n || d.n + 0, 0) n
from a, a b, a c, a d
where nvl2(b.n, sign(b.n - a.n), 1) = 1
and nvl2(c.n, sign(c.n - b.n), 1) = 1
and nvl2(d.n, sign(d.n - c.n), 1) = 1
order by 1
Perl 6, 25 bytes
[<](.comb)&&.say for ^1e4
-1 byte thanks to nwellnhof
.comb produces a list of the digits of each number, and [<] does a less-than reduction on that list, equivalent to: digit1 < digit2 < ... < digitN.
JavaScript REPL, 64 bytes
A bit of pub golf so probably far from optimal.
(f=n=>n&&f(n-1)+([...n+``].every(x=>y<(y=x),y=0)?`
`+n:``))(7e3)
Yes, doing it without an IIFE would be a few bytes shorter but that throws an overflow error when called, which would normally be fine as we can assume infinite memory for the purposes of code golf but, to me, doesn't seem to be in the spirit of KC challenges.
JavaScript, 83 bytes
Borrowed some ideas from @Shaggy, but without recursion.
[...Array(1e4)].reduce((s,_,n)=>s+=([...n+''].every(x=>y<(y=x),y=0))?'\n'+n:'','0')
K (ngn/k) / K (oK), 32 30 26 bytes
Solution:
`0:$&&/'1_'>':'" ",'$!9999
Explanation:
`0:$&&/'1_'>':'" ",'$!9999 / the solution
!9999 / range 0..9998 (could use !6890)
$ / string
" ",' / prepend " " to each (lower than "0" in ascii)
>:' / greater-than each-previous?
1_' / drop first result from each
&/' / max (&) over (/)
& / indices where true
$ / convert to string
`0: / print to stdout
K4, 19 bytes
Solution:
-1@$&&/'>':'$!9999;
Explanation:
-1@$&&/'>':'$!9999; / the solution
!9999 / range 0..9998
$ / string
>':' / greater-than (>) each-previous (':) each (')
&/' / max (&) over (/)
& / indices where true
$ / string
@ / apply
-1 ; / print to stdout and swallow return value (-1)
MATLAB, 52 bytes
arrayfun(@(n)disp(n(all(diff(num2str(n))>0))),0:1e4)
PowerShell, 42 40 bytes
0..1e4|?{-join("$_"|% t*y|sort -u)-eq$_}
Loop from 0 to 1e4 (i.e., 10000). Pull out those objects where |?{...} the number as a string $_ is -equal to the number cast toCharArray and then sorted with the -unique flag. In other words, only numbers that are the same as their sorted and deduplicated strings. Each of those are left on the pipeline and output is implicit.
Wolfram Language (Mathematica), 36 bytes
After I wrote this, it was clarified that each number must be on a new line, so +7 bytes for the Print/@.
This method takes advantage of the fact that the Subsets function 1) doesn't replicate any digits and 2) sorts the output by set size and set contents. FromDigits assembles each list of digits.
-1 byte thanks to @Mr.Xcoder
Print/@FromDigits/@Range@9~Subsets~4
Bash + GNU Core Utilities, 57 bytes
seq 1e4|grep -vP `seq 0 9|sed 's/./(&[0-&])/'|tr '
' \|`p
Uses some meta-regex-generation shit
Jelly, 13 9 8 bytes
Saved 5 bytes thanks to @Dennis
9œcⱮ4ẎŻY
Explanation
Generates all lexicographically increasing numbers below 10000 by taking the digits [1...9] and finding all combinations of length ≤ 4.
9œcⱮ4ẎŻY Main link. Arguments: none
9 Yield 9.
Ɱ4 For each n in [1...4]:
œc Yield the combinations of the range [1...9] of length n.
Ẏ Tighten; dump each of the 4 lists generated into the main list.
Ż Prepend a 0 to the list.
Y Join on newlines.
Jelly, 11 10 9 bytes
Saved a byte thanks to @EriktheOutgolfer
ȷ4Ḷ<ƝẠ$ƇY
Explanation
Filters through the range, keeping the numbers that are lexicographically increasing.
ȷ4Ḷ<ƝẠ$ƇY Main link. Arguments: none
ȷ4 Yield 10^4 (10000).
Ḷ Generate the range [0...10000).
Ƈ Filter; yield only the numbers where this link return a truthy value.
$ Run these two links and yield the result.
Ɲ For each pair of items (digits) in the number:
< Check whether the left digit is less than the right digit.
Ạ All; check that every comparison yielded true.
This yields whether the digits are strictly increasing.
Y Join the filtered list on newlines.
Jelly, 7 bytes
<ƝẠ$⁹#Y
How?
<ƝẠ$⁹#Y - Main Link: no arguments (implicit z=0)
⁹ - literal 256
# - count up from n=z (0) finding the first 256 for which this is truthy:
$ - last two links as a monad:
Ɲ - neighbours (implicitly gets digits of n):
< - less than?
Ạ - all truthy? (N.B. yields 1 for an empty list)
Y - join with newlines
05AB1E (legacy), 8 bytes
4°ÝD€êû
Works in the new version of 05AB1E as well but is painfully slow for some reason.
How?
4°ÝD€êû – Full program.
4°Ý – Push [0 ... 10000].
D€ê – Push each integer in [0 ... 10000] sorted and deduplicated at the same time.
û – And join the interection of the two lists by newlines.
Pyth, 10 bytes
jiRThc2yS9
How it works
jiRThc2yS9
S9 Yield [1, 2, 3, 4, 5, 6, 7, 8, 9].
y Take all 512 subsets.
c2 Split the array of subsets into 2 pieces (256 subsets each).
h Head; take the first piece.
iRT Convert each subset from base 10 to integer.
j Separate by newlines.
Retina 0.8.2, 38 bytes
9999$*
.
$.`¶
.
$*_$&
A`(_*)\d\1\d
_
Try it online! Explanation:
9999$*
Insert 9999 characters.
.
$.`¶
Convert into a list of numbers 0..9998
.
$*_$&
Prefix each digit with its value in _s.
A`(_*)\d\1\d
Delete lines containing nonincreasing digits.
_
Remove the now unnecessary _s.
Common Lisp, 74 72 bytes
(dotimes(i 7e3)(format(apply'char<(coerce(format()"~d"i)'list))"~d~%"i))
-2 bytes thank to @Shaggy!
Haskell, 56 55 bytes
Edit: -1 byte thanks to @Ourous
mapM print$filter(and.(zipWith(<)<*>tail).show)[0..6^5]
Haskell, 50 bytes
unlines[s|s<-show<$>[0..6^5],s==scanl1(max.succ)s]
Outputs a multiline string. We check that the number s increasing using s==scanl1(max.succ)s, a variant of the usual sortedness check s==scanl1 max s that ensures strict sortedness by incrementing each digit character before taking the maximum of it and the next digit.
Ourous saved a byte by using 6^5 as the upper bound in place of a 4-digit number.
Clean, 90 bytes
import StdEnv
Start=(0,[('
',n)\\n<-[1..6^5]|(\l=removeDup l==sort l)[c\\c<-:toString n]])
J, 26 bytes
,.(#~(-:/:~@~.)@":"0)i.1e4
explanation
,. (#~ (-: /:~@~.)@":"0) i.1e4
i.1e4 NB. list 0 to 9999
"0 NB. for each number in the input list
@":"0 NB. convert it to a string and
(#~ ( ) NB. remove any not passing this test:
-: NB. the string of digits matches
@~. NB. the nub of the digits (dups removed)
/:~ NB. sorted
,. NB. ravel items: take the result of all that
NB. and turn it into a big column
Jelly, 7 bytes
9ŒPḌḣ⁹Y
How it works
9ŒPḌḣ⁹Y Main link. No arguments.
9 Set the return value to 9.
ŒP Powerset; promote 9 to [1, ..., 9] and generate all subsets.
Ḍ Undecimal; map the subsets of digits to the integers they represent.
⁹ Yield 256.
ḣ Dyadic head; take the first 256 elements of the integer list.
Y Separate the result by linefeeds.
R, 62 49 bytes
`[`=write;0[1];for(i in 1:4)combn(1:9,i)[1,i,,""]
Because combn iterates through its input in the order given, it's easy to create all the lexicographically increasing integers, printing them out in order. write prints them each i-digit number in lines of width i, neatly fulfilling the newline requirement as well.
Charcoal, 19 bytes
ΦEXχ⁴Iι¬Φι∧쬋§ι⊖μλ
Try it online! Link is to verbose version of code. Explanation:
χ Predefined variable 10
X To the power
⁴ Literal 4
E Map over implicit range
ι Current value
I Cast to string
Φ Filter over strings where
ι Current string
Φ Filtered over characters
μ Character index (is nonzero)
∧ And
μ Character index
⊖ Decremented
§ Indexed into
ι Current string
¬ Is not
‹ Less than
λ Current character
¬ Results in an empty string
Implicitly print matches on separate lines
Python 2, 56 bytes
for n in range(9999):
if eval('<'.join(`n`))**n:print n
Converts each number like 124 to an expression 1<2<4 and evaluates it to check if the digits are sorted,
A hiccup happens for one-digit numbers giving an expression that just is the number itself. This causes 0 to evaluate to a Falsey value even though it should be printed. This is fixed by a trick suggested by Erik the Outgolfer of doing **n, which gives truthy value 0**0 for n=0 and doesn't affect the truth value otherwise.
V, 41 bytes
7000ïÎaÛ
Îy$úúP
Ç^¨ä*©±$/d
ÎãlD
ç±/d
HO0
Hexdump:
00000000: 3730 3030 efce 61db 0ace 7924 fafa 500a 7000..a...y$..P.
00000010: c75e a8e4 2aa9 b124 2f64 0ace e36c 440a .^..*..$/d...lD.
00000020: e788 b12f 640a 484f 30 .../d.HO0
Python 2, 64 61 bytes
lambda:[x for x in range(9999)if sorted(set(`x`))==list(`x`)]
Gets the unique characters of the integer's string representation, sorts them, and compares the result to the original number.