g | x | w | all
Bytes Lang Time Link
024Juby rset250515T143507ZJordan
9483Rust231123T001204Z138 Aspe
013TIBASIC231119T151428ZYouserna
033Noulith231117T150035Zbigyihsu
112Go 1.21+231030T135824Zbigyihsu
004Uiua231030T123228Zchunes
003Thunno 2230725T125050ZThe Thon
005Pyt230220T023335ZKip the
033PowerShell230220T000935ZJulian
029Arturo230219T224730Zchunes
038Desmos220629T005521ZAiden Ch
095HBL220628T225718ZDLosc
030Haskell210514T223309ZDelfad0r
006Vyxal210514T212754ZAdam
058Nim201222T083034ZAdam
044Zsh201222T075354Zpxeger
027jq210101T055405Zuser9915
049C# Visual C# Interactive Compiler201222T073127ZLiefdeWe
016x86_64 zero indexed201225T041652ZEasyasPi
183FALSE201227T204216ZReedsSho
00305AB1E201222T032927Zlyxal
044JavaScript Node.js201225T041357ZGOTO 0
004MATL201224T162012ZLuis Men
007Gaia201223T170351ZGiuseppe
049Haskell201223T134001ZAZTECCO
023R201222T172817ZDominic
087C gcc with m32201223T124626ZErikF
006Japt201222T223428ZShaggy
024R201222T122846Zpajonk
035Factor201223T023646ZBubbler
025Zsh201222T231804ZGammaFun
009Add++201222T023700Zcaird co
021Julia 1.0201222T170540ZMarcMush
045PowerShell201222T165402ZZaelin G
017Octave201222T161631ZLuis Men
012J201222T082046ZGalen Iv
082Java JDK201222T152049ZOlivier
019Scala201222T141056Zuser
009Charcoal201222T110832ZNeil
050JavaScript ES6201222T114737ZArnauld
051Retina 0.8.2201222T110250ZNeil
041Python 3201222T071426Zpxeger
005Neim201222T064832ZLiefdeWe
020Wolfram Language Mathematica201222T035816Zatt
011Brachylog201222T035249ZUnrelate
033Ruby 2.7201222T025704Zvrintle
003APL Dyalog Extended201222T025004ZBubbler
007Husk201222T031259ZRazetime
003Jelly201222T030555ZUnrelate
033Perl 5201222T030328ZXcali

J-uby -rset, 24 bytes

Takes a Set as input, returns an array of true and false.

:*%[:& &:===,:max|:!~&0]

Explanation

:* % [:& & :===, :max | :!~ & 0]

                 :max | :!~ & 0   # Range 0..(input.max)
:* % [         ,               ]  # Map with...
      :& & :===                   #   Membership in input

Attempt This Online!

Rust, 94 83 bytes

Saved 11 bytes thanks to @att

Golfed version. Attempt This Online!

|a:Vec<_>|->Vec<_>{(1..=*a.iter().max().unwrap()).map(|i|a.contains(&i)).collect()}

Ungolfed version. Attempt This Online!

fn f(a: Vec<usize>) -> Vec<bool> {
    let max_val = *a.iter().max().unwrap();
    (0..max_val).map(|i| a.contains(&(i+1))).collect()
}

TI-BASIC, 13 bytes

