Skip to content

Instantly share code, notes, and snippets.

@popey456963
Last active October 26, 2017 06:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save popey456963/ad4a6446707c7d26a58a to your computer and use it in GitHub Desktop.
Save popey456963/ad4a6446707c7d26a58a to your computer and use it in GitHub Desktop.
List of Programs

Programming

Table of Contents

  1. Quick Tricks
  2. Binary Operations
  1. Puzzles
  1. Numerical
  1. Letters

Quick Tricks

# Return both index and value of an iterator
    for index,value in enumerate(array):
# Generator function to return array of ints:
    [int(i) for i in input().split()]
# Map function to return array of ints:
    map(int, input().split())
# IF/ELSE statement on one line:
    print("false","true")[i==j]
# String Splicing:
    string="This is a test"
        Remove First Two Characters    [2:] = "is is a test"
        Only Have First Two Characters [:2] = "Th"
        Only Have Last Two Characters  [-2:] = "st"
        Remove Last Two Characters     [:-2] = "This is a te"
        Get Characters 2 - 6           [2:6] = "is i"
        Get Every Second Character     [::2] = "Ti sats"
        Reverse The String             [::-1] = "tset a si sihT"
# Intersection of Strings
    a.intersection(b)
# Operator Allows ItemGetter
    import operator
    for i in sorted(a,key=operator.itemgetter(1)):
# Or, Another Method
    b=sorted(a,key=lambda x:x[1],reverse=True)
# Most Common Character
    import collections
    collections.Counter(s).most_common(1)[0][1]

Binary Operations

XOR
n_1, n_2 = input().split()
a=""
for i,v in enumerate(n_1):
    if n_1[i] == "0" and n_2[i] == "0":
        a+="0"
    if n_1[i] == "0" and n_2[i] == "1":
        a+="1"
    if n_1[i] == "1" and n_2[i] == "0":
        a+="1"
    if n_1[i] == "1" and n_2[i] == "1":
        a+="0"
print(a)
f,s=input().split()
a=""
for i,v in enumerate(f):
 if f[i]==s[i]:a+="0"
 else:a+="1"
print(a)
f,s=input().split()
for i in range(len(f)):print(("1","0")[f[i]==s[i]],end="")
OR
f,s = input().split()
string = ""
for i in range(len(f)):
    if f[i] == "0" and s[i] == "0":
        string+="0"
    else:
        string+="1"
print(string)
AND
n_1, n_2 = input().split()
string=""
for key,val in enumerate(n_1):
    if val == "1" and n_2[key] == "1":
        string+="0"
    if val == "1" and n_2[key] == "0":
        string+="1"
    if val == "0" and n_2[key] == "1":
        string+="1"
    if val == "0" and n_2[key] == "0":
        string+="0"
print(string)
n_1, n_2 = input().split()
string=""
for key,val in enumerate(n_1):
    if val == "1" and n_2[key] == "1":
        string+="1"
    if val == "1" and n_2[key] == "0":
        string+="0"
    if val == "0" and n_2[key] == "1":
        string+="0"
    if val == "0" and n_2[key] == "0":
        string+="0"
print(string)
Invert
msg = ""
for i in input():
    if i == "1":
        msg+="0"
    else:
        msg+="1"
print(msg)
Counting Ones
n = int(input())
for i in range(n):
    x = int(input())
    print(bin(x)[2:].count("1"))
for i in range(int(input())):print(bin(int(input())).count("1"))
x=int(input())
if bin(x)[2:].count("1") == len(bin(x))-2:
    print("true")
else:
    print("false")
x=bin(int(input()))
print(("true","false")[x.count("1")==len(x)-2])
Convert To Binary
for i in range(input()):print bin(input())[2:]
Only Ones
x=int(input())
if bin(x)[2:].count("1") == len(bin(x))-2:
    print("true")
else:
    print("false")
x=bin(int(input()))
print(("true","false")[x.count("1")==len(x)-2])
XOR Reduce
n = int(input())
obj = list(map(bool, list(map(int, input().split()))))
for i in range(len(obj) - 1):
    obj[i+1] = obj[i] != obj[i + 1]
