diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-11-29 12:27:10 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-11-29 12:27:10 +0000 |
| commit | 58165265b16e87f0728c26eb509a7df8a197d7d5 (patch) | |
| tree | 51458be8bbb9fa912fbd3a66213b50742fd7b90c | |
| parent | fa14839a1bf5e4a2aff002c6753f76e5d15f9a00 (diff) | |
| download | perlweeklychallenge-club-58165265b16e87f0728c26eb509a7df8a197d7d5.tar.gz perlweeklychallenge-club-58165265b16e87f0728c26eb509a7df8a197d7d5.tar.bz2 perlweeklychallenge-club-58165265b16e87f0728c26eb509a7df8a197d7d5.zip | |
- Added more guest contribution by Robert DiCicco.
| -rw-r--r-- | challenge-193/robert-dicicco/python/ch-1.py | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/challenge-193/robert-dicicco/python/ch-1.py b/challenge-193/robert-dicicco/python/ch-1.py new file mode 100644 index 0000000000..ddab4e1aed --- /dev/null +++ b/challenge-193/robert-dicicco/python/ch-1.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python + +''' + +AUTHOR: Robert DiCicco + +DATE: 2022-11-28 + +Challenge 193 Binary String ( Python ) + + + +Write a script to find all possible binary numbers of size $n. + +Example 1 + + + +Input: $n = 2 + +Output: 00, 11, 01, 10 + + + +Example 2 + + + +Input: $n = 3 + +Output: 000, 001, 010, 100, 111, 110, 101, 011 + +------------------------------------------------------ + +SAMPLE OUTPUT + +python .\BinaryString.py + +Input: $n = 2 + +Output: 00 01 10 11 + + + +Input: $n = 3 + +Output: 000 001 010 011 100 101 110 111 + + + +Input: $n = 4 + +Output: 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 + +''' + + + +arr = [2,3,4] + + + +for p in arr: + + print("Input: $n = ",p) + + rng = range(2**p) + + print("Output: ", end=" ") + + for n in rng : + + pw = "0" + str(p) + + print("{:{width}b}".format(n,width=pw), end=" ") + + print("\n") |