seq(max(I=Ans),I,1,max(Ans

Takes input in Ans.

Noulith, 33 bytes

\l->for(x<-1to(max l))yield x in l

Uses 1-indexing.

Try it online!

Go 1.21+, 112 bytes

import."slices"
func f(I[]int)(o[]int){
for i:=1;i<=Max(I);i++{e:=0
if Contains(I,i){e=1}
o=append(o,e)}
return}

Attempt This Online!

Uses the new slices.Max function from the standard library, which doesn't exist pre-1.21.

Uiua, 4 bytes

>0⍘⊚

Try it!

0-indexed

>0⍘⊚
  ⍘⊚  # inverse where (occurrences)
>0    # where is it greater than zero?

Thunno 2, 3 bytes

GRƇ

Try it online!

Explanation

GRƇ  # Implicit input
G    # Maximum
 R   # Range
  Ƈ  # Contains
     # Implicit output

Pyt, 5 bytes

Đ↑ř⇹∈

Try it online!

Đ          implicit input; Đuplicate
 ↑         get maximum
  ř        řangify
   ⇹∈      is each element in [1,2,...,max] in the input?; implicit print

PowerShell, 33 bytes

1..($a=$args|sort)[-1]|%{$_-in$a}

Try it online!

Takes in an array of positive integer, returns an array of booleans.

I stole the test cases from Zaelin's answer, thank you!

Explanation

1..($a=$args|sort)[-1]            # Generate a range from 1 to the maximum number in the input
                      |%{$_-in$a} # If the number is in the input list, returns $true, otherwise $false

Arturo, 29 bytes

$->a->map 0..max a'x->a<>a--x

Try it

Desmos, 38 bytes

f(l)=[0^{(k-l)^2}.maxfork=[1...l.max]]

Try It On Desmos!

HBL, 9.5 bytes

'?(*(*-,.
*().(0(/.

1-indexed. Try it here!

Explanation

The helper function on the first line takes two arguments: a list of indices and a specific index. It returns 1 if the index appears in the list, 0 if it does not.

'?(*(*-,.
    (*   )   For each element of
        .    the list,
      -      subtract it from
       ,     the index
  (*      )  Take the product of the resulting list
'?           Is the product zero?

The main function takes a list of indices and returns the "untruthed" list of 0's and 1's:

*().(0(/.
    (0    )  Range from 1 to
      (/ )   the maximum of
        .    the list
*            For each element,
 ()          call the helper function
   .         with the index list as first argument
             and the element of the range as second argument

Haskell, 30 bytes

f a=map(`elem`a)[1..maximum a]

Try it online!

The relevant function is f, which takes as input a list of integers a (1-indexed) and returns a list of Bools.

Vyxal, 6 bytes

Gɾƛ?$c

Try it Online!

Gɾƛ?$c
G      Maximum
 ɾ     Range
  ƛ    Map:
   ?     Push the input
    $    Swap
     c   Contains?

Nim, 60 58 bytes

func t[S](n:S):S=
 for i in 1..n.max:result.add int i in n

Try it online!

Zsh, 44 bytes

for i ({1..${${(nO)@}[1]}})<<<$[$@[(I)$i]>0]

Try it online!

Explanation:

             ${(nO)@}                          # sort the arguments numerically, in reverse
           ${        [1]}                      # take the first (i.e. maximum value)
       {1..              }                     # range from 1 to that
for i (                   )                    # for each i
                                @[(I)$i]       # find the index of `i` in `argv`, or 0 if not present
                              $[        >0]    # is that positive? (1 or 0)
                           <<<                 # print

jq, 30 29 27 bytes

range(max)as$a|[$a+1]-.==[]

Try it online!

Explanation

range(                      # the 0-range up to
  max)                      # the largest item of the input - 1
as$a                        # And assign it to $a

|                           # And then, for every item in $a:
[$a+1]-.==[]                #     Is the item + 1 contained in the original input?

C# (Visual C# Interactive Compiler), 49 bytes

a=>Enumerable.Range(1,a.Max()).Select(a.Contains)

Try it online!

Saved 3 bytes thanks to caird

Saved 1 byte thanks to didymus

Saved 2 bytes thanks to NonlinearFruit

x86_64 (zero indexed, length given), 19 16 bytes

Raw machine code:

31 c0 57 f3 aa 5f 89 d1 8d c6 04 07 01 e2 f9 c3

Uncommented assembly:

        .intel_syntax noprefix
        .globl untruth
untruth:
        xor     eax, eax
        push    rdi
        rep stosb byte ptr [rdi]
        pop     rdi
        mov     ecx, edx
.Lloop:
        lodsd   dword ptr [rsi]
        mov     byte ptr [rdi + rax], 1
        loop    .Lloop
.Lend:
        ret

Explanation

I'm not too good at x86, so I am pretty sure there is a better way to do this.

C signature:

// System V ABI (rdi, rsi, rdx, rcx)
void untruth(bool *out, const uint32_t *indices, uint32_t indices_len, uint32_t out_len);

It's my function, I can order the parameters however I please. 😏

First: memset(out, 0, out_len) using rep stosb. Since we need to save the pointer and stosb clobbers it, we push and pop it.

The standard calling conventions say that the direction flag is always cleared when calling, so we know this will be a forwards operation.

untruth:
        xor     eax, eax
        push    rdi
        rep stosb byte ptr [rdi]
        pop     rdi

Using the fancy loop instruction, loop through each index in the array, storing 1 to out[index]

        mov     ecx, edx
.Lloop:
        lodsd   dword ptr [rsi]
        mov     byte ptr [rdi + rax], 1
        loop    .Lloop

At the end of the loop, return.

.Lend:
        ret

Note: It also happens to be x86-compatible on the binary level.

Thanks to Neil for the -3 bytes (using lodsd)!

x86_64 (zero indexed, calculates max), 28 bytes

Raw machine code:

31 c0 57 51 af 0f 42 47 fc e2 f9 91 56 56 5f f3
aa 5f 59 5e ad c6 04 07 01 e2 f9 c3

Assembly:

        .intel_syntax noprefix
        .globl untruth
        # void untruth(const uint32_t *indices{rdi}, char *out{rsi}, uint32_t indices_len{rcx})
untruth:
        xor     eax, eax
        push    rdi
        push    rcx
.Lfind_max:
        scasd   eax, dword ptr [rdi]
        cmovb   eax, dword ptr [rdi - 4]
        loop    .Lfind_max
.Lfind_max.end:
        xchg    ecx, eax
        push    rsi
        push    rsi
        pop     rdi
        rep stos byte ptr [rdi], al
        pop     rdi
        pop     rcx
        pop     rsi
.Lloop:
        lodsd   eax, dword ptr [rsi]
        mov     byte ptr [rdi + rax], 1
        loop    .Lloop
.Lloop_end:
        ret

This version will check for the maximum itself, but the output buffer provided must be large enough.

Probably many things here can be optimized.

Explanation

Note that the parameters are different than the first: indices is in rdi, out is in rsi, rdx is unused, and indices_len is in rcx.

I don't know why scasd uses rdi but whatever.

This is a simple max loop. It compares each dword in indices, and sets eax to the maximum.

This seems to be smaller than doing something with lodsd, although that 4 byte cmovb is pretty yucky.

untruth:
        xor     eax, eax
        push    rdi
        push    rcx
.Lfind_max:
        scasd   eax, dword ptr [rdi]
        cmovb   eax, dword ptr [rdi - 4]
        loop    .Lfind_max

Since we know ecx will be zero due to the loop condition, we can set ecx to the maximum and set eax to zero in one byte.

.Lfind_max.end:
        xchg    ecx, eax

Unfortunately, our output array is in rsi, not rdi. We push and pop twice to mov without the REX tax and save a copy, then do a memset with rep stosb.

        push    rsi
        push    rsi
        pop     rdi
        rep stos byte ptr [rdi], al
        pop     rdi

Now we need to get indices and indices_len from the stack. Note that this time, we put indices into rsi.

        pop     rcx
        pop     rsi

For each dword in indices, out[indices[i]] to 1 using lodsd and loop

.Lloop:
        lodsd   eax, dword ptr [rsi]
        mov     byte ptr [rdi + rax], 1
        loop    .Lloop

Return.

.Lloop_end:
        ret

FALSE, 183 bytes

0$$b:c:d:[^$1_=~][$32=$[%%0a:[a;b;=~][a;1\[$0=~][\10*\1-]#%*a;0=~[+]?a;1+$b;=~[@\]?a:]#0b:c;1+c:$d;>[$d:]?1_]?~[b;1+b:48-]?]#%[b;d;>~][0$e:[$1=~e;c;=~&][e;1+$e:øb;=[%1]?]#.32,b;1+b:]#

Try it online!

NOTE: Since FALSE does not actually have arrays, input is space-separated numbers with one space at the end, and output is the same.

Most of this answer is just input string to int.

0 indexed.

05AB1E, 4 3 bytes

ZLå

Try it online!

Yes it is just a port of every other answer.

Explained

ZLå
ZL   # Push the range: [1, max(input)]
  å  # Vectorise: is item in input? over that range

JavaScript (Node.js), 45 44 bytes

a=>a.map(b=>c[b]=1,c=[])&&[...c].map(d=>d|0)

Try it online!

This implementation uses zero indexing and returns an array of 0s and 1s.

I think the code isn't very difficult to understand. Here's a summary explanation:

Thanks to Neil for -1 byte.

MATL, 4 bytes

v1i(

Try it online! Or verify all test cases.

Explanation

v   % Concatenate stack contents vertically. Gives an empty array
1   % Push 1
i   % Take input
(   % Assignment indexing: write 1 into the array at the input positions.
    % This automatically extends the array and fills with 0
    % Implicit display

Gaia, 7 bytes

e:⌉┅¤Ė¦

Try it online!

Identical to, e.g., pajonk's R answer.

e:		# eval implicit input as a list and duplicate
⌉┅		# take the max of the list and compute [1...M]
¤		# swap so [1..M] is on the bottom
˦		# For each element of [1..M], is it in the input list?

Haskell, 52 49 bytes

t=foldl(#)[]
l#i=take i(l++[0,0..])++1:drop(i+1)l

Try it online!

R, 24 23 bytes

Edit: -1 byte thanks to pajonk

F[scan()]=1;F&!is.na(F)

Try it online!

A different approach to pajonk's R answer.
Shorter at time of posting, but this is a precarious situation, as it would be longer in a fair 'apples-with-apples' comparison (using scan() for both approaches).

C (gcc) with -m32, 87 bytes

Zero-indexed, using -1 as a sentinel value for arrays.

To get the size of the output array, I recursively scan the input array and allocate the output array with the maximum size found (plus one for the sentinel.) After that, each input index is marked and the resulting array is returned.

*j;*g(i,m)int*i;{~*i?g(i+1,m<*i?*i:m)[*i]=1:(j=calloc(++m+1,4))[m]--;i=j;}f(i){g(i,0);}

Try it online!

Japt, 6 bytes

rÔõ!øU

Try it

ÍÌÆøXÄ

Try it

R, 32 25 24 bytes

function(x)1:max(x)%in%x

Try it online!

Taking advantage of %in% operator and abusing weird precedence.

-1 thanks to Dominic van Essen

21 bytes using scan

1:max(x<-scan())%in%x

Try it online!

Factor, 35 bytes

[ 0 [ 2^ bitor ] reduce make-bits ]

Try it online!

Takes a sequence of 0-based indices and returns a virtual boolean sequence of t (true) and f (false).

How it works

[
  0 [ 2^ bitor ] reduce  ! Reduce all 2^n bitmasks by bitwise OR
                         ! for each n in the sequence
  make-bits  ! Create a virtual sequence of bits from the integer
]

Zsh, 25 bytes

for x;a[x]=1
<<<${a/#%/0}

Try it online!

The # and % in globs act like the regex ^ and $ anchors, but for full words instead of lines.

Altenatively, <<<${a:///0} works.


Very similar Zsh solution to another question

Add++, 9 bytes

L,dbMR$€e

Try it online!

Given that no-one besides me really uses Add++, I figured I wouldn't be sniping anyone

How it works

L,dbMR$€e - Anonymous lambda function
L,        - Define the lambda function. Takes l as input
  d       - Duplicate; STACK = [l l]
  bM      - Maximum;   STACK = [l max(l)]
  R       - Range;     STACK = [l [1 2 ... max(l)]]
  $       - Swap;      STACK = [[1 2 ... max(l)] l]
  €       - Over each:
    e     -   In l?

Julia 1.0, 25 21 bytes

x->1:max(x...).∈[x]

Try it online!

PowerShell, 45 bytes

1-indexed, which felt weird to do in a 0-indexed language. Accepts only non-negative integers; negative indexing in powershell is 1-based, so this answer breaks down for negative cases.

$a=,0*($args|sort)[-1];$args|%{$a[$_-1]=1};$a

Try it online!

Octave, 17 bytes

@(x){y(x)=1,y}{2}

Anonymous function that takes a row (or column) vector as input and produces a row vector as output.

Uses the last trick on this list to effectively include several statements in an anonymous function.

Try it online!

J, 12 bytes

e.~1 i.@+>./

Try it online!

0-indexed; similar to Bubbler's APL solution

K (oK), 14 12 bytes

-2 bytes thanks to coltim

{~^x?!1+|/x}

Try it online!

0-indexed

Java (JDK), 82 bytes

a->{int m=0,r[];for(int i:a)m=i>m?i:m;r=new int[m];for(int i:a)r[i-1]=1;return r;}

Try it online!

Scala, 19 bytes

i=>1 to i.max map i

Try it online!

Returns a Seq of Booleans. Takes a Set[Int] as input, since sets are also predicates in Scala. If a list is taken as input, i.contains would have to be used instead.

Charcoal, 9 bytes

⭆⊕⌈θ∧№θι¹

Try it online! Link is to verbose version of code. Outputs a binary string. 0-indexed. Explanation:

   θ        Input array
  ⌈         Maximum
 ⊕          Incremented
⭆           Map over implicit range and join.
     №      Count of
       ι    Current index
      θ     In input array
    ∧       Logical Or
        ¹   Literal `1`
            Implicitly print

1-indexed version is also 9 bytes:

⭆⌈θ∧№θ⊕ι¹

Try it online! Link is to verbose version of code. Explanation: Same as the first version, except that the increment is in a different place.

JavaScript (ES6), 50 bytes

a=>a.map(g=(x,i)=>x&&g(--x,g,o[x]|=++i/i),o=[])&&o

Try it online!

Commented

a =>                // a[] = input array
  a.map(            // for each ...
    g = (x, i) =>   // ... value x at position i in a[]:
      x &&          //   if x is not equal to 0:
        g(          //     do a recursive call:
          --x,      //       decrement x
          g,        //       force i to a non-numeric value
          o[x] |=   //       update o[x]:
            ++i / i //         set it to 1 if i is numeric (≥ 0)
                    //         or just coerce it to a number otherwise
                    //         (i.e. undefined values are turned into 0's)
        ),          //     end of recursive call
      o = []        //   start with o[] = empty array
  ) && o            // end of map(); return o[]

Retina 0.8.2, 51 bytes

.+
$*01
+`^((.)*).?(.*)¶(?<-2>.)*(?(2)$)(.+)
$1$4$3

Try it online! Takes input as a newline-separated list but link includes test suite that converts from comma-separated for ease of use. Outputs a binary string. 0-indexed. Explanation:

.+
$*01

Convert each entry into a string of 0s followed by a 1.

+`

For each additional entry, its 1 is merged into the first line in turn:

^((.)*)

Match the prefix on the first line.

.?(.*)¶

Skip the digit above the 1, if any, but keep the suffix of the first line.

(?<-2>.)*(?(2)$)

Match a prefix of the same length on the second line.

(.+)

Match the any 0s needed for padding and the 1.

$1$4$3

If the first line was shorter than the second line, then append the suffix of the second line to the first line, otherwise insert the 1 from the second line in between the prefix and suffix of the first line.

Example 1: When merging 10001 with 001, the prefix is two characters, 10 (captured as $1) on the first line corresponding to 00 on the second line. The 1 (captured as $4) from the second line is then inserted, and then the suffix 01 on the first line (captured as $3) is appended, resulting in 10101.

Example 2: When merging 101 with 00001, the prefix is three characters 101 (captured as $1) on the first line corresponding to 000 on the second line. The 01 (captured as $4) from the second line is then appended ($3 is empty as the first line is shorter than the second), again resulting in 10101.

Python 3, 42 41 bytes

-1 thanks to @ovs

lambda a:[i+1in a for i in range(max(a))]

Try it online!

Neim, 5 bytes

𝐠𝐈Γ₁𝕚

Try it online!

Explanation:

𝐠        # Get Greatest element
 𝐈       # Inclusive range: (0 .. n]
  Γ      # For each element in range do: 
   ₁     # 1st input line
    𝕚    # Check that the int is in the list

Wolfram Language (Mathematica), 20 bytes

SparseArray[#->1^#]&

Try it online!

Returns a SparseArray.

Brachylog, 11 bytes

{~l,1}ᵐz₁⌉ᵐ

Try it online!

It's certainly interesting to consider what approach is the best in a language without a concept of a Boolean. 0-indexed. For some reason the unbound variables that are pretty much 0 are actually displaying as variables, so tack a onto the end if that's a problem.

{    }ᵐ        For each element of the input:
   ,1          append 1 to
 ~l            something that long.
       z₁      Ragged zip. (i.e. non-cycling, doesn't stop until all lists are exhausted)
         ⌉ᵐ    Take the maximum of each column.

Ruby 2.7, 33 bytes

->a,n=[0]*a.max{a.map{n[_1]=1};n}

Try it online!

Uses the 0-indexing. TIO uses an older version of Ruby, whereas in Ruby 2.7, we've numbered parameters, which saves two bytes.

APL (Dyalog Extended), 3 bytes

ׯ⍸

Try it online!

A tacit function. Banning only the exact built-in actually gives APL a massive advantage!

How it works

ׯ⍸
  ⍸  ⍝ Takes a vector v and gives another vector containing v[i] copies of i
     ⍝ for each index i
 ¯   ⍝ Inverse of the above, which counts occurrences of i which becomes v[i]
×    ⍝ Signum of each number, converting any positive count to 1

APL (Dyalog Unicode), 7 bytes

⊢∊⍨∘⍳⌈/
(⍳⌈/)∊⊢

Try it online!

Non-Extended solution. Works exactly like the 3-byte Jelly solution.

APL (Dyalog Unicode), 7 bytes

∨⌿-↑⍤0×

Try it online!

A fun way to do the job. For each number n, create a length-n vector that has a 1 at the end and 0 for the rest. Then promote the entire array to a matrix (padding as necessary) and take the logical OR of the rows.

Husk, 7 bytes

mo±€¹ḣ▲

Try it online!

I feel like I'm missing a way to do this with η.

Explanation

mo±€¹ḣ▲
     ḣ▲ range 1..max(input)
mo      map each to
   €¹   whether it's present in the input(index if present, 0 if not)
  ±     and take the sign of that

Jelly, 3 bytes

Ṁe€

Try it online!

This does seem somewhat difficult to outdo.

  €    Map over (the range from 1 to)
Ṁ      the largest element of the input:
 e     is it in the input?

Silly, 0-indexed bonus:

Jelly, 6 bytes

2*BUo/

Try it online!

2*        For each element of the input, raise 2 to that power.
  B       Convert to binary
   U      and reverse each,
     /    then reduce by
    o     vectorizing logical OR.

Perl 5, -pa 33 bytes

@r[@F]=(1)x@F;map$_+=0,@r;$_="@r"

Try it online!

0 indexed. Input and output are space separated.