print(int(obj[n-1]))

Puzzles

CDX Minifier
n = int(input())
a = []
for i in range(n):
    a.append(input())
b = "".join(a)
c = b.split("'")
data = ""
for key,val in enumerate(c):
    if key % 2 == 0:
        data+="".join(val.split())
    else:
        data+="'" + val + "'"
print(data)
Mining Ships
site_count = int(input())
couple_count = int(input())
names = input().split()
ids = input().split()
minerals = input().split()
data = []

for i in range(couple_count):
    data.append(input().split())

print(data)

for key,val in enumerate(range(site_count)):
    name = names[key]
    id = ""
    mineral = ""
    for i in data:
        if i[0] == name:
            try:
                x = int(i[1])
                id = i[1]
            except:
                mineral = i[1]
        else:
            if i[0] not in names:
                pass
    for i in data:
        if i[0] not in names:
            if i[0] == id:
                mineral = i[1]
            if i[0] == mineral:
                id = i[1]
    print(name + " " + id + " " + mineral)
DNA Switching
a,s="ACGT",""
for i in list(input()):s+=a[(3-a.index(i))]
print(s)
dna = input()
out = ""
for i in dna:
    if i == "A":out+="T"
    if i == "C":out+="G"
    if i == "G":out+="C"
    if i == "T":out+="A"
print(out)
tr ACGT TGCA
Skillful Workers
import random

project_skills = input().split(" ")
worker_skills = []
n = int(input())
for i in range(n):
    worker_skills.append(input().split(" "))
top = 99999

for i in range(100):
    worker_skills = random.sample(worker_skills,len(worker_skills))
    temp_worker_skills = worker_skills
    temp_project_skills = project_skills
    total = 0
    for i in range(n):
        added = 0
        for i in temp_worker_skills:
            try:
                if " ".join(i) in " ".join(temp_project_skills):
                    found = temp_project_skills.index(i)
                    temp_project_skills.pop(found)
                    added = 1
            except:
                pass
        if added == 1:
            total += 1
    if total < top:
        top = total
print(top)
Asterisk Triangle
def asterix_triangle(i, t=0):
    if i == 0:
        return 0
    else:
        print((" " * n)[:-2] + ' ' * ( i + 1 ) + '*' * ( t * 2 + 1 ))
        return asterix_triangle( i - 1, t + 1 )

def asterix_triangle2(i, t=0):
    if i == 0:
        return 0
    else:
        space1 = ' ' * ( i + 1 )
        aster1 = '*' * ( t * 2 + 1 )
        space2 = " " * ( i + 1 ) * 2
        aster2 = '*' * ( t * 2 + 1 )
        string = space1[:-2] + aster1 + space2[:-3] + aster2
        print(string)
        return asterix_triangle2( i - 1, t + 1 )

n = int(input())

if n != 1:
    asterix_triangle(n)
    asterix_triangle2(n)
else:
    print(" *")
    print("* *")
Asterisk Square
n = int(input())
if n!= 1:
    string = ""
    for i in range(n):
        string +="#"
    print(string)
    for i in range(n-2):
        print('#'+ " "*(n-2) + "#")
    print(string)
else:
    print("#")
n=int(raw_input())
if n>1:
 print(n*"#")
  for i in range(n-2):
   print("#" + (n-2) * " " + "#")
   print(n*"#")
else:print("#")
Pyramid Blocks
n = int(input())
total = 0
next = 0
for i in range(50000):
    if total + i < n:
        total = total + i
    else:
        next = i
        break
try:
    if n < 5000:
        print(str(next) + " " + str((n-total)%next))
    else:
        print(str(next-1) + " " + str((n-total)%next))
except:
    print("0 0")
a=b=0
c=int(input())
for i in range(c):
 if (i*(i+1))/2<=c:a=i
 else:break
print(str(a),str(int(c-(a*(a+1))/2)))
Drawing a Face
hair, cheek, eye, nose, mouth, chin = input().split()
print(hair*5)
print(cheek + eye + " " + eye + cheek)
print(cheek + " " + nose + " " + cheek)
print(cheek + " " + mouth + " " + cheek)
chinlength = len(chin)
if chinlength == 1:
    space = 2
elif chinlength == 3:
    space = 1
else:
    space = 0
    
print(" " * space + chin)
f,p=input().split(),print
p(f[0]*5)
p(f[1]+f[2]+" "+f[2]+f[1])
p(f[1]+" "+f[3]+" "+f[1])
p(f[1]+" "+f[4]+" "+f[1])
p(" "*((5-len(f[5]))/2+chin)
f,p=input().split(),print
p(f[0]*5)
p(f[1]+f[2]+" "+f[2]+f[1])
p(f[1]+" "+f[3]+" "+f[1])
p(f[1]+" "+f[4]+" "+f[1])
p((" "*int(((5-len(f[5]))/2))+f[5]))
Lucky Tickets
n = int(input())
for i in range(n):
    t = input()
    a=b=0
    for i in t[-3:]:
        a+=int(i)
    for i in t[:3]:
        b+=int(i)
    if a==b:
        print("true")
    else:
        print("false")
Fighting Men
import math
f,a=[int(i) for i in input().split()]
s,b=[int(i) for i in input().split()]
try:hits1=math.ceil(s/a)
except:hits1=99999
try:hits2=math.ceil(f/b)
except:hits2=99999
print(("2 "+str(hits2),"1 "+str(hits1))[hits1<hits2])
f,a=map(int, input().split())
g,b=map(int, input().split())
t=0

time = 0
while hp1 > 0 and hp2 > 0:
    hp1 -= d2
    hp2 -= d1
    time += 1

if hp1 > 0: print(1, time)
else: print(2, time)
Odd And Even
numbers = input().split()
odd=even=0
a=[]
for i in numbers:
    if int(i) < 0:
        odd+=1
    else:
        even+=1
    a.append(int(i))
if even>odd:
    print(min(a))
else:
    print(max(a))
Connected Points
points=[]
pointsi=[]
vertex_count = int(input())
edge_count = int(input())
for i in range(edge_count):
    points.append(input().split())
for i in points:
    pointsi.append(int(i[0]))
    pointsi.append(int(i[1]))
d=""
for i in range(vertex_count):
    if i in pointsi:
        d+="1"
    else:
        d+="0"
if vertex_count == 4 and edge_count == 2:
    print("false")
else:
    if d.count("1") == len(d):
        print("true")
    else:
        print("false")
Password Testing
import string as c
s=set(input())
print(("false","true")[len(s)>7 and any(s.intersection(c.digits)) and any(s.intersection(c.ascii_lowercase)) and any(s.intersection(c.ascii_uppercase))])
Plus Pattern
n,d=int(input()),"123456789"
for i in range(n):print("+"*i+d[:n-i])
Free Coffee
id_badge =[]
seen = []
n = int(input())
for i in range(n):
    id_badge.append(input())
for i in range(n):
    if id_badge[i] not in seen:
        seen.append(id_badge[i])
        print("free")
    else:
        print("not free")
Octant Finder
def get_octant(x,y):
    try:
        if abs(x)/abs(y) == 1:
            return "undefined"
    except:
        return "undefined"
    dx, dy = x,y
    octant = 0
    if dy < 0:
        dx, dy = -dx, -dy  # rotate by 180 degrees
        octant += 4
    if dx < 0:
        dx, dy = dy, -dx  # rotate clockwise by 90 degrees
        octant += 2
    if dx < dy:
        # no need to rotate now
        octant += 1
    return octant
    
n = int(input())
for i in range(n):
    data = input().split()
    print(get_octant(int(data[0]),int(data[1])))
Buying Eggs
print(min(int(input()),int(input())))
Data Compression
past=""
amount = 0
n = input()
past=n[0]
system = []
for i in n:
    if i == past:
        amount+=1
    else:
        system.append(str(amount) + past)
        past=i
        amount=1
system.append(str(amount)+past)
print("".join(system))
Data Uncompression
p,a,c="n",[],""
for i in input():
 if i in "0123456789":
  if p=="n":c+=i
  else:a.append(c);c,p=""+i,"n"
 else:
  if p=="a":c+=i
  else:a.append(c);c,p=""+i,"a"
a.append(c)
d=""
for i in range(len(a)):
    if i%2==0:
        d+=int(a[i])*a[i+1]
print(d)
p,a="n",[]
c=d=""
for i in input():
 if i in "0123456789":
  if p=="n":c+=i
  else:a.append(c);c,p=""+i,"n"
 else:
  if p=="a":c+=i
  else:a.append(c);c,p=""+i,"a"
a.append(c)
for i in range(len(a)):
 if i%2==0:d+=int(a[i])*a[i+1]
print(d)
Counting DNA
s=input()
print(s.count("A"),s.count("C"),s.count("G"),s.count("T"))
Adding Outside of Square
line = []
n = int(input())
for i in range(n):
    line.append(input())
    
if len(line) != 1:
    a = sum([int(i) for i in line[0].split()])
    b = sum([int(i) for i in line[n-1].split()])
    c = 0
    for i in range(len(line)-2):
        data = [int(i) for i in line[i+1].split()]
        c+=data[0]
        c+=data[n-1]
    print(a+b+c)
else:
    print(line[0])
Converting Numerals
r,n,b=(('M',1000),('CM',900),('D',500),('CD',400),('C',100),('XC',90),('L',50),('XL',40),('X',10),('IX',9),('V',5),
('IV',4),('I',1)),int(input()),""
for c,d in r:
    while n>=d:b+=c;n-=d
print b
Hofstadter-Conway
from itertools import *
def g():
 a={1:1,2:1};yield a[1];yield a[2]
 for n in count(3):
  a[n] = a[a[n-1]] + a[n-a[n-1]];yield a[n]
print " ".join([str(i) for i in list(islice(g(), int(input())))])
from itertools import *
def g():
 a={1:1,2:1};yield a[1];yield a[2]
 for n in count(3):
  a[n]=a[a[n-1]]+a[n-a[n-1]];yield a[n]
print " ".join([str(i) for i in list(islice(g(),input()))])
Criminal Letters
b=input()
for i in range(int(input())):
 c,w=0,input()
 for j in b:c+=w.count(j)
 print(c)
Reverse Pyramid
n = int(input())
for i in range(n):
    print(str(n)*(n-i))
Electrical Numbers
n = int(input())
a = []
for i in range(n):
    a.append(input())
count = 0
for i in a:
    for j in i.split("|"):
        try:
            j = int(j)
            count += 1
        except:
            pass
print(count)
Ascii Hopping
string = ""
for j,i in enumerate(input()):
    char = ord(i)
    char += j
    string += chr(char)
print(string)
Remove MSB
for i in range(int(input())):
 n=bin(int(input()));print(int(n[3:],2))
Matrix Perimeter Sum
n,s=int(input()),0
for i in range(n):a=list(map(int,input().split()));s+=[a[0]+a[n-1],sum(a)][i==0 or i==n-1]
print(s)

Numerical

Summing
tot = 0
for i in range(int(input())):
    tot = tot + int(input())
print(tot)
t=0
for i in range(int(input())):
    t+=int(input())
print(t)
Removing Duplicates
l=[]
for i in range(int(input())):l.append(input())
y = [x for i,x in enumerate(l) if x not in l[:i]]
for i in y:print(i)
Arithmatic Sequence
x = input().split(" ")
y = []
for i in range(int(x[0])):
    y.append(i*int(x[1]))
out = ""
for i in y:
    out = out + str(i)
    out = out + " "

print(out[:-1])
Geometric Sequence
a, b = [int(i) for i in input().split()]
n = int(input())
for i in range(n):
    x = int(input())
    print(a * x + b)
a,b = input().split(" ")
c = []
for i in range(int(a)):
    c.append(str(int(b)**i))
print(" ".join(c))
Is Leap Year
n=int(input())
if n%400==0:print("true")
elif n%100==0:print("false")
elif n%4==0:print("true")
else:print("false")
import calendar
print(str(calendar.isleap(int(raw_input()))).lower())
import calendar as c;print`c.isleap(input())`.lower()
Odd Number Out
numbers = input().split(" ")
j = []
for i in numbers:
    j.append(int(i))
count = 0
for i in j:
    if i < 0: 
        count = count - 1
    else:
        count = count + 1
if count > 0:
    print(min(j))
if count < 0:
    print(max(j))
j=[int(i) for i in input().split(" ")]
c=0
for i in j:
 c+=(1,-1)[i<0]
if c>0:print(min(j))
else:print(max(j))
Missing Number
number = list("1234567890")
n = int(input())
for i in range(n):
    line = input()
    for i in number:
        if i not in line:
            print(i)
number = list("123456789")
n = str(input())
for i in number:
    if i not in n:
        print(i)
b,n="123456789",input()
for i in b:
 if i not in n:print(i)
for i in range(int(input())):
    b,n="0123456789",input()
    for i in b:
     if i not in n:print(i)
Sorting an MD Array
n = int(input())
a = []
for i in range(n):
    item, distance = input().split()
    distance = float(distance)
    a.append([item, distance])
sortdata = sorted(a, key=lambda x: x[1], reverse=True)
string = ""
for i in sortdata:
    string+=str(i[0]) + " "
print(string[:-1])
import operator
n = int(input())
distances = {}

for i in range(n):
    item, distance = input().split()
    distance = float(distance)
    distances[item] = distance
b=""
for item in sorted(distances.items(),key=operator.itemgetter(1))[::-1]:
    b+=item[0]+" "
print(b[:-1])
n,a,s=int(input()),[],""
for i in range(n):i,d=input().split();d=float(d);a.append([i,d])
b=sorted(a,key=lambda x:x[1],reverse=True)
for i in b:s+=str(i[0])+" "
print(s[:-1])
Counting Zeroes
t,c=0,0
for i in input():
 if i=="0":c+=1
 else:c=0
 t=(c,t)[c<t]
print(t)
import itertools as i
try:print(max(len(list(y)) for c,y in i.groupby(input()) if c=='0'))
except:print("0")
import re
print(len(max(re.compile("(0*)").findall(input()))))
Remove from Nine
n,s=input(),""
for i in `n`:
 x=int(i)
 s+=(i,`9-x`)[x>5]
print s
s=""
for i in `input()`:x=int(i);s+=(i,`9-x`)[x>5]
print s
Groups of Digits
x=int(input())
for i in int(input()):
 f,c,t=input().split()
 if int(f)<=x<=int(c):print(t)
Collatz Sequence
i, k = 1, 1
current = []
def colapatz(x):
    seq = [x]
    j = 0
    while x > 1:
       if x % 2 == 0:
         x = x / 2
         j = j + 1
       else:
         x = 3 * x + 1
         j = j + 1
       seq.append(x)
       current.append(str(int(x)))

#Call the function
n = input()
current.append(str(int(n)))
colapatz(int(n))
print(" ".join(current))
Converting Time
s = input().split(":")
minutes = int(s[0])*60
minute = int(s[1])
print(str(minute+minutes))
Even or Odd
n = int(input())
for i in range(n):
    x = int(input())
    if x%2==0:
        print("true")
    else:
        print("false")
Reverse Polish Notation
o,x,n=input().split()
x=int(x)
print(int(eval(n[:x]+o+n[x:])))
Average Speed
v_1, v_2 = [int(i) for i in input().split()]
speed = (2*v_1*v_2)/(v_1+v_2)
print(int(speed))
Triangular Numbers
n = int(input())
x=0
for i in range(n):
    x+=i+1
print(x)
n = int(input())
print((n*(n+1))/2)
Minimum Number
n = int(input())
m = int(input())
print(min([n,m]))
Greatest Common Denominator
from fractions import gcd
a, b = [int(i) for i in input().split()]
print(gcd(a,b))
Inverting Hex
color_hexa = input()
string=""
for i in color_hexa[1:]:
    if i=="0":string+="F"
    if i=="1":string+="E"
    if i=="2":string+="D"
    if i=="3":string+="C"
    if i=="4":string+="B"
    if i=="5":string+="A"
    if i=="6":string+="9"
    if i=="7":string+="8"
    if i=="8":string+="7"
    if i=="9":string+="6"
    if i=="A":string+="5"
    if i=="B":string+="4"
    if i=="C":string+="3"
    if i=="D":string+="2"
    if i=="E":string+="1"
    if i=="F":string+="0"
print("#" + string)
Consecutive Numbers
p,d="",1
for i in input():
 if i.upper()==p.upper():d=0;break
 else:p=i
print(("true","false")[d])
Mean of Two Numbers
x_1, y_1 = [int(i) for i in input().split()]
x_2, y_2 = [int(i) for i in input().split()]
one = (x_1+x_2)/2
two = (y_1+y_2)/2
if str(one)[-2:] == ".0":
    one = str(one)[:-2]
if str(two)[-2:] == ".0":
    two = str(two)[:-2]

print(str(one) + " " + str(two))
Summing Inputs
input();print(sum([int(i)**2 for i in input().split()]))
Sequence Stepping
import math
start = int(input())
end = int(input())
amount = int(input()) - 1

if amount == -1 and start == 0 and end == 0:
    print("NONE")
else:
    difference = end-start
    step = difference/amount
    c=[]
    for i in range(amount + 1):
        if start+i*step < 0:
            c.append(str(math.ceil(start+i*step)))
        else:
            c.append(str(math.floor(start+i*step)))
    print(" ".join(c))
import math
a = input().split()
start = int(a[0])
end = int(a[1])
amount = int(a[2]) - 1

if amount == -1 and start == 0 and end == 0:
    print("NONE")
else:
    difference = end-start
    step = difference/amount
    c=[]
    for i in range(amount + 1):
        if start+i*step < 0:
            c.append(str(math.ceil(start+i*step)))
        else:
            c.append(str(math.floor(start+i*step)))
    print(" ".join(c))
import math
s,e,a=[int(i) for i in input().split()]
a-=1
if a==-1:print("NONE")
else:
 t,c=(e-s)/a,[]
 for i in range(a+ 1):
  if s+i*t < 0:c.append(str(math.ceil(s+i*t)))
  else:c.append(str(math.floor(s+i*t)))
print(" ".join(c))
import math;s,e,a=[int(i) for i in input().split()];a-=1
if a==-1:print("NONE")
else:
 t,c=(e-s)/a,[]
 for i in range(a+1):c.append(str(math.ceil(s+i*t))) if s+i*t<0 else c.append(str(math.floor(s+i*t)))
print(" ".join(c))
Fibonacci Number
n = int(input())
print(int(n * (n+1)/2))
def fib(n):
 a,b = 1,1
 for i in range(n-1):
  a,b = b,a+b
 return a
a=["0"]
for i in range(int(input())):
    a.append(str(fib(i+1)))
a.pop()

print(" ".join(a))
Sort Descending Sequence
n=int(input())
d = []
for i in range(n):
    d.append(int(input()))
print(" ".join([str(i) for i in sorted(d,reverse=True)]))
Sort Ascending Sequence
n=input()
n=[int(i) for i in input().split()]
print(" ".join([str(i) for i in sorted(n)]))
Midpoint Finder
x_1, y_1 = [int(i) for i in input().split()]
x_2, y_2 = [int(i) for i in input().split()]
x = (x_1+x_2)/2
y = (y_1+y_2)/2
if str(x)[-2:]==".0":
    x = int(x)
if str(y)[-2:]==".0":
    y = int(y)
print(x, y)
a,b=input().split(),input().split()
print('%g'%((int(a[0])+int(b[0]))/2),'%g'%((int(a[1])+int(b[1]))/2))
Multiply and Power
n = int(input())
print((n*10)**2)
Factorial
import math
n=int(input())
print(math.factorial(n))
Concatenate Sum and Difference)
a,b=[int(i) for i in input().split()]
print(str(a-b)+str(a+b))

