-2
\$\begingroup\$

Introduction

So the Challenge is to give out all combinations with two Inputs. The length of the string is also optional and you should be able to edit this.

I've selected this channel because I thought it would be very easy to do it "normally" but the challenge itself could be very interesting. I had to create that for one of our employee to make a list with product numbers.

I quickly searched the site and I didn't found any other Challenges like this.

Challenge

So the input doesn't have to be edited so you can just take the binary system [0,1]. But you have to set the length of the string or char of the output.

You can give out all the numbers in a file. You can decide the name and also the file type.

The Shortest program in characters wins.

Example Input and Output

Input:

3

Output example.txt:

000
001
010
100
101
110
111
011

Input:

2

Output example.txt:

00
01
10
11
\$\endgroup\$
  • \$\begingroup\$ Related and related. EDIT: actually, this might be a dupe instead (only difference is that this challenge takes [1,0] hard-coded and the other challenge takes a list as input, and the other challenge states the output should be sorted). \$\endgroup\$ – Kevin Cruijssen Jul 1 at 9:29
  • \$\begingroup\$ Any reason why 011 is output last in the first example? \$\endgroup\$ – Arnauld Jul 1 at 9:32
  • \$\begingroup\$ The order in the output isn't important. \$\endgroup\$ – Doggo Jul 1 at 9:33
  • \$\begingroup\$ It was a toss-up whether to vote to close as unclear or dupe, but I think it's clear enough that you're just asking us to count from 0 to 2**n - 1. \$\endgroup\$ – Peter Taylor Jul 1 at 9:45
0
\$\begingroup\$

05AB1E, 3 bytes

TIã

Try it online or verify a few more test cases.

Explanation:

T    # Push 10
 Iã  # Take the cartesian product of "10" repeated the input amount of times
     # (and output the resulting list implicitly as result)
\$\endgroup\$
0
\$\begingroup\$

Python 2, 46 bytes

lambda n:map(('{:0%db}'%n).format,range(1<<n))

Try it online!

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.