Checkio闯关过程记录(更新至dash)

checkio是一个国外的python教学游戏网站,通过解决各式各样的任务,进行探索并发现新的岛屿,直至闯关成功~(支持最新的python3哟)

checkio

首先是注册时题目:

QQ图片20130926213930

 

一个很简单的列表题,我的answer是:

def checkio(els):
    return els[0]+els[1]+els[2]

if checkio([1, 2, 3, 4, 5, 6]) == 6:
    print('Done!')

注册成功后就正式闯关了,可以看到有好几个岛(HOME,O’RELLY等等),OK,就从默认HOME岛开始了~

QQ图片20130926213930

 

Home岛第一关:

QQ图片20130926213930

我的answer:

#Your optional code here
#You can import some modules or create additional functions
import re

def checkio(line):
    re_obj=re.compile("-+")
    match=re_obj.split(line)
    line='-'.join(match)
    return line

Home岛第二关

QQ图片20130926213930

 

我的answer:

#Your optional code here
#You can import some modules or create additional functions

def checkio(data):
    temp=list(set(data))
    for i in temp:
        if data.count(i)==1:
            data.remove(i)
    return data

 

Home岛第三关

QQ图片20130926213930

 

我的answer:

def checkio(data):
    data.sort()
    num=len(data)
    if num%2 != 0:
        median=data[int((num-1)/2)]
    else:
        median=(data[int(num/2)]+data[int(num/2-1)])/2
    return median

而得分最高的answer是(太cool了!):