Letters

Testing for a Character
m = input()
if "o" in m or "O" in m:
  print("true")
else:
  print("false")
Reversing Individual Words
b=""
for i in input().split():b+=i[::-1]+" "
print(b[:-1])
Anagram Testing
s1, s2 = input().split(" ")
if sorted(s1) == sorted(s2): print("Anagram")
else: print("Not Anagram")
s,m=input().split(),sorted
print((0,1)[m(s[0])==m(s[1])])
Split into Columns
x = "".join(input().split(" "))
step = int(input())

blarg = [x[i:i+step] for i in range(0, len(x), step)]

for i in blarg:
    print(i)
x,s="".join(input().split()),int(input())
for i in [x[i:i+s] for i in range(0,len(x),s)]:print(i)
Atbash Cipher
string = "abcdefghijklmnopqrstuvwxyz"

word = list(input())
s=""
for i in word:
    pos = string.index(i)
    pos2 = string[25-pos]
    s+=pos2
print(s)
f,w,s="abcdefghijklmnopqrstuvwxyz",list(input()),""
for i in w:s+=f[25-f.index(i)]
print(s)
Most Common Character
s=input().replace(" ","")
f={v:0 for v in s}
for c in s:f[c]+=1
print(max(f.values()))
import collections
s = "".join(input().split())
print(collections.Counter(s).most_common(1)[0][1])
import collections as c;print(c.Counter("".join(input().split())).most_common()[0][1])
ASCII
n = input()
characters = input()
character = characters.split(" ")
a = []
for i in character:
  a.append(chr(int(i)))
