IT 討論區(48)最強工種,FG25K,你!敢唔敢成功?

青花瓷

1001 回覆
6 Like 0 Dislike
青花瓷 2018-11-27 09:55:31
python 25 行, time complexity:簡短
屌埋你果份 2018-11-27 10:02:54
屌埋你果份 2018-11-27 10:05:27
Mike_Chan 2018-11-27 10:18:57
做Support都做到咁風騷
做programmer搵兩倍人工無人吼
Tirpitz 2018-11-27 10:33:50
想俾日本妹sm
最鐘意埋單 2018-11-27 10:39:15
有冇人知auditor點入行,條career path又好唔好
i-vtec 2018-11-27 10:40:43
人地有埋學校宿舍住
你班it9咪又係住公屋
麥斯 2018-11-27 10:41:38
[1,1]會炒
Code4Food 2018-11-27 10:42:32
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


9行Haskell。應該係linear time,如果唔係。可以好容易用C/C++寫到係不過應該長D。如果output准有trailing zeros,可以唔洗reverse兩次同dropWhile。

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> 
麥斯 2018-11-27 10:42:57
max唔可以食empty set
玩家國度 2018-11-27 10:54:15
係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" />
做Support都做到咁風騷
做programmer搵兩倍人工無人吼<img src="/assets/faces/normal/frown.gif" class="hkgmoji" />
想俾日本妹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" />

黑C踩面
Mike_Chan 2018-11-27 10:57:42
原來有炮房先係最重要
Code4Food 2018-11-27 10:58:12
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

多三行去處理list of zeroes,前面9行版 ceilOfHalf [1,1] 會出empty list。其實數值上無錯,因為empty list係對應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> 
素晴 2018-11-27 11:02:17
上面嗰啲係咪code嚟㗎好型呀
可唔可以教吓小妹
冇得輸窮三代IT狗 2018-11-27 11:07:12
樓上咁多 code 聖
Tirpitz 2018-11-27 11:10:28
code4food
Code4Food 2018-11-27 11:17:16
Actually,stripTrailingZeros處理output formatting嘅問題,咁addBaseMinus2其實可以再簡單D少一行。

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
冇得輸窮三代IT狗 2018-11-27 11:20:34
我都寫返兩句先
print(
  "!".join([
    "Hong Kong no IT" if x % 2 is 0
    else "一齊寫爛 code"
    for x in range(9999)
  ])
)
冇得輸窮三代IT狗 2018-11-27 11:34:31
JS
Array.from(
  Array(9999).keys()
).map(
  x => x % 2 === 0 ?
  "Hong Kong no IT" :
  "一齊寫爛 code"
).join("!")
Code4Food 2018-11-27 11:52:07
講番條題目:x = ceil(x/2) + floor(x/2) 所以 ceil(x/2) = x - floor(x/2)。而base -2 shift走最低digit其實就係 -floor(x/2)。AddBaseMinus2只係簡單嘅小學進位加法,不過因為係base -2所以我carryOut係要反轉正負,因為我2去除。
作Code人 2018-11-27 11:54:39
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

python array.pop() remove trailing zeros都方便
觀塘奧蘇利雲 2018-11-27 11:55:14
Rakuten 有冇人收到 1st interview email

If you pass screening, you will recieve invitation e-mail to 1st interview.
The interview will be hold during 28th to 30th Nov about 30 minutes through online(Skype) and final interview will be face to face in Hong Kong on 8th/9th Dec.
麥斯 2018-11-27 11:58:58
好clean, j死
Code4Food 2018-11-27 12:02:59
Can you do it in O(1) memory? Imaging that you have a very long array (e.g. 1 billion digits) but your computer has very limited memory like 64K and a network interface.
吹水台自選台熱 門最 新手機台時事台政事台World體育台娛樂台動漫台Apps台遊戲台影視台講故台健康台感情台家庭台潮流台美容台上班台財經台房屋台飲食台旅遊台學術台校園台汽車台音樂台創意台硬件台電器台攝影台玩具台寵物台軟件台活動台電訊台直播台站務台黑 洞