Esempio n. 1
0
def transfor(s):
	result=''
	for char in s:
		if char in lowercase:
			if char<'w':
				char=lowercase[lowercase.index(char)+4]
			else:
				char=lowercase[3-len(lowercase)+lowercase.index(char)]
		elif char in uppercase:
			if char<'W':
				char=uppercase[uppercase.index(char)+4]
			else:
				char=uppercase[3-len(uppercase)+uppercase.index(char)]
		result+=char
	return result
Esempio n. 2
0
def bounding_coordinates( scale_code, zone, fuse, hemisphere):
    """Return the bounding box for the given CIM encoded chart, in ((minlon, maxlon),(minlat, maxlat))"""
    coordinates = ({'V':(0.0, 0.0), 'X':(0.0, 3.0), 'Y':(2.0, 0.0), 'Z':(2.0, 3.0)},
    {'A':(0.0, 0.0), 'B':(0.0, 1.5), 'C':(1.0, 0.0), 'D':(1.0, 1.5)},
    {'I':(0.0, 0.0), 'II':(0.0, 0.5), 'III':(0.0, 1.0), 'IV':(0.5, 0.0), 'V':(0.5, 0.5), 'VI':(0.5, 1.0)},
    {'1':(0.0, 0.0), '2':(0.0, 0.25), '3':(0.25, 0.0), '4':(0.25, 0.25)},
    {'NO':(0.0, 0.0), 'NE':(0.0, 0.125), 'SO':(0.125, 0.0), 'SE':(0.125, 0.125)},
    {'A':(0.0, 0.0), 'B':(0.0, 0.0625), 'C':(TWOM_30S, 0.0), 'D':(TWOM_30S, 0.0625), 'E':(TWOM_30S*2, 0.0), 'F':(TWOM_30S*2, 0.0625)})
    dims = {0:(4.0, 6.0), 1:(2.0, 3.0), 2:(1.0, 1.5), 3:(0.5, 0.5), 4:(0.25, 0.25), 5:(0.125, 0.125), 6:(TWOM_30S, 0.0625)}[len(scale_code)]
    print dims
    lat = zones.index(zone) * 4
    print lat
    lat = hemisphere == "N" and lat or -lat
    print lat
    lon = ((float(fuse) - 1)*6 - 180)
    print "fuse", fuse
    print "longitude", lon
    if scale_code:
        for scode, coords in zip(scale_code, coordinates):
            dy, dx = coords[scode]
            print "dlon, dlat\t", dx, dy
            lon += dx
            lat -= dy
            print "lon, lat\t", lon, lat
        #~ lon -= 180
        return lon, lon + dims[1], lat, lat - dims[0] #, lon), (lat - dims[0], lon + dims[1]))
    else:
        #~ lon -= 180
        return lon, lon + 6.0, lat, lat - 4.0
Esempio n. 3
0
def rot(c, n):
    """ Rotates a single character forward or backward n numbers in the alphabet
    """
    if c in lowercase:
        return lowercase[(lowercase.index(c) + n) % 26]
    elif c in uppercase:
        return uppercase[(uppercase.index(c) + n) % 26]
    else:
        return c
def caesarCipher(s, k):
    result = []
    for c in s:
        if c in lowercase:
            idx = (lowercase.index(c) + k) % 26
            result.append(lowercase[idx])
        elif c in uppercase:
            idx = (uppercase.index(c) + k) % 26
            result.append(uppercase[idx])
        else:
            result.append(c)
    return "".join(result)
Esempio n. 5
0
def get_data(text):
    data = {}
    for step in list(set(re.findall(re_str, text))):
        data[step] = {'blocks': [], 'prereqs': [], 'processing_time': uppercase.index(step) + 1}

    text = text.split('\n')

    for line in text:
        steps = re.findall(re_str, line)
        data[steps[0]]['blocks'].append(steps[1])
        data[steps[1]]['prereqs'].append(steps[0])
    return data
Esempio n. 6
0
from string import uppercase
from urllib import urlopen


