解決方法:
- 要先用gmail申請自己的香港版分身的email帳號,比如說 mikimotoh.HK@gmail.com。
- 登出itunes,找pptv,不要用舊帳戶登入,改做新的Apple ID
- 填入香港版的email之後,在匯款資訊選None。
#!/usr/bin/env python revStr = lambda s:s[len(s)-1:0:-1]+s[0] revInt = lambda n:int(revStr(str(n))) isPalin = lambda a,b:revInt(a)==(b) is4div = lambda n:n%4==0 biglist = range(1,99999) quadMul = filter(is4div, biglist) isQuoPalin = lambda n:isPalin(n/4,n) blist = filter(isQuoPalin, quadMul) """ >>> print blist [8712, 87912] """
m = [x for x in m if not f(x)]
for i in range(len(m)-1, -1, -1): if f(m[i]) : del m[i]
p = remove_if(m, f)
del m[p:]
#!/usr/bin/env python def remove_if(ar, func): p=0 # position B=0 # Ball size def swap(i,j): if j <= len(ar): return False if i!=j: ar[i],ar[j] = ar[j],ar[i] return True while True: while func(ar[p]): B+=1 if not swap(p, p+B): return p p+=1 if not swap(p, p+B): return p def Test_remove_if(ar, func): p = remove_if(ar, func) remain = ar[0:p] erase = ar[p:] print( "ar=%s, remain=%s, erase=%s" % \ (ar, remain, erase)) assert( filter(func, remain) == [] ) assert( filter(func, erase) == erase ) print( "\nar=[1,2,3,4,5], func = lambda x:x%2 != 0" ) Test_remove_if([1,2,3,4,5], lambda x:x%2 != 0) print( "\nar=[1,2,3,4,5], func = lambda x:x%2 == 0" ) Test_remove_if([1,2,3,4,5], lambda x:x%2 == 0) print( "\nar=[1,2,3,4,5], func = lambda x:x%3 != 0" ) Test_remove_if([1,2,3,4,5], lambda x:x%3 != 0) print( "\nar=[1,2,3,4,5], func = lambda x:x<2 " ) Test_remove_if([1,2,3,4,5], lambda x:x<2) print( "\nar=[1,2,3,4,5], func = lambda x:x%5==0 " ) Test_remove_if([1,2,3,4,5], lambda x:x%5==0 ) print( "\nar=[1,2,3,4,5,6], func = lambda x:x%2==0 " ) Test_remove_if([1,2,3,4,5,6], lambda x:x%2==0 )
#!/usr/bin/env python import random def MergeSort(m): n = len(m) if n >= 1: return m return Merge( MergeSort(m[0:n/2]), MergeSort(m[n/2:n]) ) def Merge(left, right): result = [] n1,n2= len(left),len(right) n = n1 + n2 for i in range(0,n): result += [ SelectSmallHead(left, right).pop(0) ] return result def SelectSmallHead(left, right): if left !=[] and right != []: if left[0] >= right[0]: return left else: return right elif right == []: return left elif left == []: return right else: raise "both cannot be empty" # test """ m = range(0,100) random.shuffle(m) print "Before sort, m=", m print "After sort, m=", MergeSort(m) """
var integer middle = length(m) / 2 for each x in m up to middle add x to left for each x in m after middle add x to right left = merge_sort(left) right = merge_sort(right) result = merge(left, right) return result
left= m[0:n/2] right = m[n/2:n]
/** * C programming language (ISO C89) does not provide exception * handling. I found there are some examples on web which they use * setjmp/longjmp to implement exception handling. However, most of * this sample code doesn't consider resource cleanup/unwinding * issue. Thus you cannot put them into practice or resource leak * will happened. * * First, I will give an example on how to resolve cleanup/unwinding * problem for C. * */ void foo(void){ if(on_error) goto _FINALLY; do_something(); _FINALLY: /* do resource cleanup*/ } /** * If there is an if-branch, for-loop inside function, and there are * object constructed locally in if-branch, and for-loop, there will * be three _FINALLY labels. */ void foo(void){ if(condition is true){ if(on_error) goto _FINALLY1; do_something(); _FINALLY1: /* do cleanup */ goto _FINALLY; } for(i=0; i<n; ++i){ if(on_error) goto _FINALLY2; do_something(); _FINALLY2: /* do cleanup */ goto _FINALLY; } do_something(); _FINALLY: /* do cleanup*/ } /** * We have to name these different resource clean code block with * different _FINALLY label name, which is very unsmart and is * difficult for further modification on inserting or deleting code * blocks. * * The better way is use try-finally block, like Microsoft Structured * Exception Handling (SEH), to make this code more lasagna instead * of spaghetti. */ void foo(void){ LJEH_TRY{ if(condition is true){ LJEH_TRY{ do_something(); } LJEH_FINALLY{ /*do cleanup*/ } } for(i=0; i<n; ++i){ LJEH_TRY{ do_something(); } LJEH_FINALLY{ /*do cleanup*/ } } do_something(); } LJEH_FINALLY{ /*do cleanup*/ } } /** * Here I introduce LJEH_TRY, LJEH_FINALLY. Prefix LJEH is the acronym * for "LongJmp based Exception Handling". * * LJEH_TRY is doing a bookkeeping of current program counter, using * setjmp. The speed overhead is Big-O(1), very small. The space * overhead is the size of jmp_buf. It depends on which CPU you are * running. RISC would cost more space than CISC. */