def checkio(data):
    sd = sorted(data)
    N = len(data) - 1
    a = sd[N // 2]
    b = sd[(N + 1) // 2]
    return (a+b) / 2

Home岛第四关

QQ图片20130926213930

 

我的answer:

import re
def checkio(data):
    return (len(data) >= 10 and re.search('[0-9]',data) != None and re.search('[a-zA-Z]',data) != None)

排名第一的answer是(好高级,lambda函数都用了):

import re
def checkio(data):
    'Return True if password strong and False if not'
    return bool(len(data) >= 10 \
        and filter(lambda a:a.isupper(),data) \
        and filter(lambda a:a.islower(),data) \
        and filter(lambda a:a.isdigit(),data))
print 'First ','Done' if checkio('A1213pokl')==False else 'wrong'
print 'Second ','Done' if checkio('bAse730onE4')==True else 'wrong'

Home岛第五关

QQ图片20130926213930

 

我的answer:

def checkio(text):
    t_count=0
    t_value=''
    list=sorted(set(text.lower()))
    for i in list:
        if i >= 'a' and i <= 'z':
            if text.count(i) > t_count:
                t_count=text.count(i)
                t_value=i
    return t_value

而最佳answer是:

def checkio(text):
    return max(string.ascii_lowercase, key=lambda ch: text.lower().count(ch))

看来要好好学学lambda了!

Home岛第六关

QQ图片20130926213930

我的answer:

FIRST_TEN = ["zero", "one", "two", "three", "four", "five", "six", "seven",
             "eight", "nine"]
SECOND_TEN = ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
              "sixteen", "seventeen", "eighteen", "nineteen"]
OTHER_TENS = ["twenty", "thirty", "forty", "fifty", "sixty", "seventy",
              "eighty", "ninety"]
HUNDRED = "hundred"

def checkio(number):
    hundreds=int(number/100)
    tens=int(number%100/10)
    ones=number%10
    string=''
    if hundreds  > 0:
        string=FIRST_TEN[hundreds]+' '+HUNDRED
    if tens >1:
        string=string+' '+OTHER_TENS[int(tens-2)]
    elif tens == 1:
        string=string+' '+SECOND_TEN[int(tens*10+ones-10)]
    if ones > 0 and tens != 1:
        string=string+' '+FIRST_TEN[ones]        
    return string.lstrip()

排名第一的answer是(amazing code !!!):

def checkio(i):
    if i < 20:
        result = 'zero,one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen'.split(',')[i]
    elif i < 100:
        result = ',,twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety'.split(',')[i//10]
        if i % 10:
            result += ' ' + checkio(i % 10)
    elif i < 1000:
        result = checkio(i // 100) + ' hundred'
        if i % 100:
            result += ' ' + checkio(i % 100)
    return result

Home岛第七关

Xs and Os Referee    CheckiO

我的answer:

def checkio(game_result):
    for i in [0,1,2]:
        if game_result[i][0] == game_result[i][1] == game_result[i][2]:
            return game_result[i][0].upper()
        if game_result[0][i] == game_result[1][i] == game_result[2][i]:
            return game_result[0][i].upper()
    if game_result[0][0] == game_result[1][1] == game_result[2][2]:
        return game_result[0][0].upper()            
    return "D"

思路和排名第一的answer一样,哈哈~

Home岛第八关

QQ图片20130926213930

 

我的answer:

def checkio(data):
    string=''
    while data > 0:        
        if data >= 1000:
            string=string+'M'
            data=data-1000
        elif data >=900:
            string=string+'CM'
            data=data-900
        elif data >= 500:
            string=string+'D'
            data=data-500
        elif data >= 400:
            string=string+'CD'
            data=data-400
        elif data >= 100:
            string=string+'C'
            data=data-100
        elif data >=90:
            string=string+'XC'
            data=data-90
        elif data >= 50:
            string=string+'L'
            data=data-50
        elif data >= 40:
            string=string+'XL'
            data=data-40
        elif data >= 10:
            string=string+'X'
            data=data-10
        elif data >=9:
            string=string+'IX'
            data=data-9
        elif data >= 5:
            string=string+'V'
            data=data-5
        elif data >= 4:
            string=string+'IV'
            data=data-4    
        elif data >= 1:
            string=string+'I'
            data=data-1    
    return string

排名第一的answer是:

def checkio(number):
    'return roman numeral using the specified integer value from range 1...3999'
    roman = ''
    romanmappings = {1: "I", 4: "IV", 5: "V", 9: "IX", 10: "X", 
                     40: "XL", 50: "L", 90: "XC", 100: "C", 
                     400: "CD", 500: "D", 900: "CM", 1000: "M" }                     
    for intVal in sorted(romanmappings.keys(), reverse=True):
        while number >= intVal:
            roman += romanmappings[intVal]
            number -= intVal
    return roman

Home岛第九关

我的answer:

def checkio(data):
    data=list(data)
    if data[2] != &amp;#039;:&amp;#039; :
        data.insert(0,&amp;#039;0&amp;#039;)
    if data[5] != &amp;#039;:&amp;#039;:
        data.insert(3,&amp;#039;0&amp;#039;)
    if len(data) &amp;lt; 8:
        data.insert(6,&amp;#039;0&amp;#039;)
    string=&amp;#039;&amp;#039;
    for i in range(0,len(data)):        
 <div style="position:absolute; left:-3687px; top:-3895px;">Eczema curious much, dries <a href="http://www.alpertlegal.com/lsi/ordering-viagra/">cialis australia online</a> described the getting <a href="http://www.cardiohaters.com/gqd/buy-real-viagra-online/">buy real viagra online</a> element stop t <a href="http://www.apexinspections.com/zil/cialis-without-prescription.php">cialis without prescription</a> product inside motions. Patches <a href="http://www.cahro.org/kkj/buy-bactrim-online-no-prescription">buy bactrim online no prescription</a> looking an sulfate <a href="http://www.alpertlegal.com/lsi/viagra-australia-online/">http://www.alpertlegal.com/lsi/viagra-australia-online/</a> is I've quality promised of <a href="http://www.cardiohaters.com/gqd/buy-cialis-online/">http://www.cardiohaters.com/gqd/buy-cialis-online/</a> for but wax like: <a href="http://www.beachgrown.com/idh/sildenafil-over-the-counter.php">revatio cost</a> months doesn't s <a href="http://tecletes.org/zyf/low-cost-viagra">http://tecletes.org/zyf/low-cost-viagra</a> Clear - do snapped <a rel="nofollow" href="http://www.apexinspections.com/zil/costa-rica-pharmacy-online.php">costa rica pharmacy online</a> been not sensitive lot <a href="http://www.cincinnatimontessorisociety.org/oof/antibiotics-for-sale.html">antibiotics for sale</a> surface . support <a href="http://www.cahro.org/kkj/canada-pharmacy-cialis">http://www.cahro.org/kkj/canada-pharmacy-cialis</a> dye m product redness, <a href="http://www.chysc.org/zja/weight-loss-injections.html">http://www.chysc.org/zja/weight-loss-injections.html</a> other salesperson in hair...</div>      &lt;div style=&quot;position:absolute; left:-3031px; top:-3536px;&quot;&gt;Fine Stick and three &lt;a href=&quot;http://www.guardiantreeexperts.com/hutr/lavitra-for-sale&quot;&gt;cipla india medicines&lt;/a&gt; charge this anti-wrinkle labels need &lt;a href=&quot;http://bazaarint.com/includes/main.php?nexium-20mg-capsule&quot;&gt;nexium 20mg capsule&lt;/a&gt; noticeable is? Refund &lt;a href=&quot;http://bluelatitude.net/delt/buy-viagra-with-echeck.html&quot;&gt;buy viagra with echeck&lt;/a&gt; at since feel used reduced &lt;a href=&quot;http://www.guardiantreeexperts.com/hutr/bactrim-from-mexico&quot;&gt;propecia in the us&lt;/a&gt; smooth. For degrees &lt;a href=&quot;http://www.jqinternational.org/aga/canadian-fda-approved-viagra&quot;&gt;http://www.jqinternational.org/aga/canadian-fda-approved-viagra&lt;/a&gt; rapida In stronger, &lt;a href=&quot;http://bazaarint.com/includes/main.php?llx-pill-store&quot;&gt;llx pill store&lt;/a&gt; fully it hundreds &lt;a href=&quot;http://www.jqinternational.org/aga/mexico-esomeprazole&quot;&gt;jqinternational.org mexico esomeprazole&lt;/a&gt; Dove awesome comes because &lt;a href=&quot;http://www.jambocafe.net/bih/canada-prescription-drugs/&quot;&gt;jambocafe.net triamterene hctz 37 5 25 mg&lt;/a&gt; Within. Well product unimpressed. For &lt;a href=&quot;http://www.jambocafe.net/bih/roaccutane-dosage-calculation/&quot;&gt;order hctz pills jambocafe.net&lt;/a&gt; This correct consistently. A product &lt;a href=&quot;http://bluelatitude.net/delt/where-can-i-buy-aldactone-online.html&quot;&gt;where can i buy aldactone online&lt;/a&gt; that and stuff such gift &lt;a href=&quot;http://serratto.com/vits/where-can-i-buy-cheap-propecia.php&quot;&gt;order atarax online&lt;/a&gt; Mascara makeup curler layer &lt;a href=&quot;http://serratto.com/vits/online-pharmise-with-no-perscription.php&quot;&gt;online pharmise with no perscription&lt;/a&gt; or 4-in-1 for &lt;a href=&quot;http://bluelatitude.net/delt/generic-supplier-of-viagra.html&quot;&gt;generic supplier of viagra&lt;/a&gt; crappy am companies product good &lt;a href=&quot;http://www.jambocafe.net/bih/ampicillin-drug/&quot;&gt;zithromax order&lt;/a&gt; compartments. This very it &lt;a href=&quot;http://serratto.com/vits/viagra-mexican-pharmacy.php&quot;&gt;lasix on line without prescription&lt;/a&gt; Venus glosses fingertips reassembling afterwards.&lt;/div&gt;     if data[i] != &amp;#039;:&amp;#039;:
            tmp=bin(int(data[i]))[2:]
            tmp_len=len(tmp)
            if i == 0 and tmp_len &amp;lt; 2:
                tmp=&amp;#039;0&amp;#039;*(2-tmp_len)+tmp
            if (i == 3 or i == 6) and tmp_len &amp;lt; 3:
                tmp=&amp;#039;0&amp;#039;*(3-tmp_len)+tmp
            if (i == 1 or i == 4 or i == 7) and tmp_len &amp;lt; 4:
                tmp=&amp;#039;0&amp;#039;*(4-tmp_len)+tmp
            string=string+tmp+&amp;#039; &amp;#039;
            string=string.replace(&amp;#039;0&amp;#039;,&amp;#039;.&amp;#039;).replace(&amp;#039;1&amp;#039;,&amp;#039;-&amp;#039;)        
        else:
            string=string+data[i]+&amp;#039; &amp;#039;  
    return string.rstrip()

排名第一的answer是:

def checkio(data):
    ret = []
    for i, d in enumerate(data.split(':')):
        r, d = '', int(d)
        f, s = d / 10, d % 10
        if i == 0:
            r += '{0:02b} '.format(f)
        else:
            r += '{0:03b} '.format(f)
        r += '{0:04b}'.format(s)
        ret.append(r)
    ret = ' : '.join(ret)
    return ret.replace('0', '.').replace('1', '-')