Skip to content

Commit 8e228fb

Browse files
committed
add five files
1 parent 6b44542 commit 8e228fb

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

[6 kyu]Decode the Morse code.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MORSE_CODE = {'.-...': '&', '--..--': ',', '....-': '4',
2+
'.....': '5', '...---...': 'SOS', '-...': 'B', '-..-': 'X',
3+
'.-.': 'R', '.--': 'W', '..---': '2', '.-': 'A', '..': 'I',
4+
'..-.': 'F', '.': 'E', '.-..': 'L', '...': 'S', '..-': 'U',
5+
'..--..': '?', '.----': '1', '-.-': 'K', '-..': 'D', '-....': '6',
6+
'-...-': '=', '---': 'O', '.--.': 'P', '.-.-.-': '.', '--': 'M', '-.': 'N',
7+
'....': 'H', '.----.': "'", '...-': 'V', '--...': '7', '-.-.-.': ';',
8+
'-....-': '-', '..--.-': '_', '-.--.-': ')', '-.-.--': '!', '--.': 'G',
9+
'--.-': 'Q', '--..': 'Z', '-..-.': '/', '.-.-.': '+', '-.-.': 'C',
10+
'---...': ':', '-.--': 'Y', '-': 'T', '.--.-.': '@', '...-..-': '$',
11+
'.---': 'J', '-----': '0', '----.': '9', '.-..-.': '"', '-.--.': '(',
12+
'---..': '8', '...--': '3'}
13+
14+
def decodeMorse(morseCode):
15+
MORSE_CODE['@'] = ' '
16+
morseCode = morseCode.strip().replace(' ',' @ ')
17+
return ''.join([MORSE_CODE[code] for code in morseCode.split()])
18+
19+
20+
print(decodeMorse('.... . -.-- .--- ..- -.. . '))
21+
# H E Y J U D E

[beta]Fibonacci Rabbits.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def fib_rabbits(n, b):
2+
n -= 1
3+
young,adult = 1,0
4+
while n > 0:
5+
young,adult = adult * b , adult + young
6+
n -= 1
7+
return young + adult
8+
9+

[beta]String incrementer.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import re
2+
def increment_string(strng):
3+
strMatch = re.match(r'([\w]*)(\d*)',strng)
4+
stringPart,numberPart = strMatch.group(1),strMatch.group(2)
5+
number = re.match(r'0*(\d*)',numberPart).group(1)
6+
number = 1 if len(number) == 0 else int(number) + 1
7+
if len(str(number)) >= len(numberPart):
8+
number = number
9+
else :
10+
number = ('0' * (len(numberPart) - len(str(number)))) + str(number)
11+
return stringPart + str(number)
12+
13+
14+
15+
print(increment_string('foobar123'))
16+
print(increment_string('foobar0056'))
17+
print(increment_string('foobar'))
18+
print(increment_string('035'))
19+
print(increment_string(''))
20+
print(increment_string('p)L2_9:0R[800755806{OtCsowX8847280959000119'))

[beta]longest_palindrome.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#remodify to match python 2
2+
def longest_palindrome (s):
3+
print(s)
4+
if len(s) == 0:
5+
return 0
6+
def isPalindrome(string):
7+
return string == ''.join(string[::-1])
8+
for i in range(len(s)-1,-1,-1):
9+
print([i for i in range(len(s)-i)],i)
10+
for j in [i for i in range(len(s)-i)]:
11+
if isPalindrome(s[j:i+j+1]):
12+
return len(s[j:i+j+1])
13+
14+
15+
16+
print(longest_palindrome('baablkj12345432133d'))
17+
print(longest_palindrome('baa'))
18+
print(longest_palindrome('abba'))

drop.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
a,*b = (1,2,3)
2+
print(a,b)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy