From e2d0ee960837bca9ad2e85a88be5a0375e112ee5 Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Fri, 20 Sep 2024 09:41:59 +0100 Subject: Add Python solution to challenge 069 --- challenge-069/paulo-custodio/python/ch-2.py | 47 +++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 challenge-069/paulo-custodio/python/ch-2.py (limited to 'challenge-069/paulo-custodio/python/ch-2.py') diff --git a/challenge-069/paulo-custodio/python/ch-2.py b/challenge-069/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..2987057e01 --- /dev/null +++ b/challenge-069/paulo-custodio/python/ch-2.py @@ -0,0 +1,47 @@ +#!/usr/bin/env perl + +# Challenge 069 +# +# TASK #2 > 0/1 String +# Submitted by: Mohammad S Anwar +# A 0/1 string is a string in which every character is either 0 or 1. +# +# Write a script to perform switch and reverse to generate S30 as described +# below: +# +# switch: +# +# Every 0 becomes 1 and every 1 becomes 0. For example, "101" becomes "010". +# +# reverse: +# +# The string is reversed. For example, "001" becomes "100". +# UPDATE (2020-07-13 17:00:00): +# It was brought to my notice that generating S1000 string would be nearly +# impossible. So I have decided to lower it down to S30. Please follow the rule +# as below: +# +# S0 = "" +# S1 = "0" +# S2 = "001" +# S3 = "0010011" +# +# SN = SN-1 + "0" + switch(reverse(SN-1)) + +# Note: modified to S20, as S30 was taking forever + +N = 20 + +def bits_switch(s): + return s.translate(str.maketrans('01', '10')) + +def bits_reverse(s): + return ''.join(reversed(s)) + +prev = "" +s = "" +for _ in range(1, N + 1): + s = prev + "0" + bits_switch(bits_reverse(prev)) + prev = s + +print(s) -- cgit From 5354c57e27196ca67ad5e821b3e999867c1aaef3 Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Fri, 20 Sep 2024 10:23:09 +0100 Subject: Add Python solution to challenge 070 --- challenge-069/paulo-custodio/python/ch-2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'challenge-069/paulo-custodio/python/ch-2.py') diff --git a/challenge-069/paulo-custodio/python/ch-2.py b/challenge-069/paulo-custodio/python/ch-2.py index 2987057e01..d5fca17564 100644 --- a/challenge-069/paulo-custodio/python/ch-2.py +++ b/challenge-069/paulo-custodio/python/ch-2.py @@ -1,4 +1,4 @@ -#!/usr/bin/env perl +#!/usr/bin/env python3 # Challenge 069 # -- cgit