Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

#JavaScript (ES6), (削除) 84 60 (削除ここまで) 58 bytes

JavaScript (ES6), (削除) 84 60 (削除ここまで) 58 bytes

Ignores \$d\$. Returns \0ドル\$ if there's no solution.

f=([v,...a],x,o=[])=>x<1?o:v?f(a,x,o)||f(a,x^v,[...o,v]):0

Try it online!

###Commented

Commented

f = ( // f is a recursive function taking:
 [v, // v = next value from the input set
 ...a], // a[] = array of remaining values
 x, // x = 'XOR total', initially undefined
 o = [] // o[] = output subset
) => //
 x < 1 ? // if x is defined and equal to 0:
 o // success: return o[]
 : // else:
 v ? // if v is defined:
 f(a, x, o) || // try a recursive call where v is ignored
 f(a, x ^ v, [...o, v]) // try a recursive call where v is used
 : // else:
 0 // failed

#JavaScript (ES6), (削除) 84 60 (削除ここまで) 58 bytes

Ignores \$d\$. Returns \0ドル\$ if there's no solution.

f=([v,...a],x,o=[])=>x<1?o:v?f(a,x,o)||f(a,x^v,[...o,v]):0

Try it online!

###Commented

f = ( // f is a recursive function taking:
 [v, // v = next value from the input set
 ...a], // a[] = array of remaining values
 x, // x = 'XOR total', initially undefined
 o = [] // o[] = output subset
) => //
 x < 1 ? // if x is defined and equal to 0:
 o // success: return o[]
 : // else:
 v ? // if v is defined:
 f(a, x, o) || // try a recursive call where v is ignored
 f(a, x ^ v, [...o, v]) // try a recursive call where v is used
 : // else:
 0 // failed

JavaScript (ES6), (削除) 84 60 (削除ここまで) 58 bytes

Ignores \$d\$. Returns \0ドル\$ if there's no solution.

f=([v,...a],x,o=[])=>x<1?o:v?f(a,x,o)||f(a,x^v,[...o,v]):0

Try it online!

Commented

f = ( // f is a recursive function taking:
 [v, // v = next value from the input set
 ...a], // a[] = array of remaining values
 x, // x = 'XOR total', initially undefined
 o = [] // o[] = output subset
) => //
 x < 1 ? // if x is defined and equal to 0:
 o // success: return o[]
 : // else:
 v ? // if v is defined:
 f(a, x, o) || // try a recursive call where v is ignored
 f(a, x ^ v, [...o, v]) // try a recursive call where v is used
 : // else:
 0 // failed
saved 2 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

#JavaScript (ES6), (削除) 84 60 (削除ここまで) 6058 bytes

Ignores \$d\$. Returns \0ドル\$ if there's no solution.

f=([v,...a],x,o=[])=>x<1?o:1/v?f(a,x,o)||f(a,x^v,[...o,v]):0

Try it online! Try it online!

###Commented

f = ( // f is a recursive function taking:
 [v, // v = next value from the input set
 ...a], // a[] = array of remaining values
 x, // x = 'XOR total', initially undefined
 o = [] // o[] = output subset
) => //
 x < 1 ? // if x is defined and equal to 0:
 o // success: return o[]
 : // else:
 1 / v ? // if v is defined:
 f(a, x, o) || // try a recursive call where v is ignored
 f(a, x ^ v, [...o, v]) // try a recursive call where v is used
 : // else:
 0 // failed

#JavaScript (ES6), (削除) 84 (削除ここまで) 60 bytes

Ignores \$d\$. Returns \0ドル\$ if there's no solution.

f=([v,...a],x,o=[])=>x<1?o:1/v?f(a,x,o)||f(a,x^v,[...o,v]):0

Try it online!

###Commented

f = ( // f is a recursive function taking:
 [v, // v = next value from the input set
 ...a], // a[] = array of remaining values
 x, // x = 'XOR total', initially undefined
 o = [] // o[] = output subset
) => //
 x < 1 ? // if x is defined and equal to 0:
 o // success: return o[]
 : // else:
 1 / v ? // if v is defined:
 f(a, x, o) || // try a recursive call where v is ignored
 f(a, x ^ v, [...o, v]) // try a recursive call where v is used
 : // else:
 0 // failed

#JavaScript (ES6), (削除) 84 60 (削除ここまで) 58 bytes

Ignores \$d\$. Returns \0ドル\$ if there's no solution.

f=([v,...a],x,o=[])=>x<1?o:v?f(a,x,o)||f(a,x^v,[...o,v]):0

Try it online!

###Commented

f = ( // f is a recursive function taking:
 [v, // v = next value from the input set
 ...a], // a[] = array of remaining values
 x, // x = 'XOR total', initially undefined
 o = [] // o[] = output subset
) => //
 x < 1 ? // if x is defined and equal to 0:
 o // success: return o[]
 : // else:
 v ? // if v is defined:
 f(a, x, o) || // try a recursive call where v is ignored
 f(a, x ^ v, [...o, v]) // try a recursive call where v is used
 : // else:
 0 // failed
added a commented version
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

#JavaScript (ES6), (削除) 84 (削除ここまで) 60 bytes

Ignores \$d\$. Returns \0ドル\$ if there's no solution.

f=([v,...a],x,o=[])=>x<1?o:1/v?f(a,x,o)||f(a,x^v,[...o,v]):0

Try it online!

###Commented

f = ( // f is a recursive function taking:
 [v, // v = next value from the input set
 ...a], // a[] = array of remaining values
 x, // x = 'XOR total', initially undefined
 o = [] // o[] = output subset
) => //
 x < 1 ? // if x is defined and equal to 0:
 o // success: return o[]
 : // else:
 1 / v ? // if v is defined:
 f(a, x, o) || // try a recursive call where v is ignored
 f(a, x ^ v, [...o, v]) // try a recursive call where v is used
 : // else:
 0 // failed

#JavaScript (ES6), (削除) 84 (削除ここまで) 60 bytes

Ignores \$d\$. Returns \0ドル\$ if there's no solution.

f=([v,...a],x,o=[])=>x<1?o:1/v?f(a,x,o)||f(a,x^v,[...o,v]):0

Try it online!

#JavaScript (ES6), (削除) 84 (削除ここまで) 60 bytes

Ignores \$d\$. Returns \0ドル\$ if there's no solution.

f=([v,...a],x,o=[])=>x<1?o:1/v?f(a,x,o)||f(a,x^v,[...o,v]):0

Try it online!

###Commented

f = ( // f is a recursive function taking:
 [v, // v = next value from the input set
 ...a], // a[] = array of remaining values
 x, // x = 'XOR total', initially undefined
 o = [] // o[] = output subset
) => //
 x < 1 ? // if x is defined and equal to 0:
 o // success: return o[]
 : // else:
 1 / v ? // if v is defined:
 f(a, x, o) || // try a recursive call where v is ignored
 f(a, x ^ v, [...o, v]) // try a recursive call where v is used
 : // else:
 0 // failed
saved 24 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading

AltStyle によって変換されたページ (->オリジナル) /