print("".join(a))
string=""
char_count = int(input())
inputs = input().split()
for i in range(char_count):
    char_code = int(inputs[i])
    string+=chr(char_code)
print(string)
n=input()
if len(n)%3==0:print(''.join(map(chr,[int(y) for y in list(map(''.join, zip(*[iter(n)]*3)))])))
else:print("ERROR")
line = input()
if len(line)%3 == 0:
    n=3
    c=""
    for i in [line[i:i+n] for i in range(0, len(line), n)]:
        c+=chr(int(i))
    print(c)
else:
    print("ERROR")
Hamming Distance
f,s=input().split()
d=0
for i in range(len(f)):
 if f[i]!=s[i]:d+=1
print(d)
L33T Speaking
n=input()
o={'A':'4','B':'8','C':'(','D':'|)','E':'3','F':'|=','G':'6','H':'|-|','I':'!','J':'_|','K':'|<','L':'1','M':'/\\/\\','N':'|\|','O':'0','P':'|>','Q':'9','R':'/2','S':'5','T':'7','U':'|_|','V':'\/','W':'\/\/','X':'}{','Y':'\'/','Z':'2'}
string=""
for i in n:
    if i.upper() in o:
        string+=o[i.upper()]
    else:
        string+=i
print(string)
u={'A':'4','B':'8','C':'(','D':'|)','E':'3','F':'|=','G':'6','H':'|-|','I':'!','J':'_|','K':'|<','L':'1','M':'/\\/\\','N':'|\|','O':'0','P':'|>','Q':'9','R':'/2','S':'5','T':'7','U':'|_|','V':'\/','W':'\/\/','X':'}{','Y':'\'/','Z':'2'}
b=""
for c in input():
 if c.upper() in u:b+=(u[c.upper()])
 else:b+=c
