aboutsummaryrefslogtreecommitdiff
path: root/challenge-255/luca-ferrari/python/ch-1.python
diff options
context:
space:
mode:
authorrir <rirans@comcast.net>2024-02-09 21:20:12 -0500
committerrir <rirans@comcast.net>2024-02-09 21:20:12 -0500
commit138a757205ea1278fec6191eecdfa31b9d4fd3cc (patch)
tree08d8157e2f400c51e90e1bc6fcdb34581decb9b9 /challenge-255/luca-ferrari/python/ch-1.python
parent844af3cafa518e1f64f5a0729fcc69e1adfcba14 (diff)
parent399287fcd1fa2800c9ab44b9a065116e9a55ec86 (diff)
downloadperlweeklychallenge-club-138a757205ea1278fec6191eecdfa31b9d4fd3cc.tar.gz
perlweeklychallenge-club-138a757205ea1278fec6191eecdfa31b9d4fd3cc.tar.bz2
perlweeklychallenge-club-138a757205ea1278fec6191eecdfa31b9d4fd3cc.zip
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-255/luca-ferrari/python/ch-1.python')
-rw-r--r--challenge-255/luca-ferrari/python/ch-1.python26
1 files changed, 19 insertions, 7 deletions
diff --git a/challenge-255/luca-ferrari/python/ch-1.python b/challenge-255/luca-ferrari/python/ch-1.python
index a0533551d8..d5e0960574 100644
--- a/challenge-255/luca-ferrari/python/ch-1.python
+++ b/challenge-255/luca-ferrari/python/ch-1.python
@@ -1,24 +1,36 @@
#!python
#
-# Perl Weekly Challenge 254
+# Perl Weekly Challenge 255
# Task 1
#
# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-254>
#
import sys
-import math
# task implementation
# the return value will be printed
def task_1( args ):
- num = int( args[ 0 ] )
- for i in range( 2, int( math.sqrt( num ) ) ):
- if ( i ** 3 ) == num:
- return True
+ origin = args[ 0 ]
+ shuffled = args[ 1 ]
+ if len( shuffled ) != len( origin ) + 1:
+ return "Shuffled string must be one character longer than original string"
- return False
+ classification = {}
+
+ for needle in shuffled:
+ if not needle in classification:
+ classification[ needle ] = 0
+
+ classification[ needle ] += 1
+
+ for needle in origin:
+ classification[ needle ] -= 1
+ if classification[ needle ] <= 0:
+ del classification[ needle ]
+
+ return list( classification.keys() )[ 0 ]
# invoke the main without the command itself