page_text = urlopen('https://projecteuler.net/project/resources/p022_names.txt').read()
page_text_parsed = page_text.replace('"', '')
words = sorted(page_text_parsed.split(','))
print sum(sum(uppercase.index(c) + 1 for c in word) * (i + 1)
          for i, word in enumerate(words))
Esempio n. 7
0
def score_word(word):
    return sum([uppercase.index(letter) for letter in word]) + len(word)
Esempio n. 8
0
#!/usr/bin/env python
# *-* coding:utf-8 *-*

"""
Date :
Author : Vianney Gremmel [email protected]

"""

from string import uppercase

datas = ''
while True:
    try:
        datas += raw_input()
    except EOFError:
        break

datas = [word.strip()[1:-1] for word in datas.split(',')]

score = lambda word: sum(uppercase.index(c) + 1 for c in word)
istriangle = lambda n: not (-1 + (1+8*n)**0.5)%2

print sum(1 for word in datas if istriangle(score(word)))
Esempio n. 9
0
File: 22.py Progetto: Octember/Euler
def get_value(name):
	return sum([uppercase.index(letter) + 1 for letter in name])
Esempio n. 10
0
from string import uppercase
message = "IjgJUO{P_LOUV_AIRUS_GYQUTOLTD_SKRFB_TWNKCFT}"
numbers = '07271978'
new_message = ""
counter = 0
for i in message:
    if i.upper() in uppercase:
        new_message += uppercase[(uppercase.index(i.upper()) -
                                  int(numbers[counter])) % len(uppercase)]
        counter += 1
    else:
        new_message += i
    if counter == 8:
        counter = 0
print new_message
Esempio n. 11
0
#!/usr/bin/env python
# *-* coding:utf-8 *-*

"""
Date :
Author : Vianney Gremmel [email protected]

"""

from string import uppercase

datas = ''
while True:
    try:
        datas += raw_input()
    except EOFError:
        break

score = lambda name, pos: sum(uppercase.index(c) + 1 for c in name)*pos

datas = [name.strip()[1:-1] for name in datas.split(',')]
datas.sort()
print sum(score(name, pos + 1) for pos, name in enumerate(datas))
Esempio n. 12
0
def calc_score(word):
    return sum([uppercase.index(n) + 1 for n in word])
Esempio n. 13
0
from string import uppercase

T = int(raw_input())
for t in xrange(T):
    line = raw_input()
    
    if line[0] == 'R' and line[1] not in uppercase:
        i = line.index('C')
        row = line[1:i]
        if i > 0:
            col = ''
            x = int(line[i+2:])
            while x > 0:
                x, d = divmod(x-1, 26)
                col = uppercase[d] + col
            print col + row
            continue
    col = 0
    for c in line:
        if c not in uppercase: break
        col = col*26 + uppercase.index(c) + 1
    print 'R%sC%d' % (row, col)
def calc_score(word):
    return sum([uppercase.index(n) + 1 for n in word])
Esempio n. 15
0
 def test_single_letter(self):
     s = Solution()
     for i in uppercase:
         self.assertEquals(s.titleToNumber(i), uppercase.index(i) + 1)
Esempio n. 16
0
File: 42.py Progetto: Octember/Euler
def get_value(word):
	return sum([uppercase.index(letter) + 1 for letter in word])
Esempio n. 17
0
 def titleToNumber(self, s):
     if not s:
         return 0
     else:
         return sum((uppercase.index(letter) + 1) * 26 ** i
                    for i, letter in enumerate(reversed(s)))
Esempio n. 18
0
# Problem22 Name scores
# Let's try no optimization
import ujson
from string import uppercase

names = []
with open("p022_names.txt", "r") as f:
    names = ujson.decode("[" + f.read() + "]")


names = sorted(names)
score = 0

for pos, name in enumerate(names, start=1):
    local_score = reduce(lambda x, y: x + y, [uppercase.index(ch)+1 for ch in name])
    score += (local_score * pos)

print score