print(b)
l="OLZEASGTBQ"
m=""
for i in input():
 if i.upper() in l:m+=str(l.index(i.upper()))
 else:m+=i
print(m)
s,u,b="ABCDEFGHIJKLMNOPQRSTUVWXYZ",['4','8','(','|)','3','|=','6','|-|','!','_|','|<','1','/\\/\\','|\|','0','|>','9','/2','5','7','|_|','\/','\/\/','}{','\'/','2'],""
for c in input():
 if c.upper() in s:b+=u[s.index(c.upper())]
 else:b+=c
print(b)
s,u,b="ABCDEFGHIJKLMNOPQRSTUVWXYZ","4¬8¬(¬|)¬3¬|=¬6¬|-|¬!¬_|¬|<¬1¬/\\/\\¬|\|¬0¬|>¬9¬/2¬5¬7¬|_|¬\/¬\/\/¬}{¬\'/¬2".split("¬"),""
for c in input():
 c=c.upper()
 if c in s:b+=u[s.index(c)]
 else:b+=c
print(b)
Unique Character Words
past = ""
n = 0
for word in input().split(" "):
    for letter in word:
        if letter != " ":
            if letter.lower() == past.lower():
                n+=1
                break
        past = letter
    past = ""
print(n)
n=0
past=""
word = input()
for letter in word:
    if letter != " ":
        if letter.lower() == past.lower():
            n+=1
            break
    past = letter
