From 7889c7605e7b825721131dae38d80523d59c3e17 Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Tue, 9 Mar 2021 19:38:45 +0000 Subject: Add Lua and Python solutions to challenge 092 --- challenge-092/paulo-custodio/python/ch-1.py | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 challenge-092/paulo-custodio/python/ch-1.py (limited to 'challenge-092/paulo-custodio/python/ch-1.py') diff --git a/challenge-092/paulo-custodio/python/ch-1.py b/challenge-092/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..73b5d30b43 --- /dev/null +++ b/challenge-092/paulo-custodio/python/ch-1.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python + +# Challenge 092 +# +# TASK #1 > Isomorphic Strings +# Submitted by: Mohammad S Anwar +# You are given two strings $A and $B. +# +# Write a script to check if the given strings are Isomorphic. Print 1 if they +# are otherwise 0. +# +# Example 1: +# Input: $A = "abc"; $B = "xyz" +# Output: 1 +# Example 2: +# Input: $A = "abb"; $B = "xyy" +# Output: 1 +# Example 3: +# Input: $A = "sum"; $B = "add" +# Output: 0 + +import sys + +def isomorphic(a,b): + if len(a)!=len(b): + return 0 + else: + mapping = {} + mapped = {} + for i in range(0, len(a)): + if not a[i] in mapping: # a is new + if b[i] in mapped: # b already mapped to some other a + return 0 + else: # store mapping + mapping[a[i]] = b[i] + mapped[b[i]] = 1 + else: # a already occurred + if mapping[a[i]]!=b[i]: # previous mapping is different + return 0 + return 1 + +print(isomorphic(sys.argv[1], sys.argv[2])) -- cgit From c51f9bd979dbd79f20cb0abd543dc9b4df9f4e84 Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Tue, 9 Mar 2021 20:01:18 +0000 Subject: Remove tabs --- challenge-092/paulo-custodio/python/ch-1.py | 32 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'challenge-092/paulo-custodio/python/ch-1.py') diff --git a/challenge-092/paulo-custodio/python/ch-1.py b/challenge-092/paulo-custodio/python/ch-1.py index 73b5d30b43..70e334812e 100644 --- a/challenge-092/paulo-custodio/python/ch-1.py +++ b/challenge-092/paulo-custodio/python/ch-1.py @@ -22,21 +22,21 @@ import sys def isomorphic(a,b): - if len(a)!=len(b): - return 0 - else: - mapping = {} - mapped = {} - for i in range(0, len(a)): - if not a[i] in mapping: # a is new - if b[i] in mapped: # b already mapped to some other a - return 0 - else: # store mapping - mapping[a[i]] = b[i] - mapped[b[i]] = 1 - else: # a already occurred - if mapping[a[i]]!=b[i]: # previous mapping is different - return 0 - return 1 + if len(a)!=len(b): + return 0 + else: + mapping = {} + mapped = {} + for i in range(0, len(a)): + if not a[i] in mapping: # a is new + if b[i] in mapped: # b already mapped to some other a + return 0 + else: # store mapping + mapping[a[i]] = b[i] + mapped[b[i]] = 1 + else: # a already occurred + if mapping[a[i]]!=b[i]: # previous mapping is different + return 0 + return 1 print(isomorphic(sys.argv[1], sys.argv[2])) -- cgit