addBaseMinus2 [] [] 0 = []
addBaseMinus2 [0] [0] 0 = [0]
addBaseMinus2 [] ys carry_in = addBaseMinus2 [0] ys carry_in
addBaseMinus2 xs [] carry_in = addBaseMinus2 xs [0] carry_in
addBaseMinus2 (x:xs) (y:ys) carry_in = oneDigitSum : (addBaseMinus2 xs ys (-carryOut)) where
(carryOut, oneDigitSum) = (x + y + carry_in) `divMod` 2
ceilOfHalf [] = []
ceilOfHalf xs = reverse . dropWhile (== 0) . reverse $ addBaseMinus2 xs (tail xs) 0
sh-3.2$ ghci q.hs
GHCi, version 8.4.2: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /Users/code4food/.ghci
[1 of 1] Compiling Main ( q.hs, interpreted )
Ok, one module loaded.
*Main> ceilOfHalf []
[]
*Main> ceilOfHalf [1,0,0,1,1]
[1,0,1]
*Main> ceilOfHalf [1,0,0,1,1,1]
[1,0,1,0,1,1]
*Main>
想俾日本妹sm<img src="/assets/faces/lm2/jable.gif" class="hkgmoji" /> <img src="/assets/faces/lm2/jable.gif" class="hkgmoji" /> <img src="/assets/faces/lm2/jable.gif" class="hkgmoji" />做Support都做到咁風騷係server房同人妻扑野 <img src="/assets/faces/dog/lick.gif" class="hkgmoji" /> <img src="/assets/faces/dog/lick.gif" class="hkgmoji" /> <img src="/assets/faces/dog/lick.gif" class="hkgmoji" /><img src="/assets/faces/lm2/diu.gif" class="hkgmoji" /> <img src="/assets/faces/lm2/diu.gif" class="hkgmoji" />
做programmer搵兩倍人工無人吼<img src="/assets/faces/normal/frown.gif" class="hkgmoji" />
addBaseMinus2 [] [] 0 = []
addBaseMinus2 [0] [0] 0 = [0]
addBaseMinus2 [] ys carry_in = addBaseMinus2 [0] ys carry_in
addBaseMinus2 xs [] carry_in = addBaseMinus2 xs [0] carry_in
addBaseMinus2 (x:xs) (y:ys) carry_in = oneDigitSum : (addBaseMinus2 xs ys (-carryOut)) where
(carryOut, oneDigitSum) = (x + y + carry_in) `divMod` 2
stripTrailingZeros [] = []
stripTrailingZeros (x:xs) = x : (reverse . dropWhile (== 0) $ reverse xs)
ceilOfHalf [] = []
ceilOfHalf xs = stripTrailingZeros $ addBaseMinus2 xs (tail xs) 0
GHCi, version 8.4.2: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /Users/code4food/.ghci
[1 of 1] Compiling Main ( q.hs, interpreted )
Ok, one module loaded.
*Main> ceilOfHalf [1,0,0,1,1]
[1,0,1]
*Main> ceilOfHalf [1,0,0,1,1,1]
[1,0,1,0,1,1]
*Main> ceilOfHalf [1,1]
[0]
*Main>
addBaseMinus2 [] [] 0 = [0]
addBaseMinus2 [] ys carry_in = addBaseMinus2 [0] ys carry_in
addBaseMinus2 xs [] carry_in = addBaseMinus2 xs [0] carry_in
addBaseMinus2 (x:xs) (y:ys) carry_in = oneDigitSum : (addBaseMinus2 xs ys (-carryOut)) where
(carryOut, oneDigitSum) = (x + y + carry_in) `divMod` 2
stripTrailingZeros [] = []
stripTrailingZeros (x:xs) = x : (reverse . dropWhile (== 0) $ reverse xs)
ceilOfHalf [] = []
ceilOfHalf xs = stripTrailingZeros $ addBaseMinus2 xs (tail xs) 0
print(
"!".join([
"Hong Kong no IT" if x % 2 is 0
else "一齊寫爛 code"
for x in range(9999)
])
)
Array.from(
Array(9999).keys()
).map(
x => x % 2 === 0 ?
"Hong Kong no IT" :
"一齊寫爛 code"
).join("!")
def solution(arr):
for i in range(1, len(arr)):
if arr[i] == 1:
arr[i - 1] += 1
for i in range(len(arr)-1):
if arr[i] == 2:
arr[i] = 0
arr[i+1] -= 1
while arr and arr[-1] == 0:
arr.pop()
return arr