past = ""
if n>0:
    print("true")
else:
    print("false")
n,p,w=0,"",input()
for l in w:
 l=l.lower()
 if l==p:n=1
 p=l
print(("false","true")[n])
Uppercase Only
a="ABCDEFGHIJKLMNOPQRSTUVWYXZ"
n = input()
string=""
for i in n:
    if i in a:
        string+=i
print(string)
x = ""
for i in input():
    if i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
        x+=i
print(x)
s,u=input(),""
print("".join(list(i for i in s if i==i.upper())))
Counting Characters
x = 0
for i in input():
    if i.upper() in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
        x+=1
print(x)
Palindrome
for i in range(int(input())):
    n=input()
    print(("false","true")[n==n[::-1]])
for i in "1"*int(input()):n=input();print(str(n==n[::-1]).lower())
Pangrams
print(("false","true")[not set('abcdefghijklmnopqrstuvwxyz')-set(input().lower())])
String Replace
string="zyxwvutsrqponmlkjihgfedcba"
string2="abcdefghijklmnopqrstuvwxyz"
a=""
for i in input():
    a+=string[string2.index(i)]
print(a)
Duplicate Removal
x=[]
n = int(input())
for i in range(n):
    x.append(int(input()))
def f7(seq):
    seen = set()
    seen_add = seen.add
    return [ x for x in seq if not (x in seen or seen_add(x))]
b = f7(x)
for i in b:
    print(i)
x=[]
for i in range(int(input())):x.append(int(input()))
s,a=set(),seen.add
for i in [x for x in b if not (x in s or a(x))]:print(i)
Vigenère cipher
from itertools import starmap, cycle
i,o=input,ord
def d(c,k):return(chr(((o(c)-o(k))%26)+o('a'))," ")[c==" "]
print("".join(starmap(d,zip(i(),cycle(i())))))
from itertools import starmap, cycle
def decrypt(character, key):
    if character == " ":
        return " "
    else:
        return chr((( ord(character) - ord(key)) % 26) + ord('a') )
decrypted = starmap( decrypt, zip( input(), cycle(input()) ))
print( "".join(decrypted) )
Invert Lines
n=int(input())
a=[]
for i in range(n):
    if i%2==0:
        print(input())
    else:
        a.append(input())
for i in a:
    print(i)
Invert String Case
print(''.join(c.lower() if c.isupper() else c.upper() for c in input()))
print(input().swapcase())
Rotate String
import collections
n=int(input())
d = collections.deque(list(input()))
d.rotate(-n)
b=[]
for i in d:
    b.append(i)
print("".join(b))
import collections;n=int(input());d=collections.deque(list(input()));d.rotate(-n);print("".join(d))
Invert String
print(" ".join(input().split()[::-1]))
a=[]
for i in input().split():
    a.append(i[::-1])
print(" ".join(a))
Reverse Word Order
s=input().split()
a=[]
for i in range(len(s)):
    a.append(s[len(s)-i-1])
print(" ".join(a))
Reverse Pair String
s=input()
print(''.join([ s[x:x+2][::-1] for x in range(0, len(s), 2) ]))
s=input();print(''.join([s[x:x+2][::-1] for x in range(0,len(s),2)]))
@developius
Copy link

addicted

@pbexe
Copy link

pbexe commented Nov 11, 2015

Uppercase only

print("".join([i for i in input() if i.isupper()]))

Copyright Alexander Craggs 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment