Code Warrior -- HaskellRank #04

Поділитися
Вставка
  • Опубліковано 13 вер 2024
  • Kata: www.codewars.c...
    Twitch Channel: / tsoding
    Support: / tsoding

КОМЕНТАРІ • 41

  • @lazy_racer
    @lazy_racer 4 роки тому +15

    The part of codewars i like the most, is when you've done and submitted kata you get presented with other people solutions, where they get market as 'best practice' and 'clever' and get sorted out, so the best of the best is on top. Then, you see it and think what a dumbass you are. A great fuel to improve.

  • @davidyanceyjr
    @davidyanceyjr 6 років тому +2

    Honestly I'm just here to learn more Haskell. I'm currently working through project euler and as my math skills suck I find it challenging. However, in every quest for a solution I find something new about Haskell that amazes me. I tip my hat to all who master Haskell.

  • @houssemelhadj6881
    @houssemelhadj6881 5 років тому +11

    just wanted to share this solution
    getmiddel :: String -> String
    getmiddel "" = ""
    getmiddel [x] = [x]
    getmiddel [x,y] = [x,y]
    getmiddel (x:xs) = getmiddel (init xs)

    • @jaketripp
      @jaketripp 5 років тому

      This blew my mind! Thanks for sharing!

    • @houssemelhadj6881
      @houssemelhadj6881 5 років тому +1

      ow thanks! ur welcome

    • @hdt1948
      @hdt1948 4 роки тому +2

      sharing mine as well
      getMiddle :: String -> String
      getMiddle s
      | (ls

    • @harshitjoshi3082
      @harshitjoshi3082 4 роки тому +1

      Wow nice

    • @Bredor
      @Bredor 2 роки тому

      init is O(n), though

  • @CliffStamp
    @CliffStamp 5 років тому +7

    Ha, try one of the purples in Haskell in real time!

  • @pluieuwu
    @pluieuwu Рік тому +1

    i used an amazingly clean recursive method that doesn't have anything to do with modulos 😅 the only downside is that `init` is O(n) but for a string at most 100 chars long it doesnt matter
    middle xs
    | length xs

  • @DeboXP
    @DeboXP 5 років тому

    Thank you so much for these videos!!

  • @karelnovak8818
    @karelnovak8818 6 років тому +4

    I like your videos. Can you do a harder problem next time? Especially, dynamic programming problems in Haskell would be interesting.

  • @sholum4440
    @sholum4440 Рік тому

    Newbie question, but how do you do to put the equal signs in the same column like in 10:23?

  • @johnnyphoney5669
    @johnnyphoney5669 6 років тому +26

    multiply = (*)

    • @muntoonxt
      @muntoonxt 6 років тому +1

      Or on the other spectrum of elegance...
      multiply multiply'' = (curry . uncurry $ (\multiply' -> (*) . id $ multiply')) multiply''

    • @niyazfahretdinov9651
      @niyazfahretdinov9651 Рік тому

      Am I doing it wrong? multiply a b = getSolo $ do return $ 0 & do return $ fromJust $ do return $ head $ do return $ a * b

  • @valentjedi
    @valentjedi 6 років тому

    I registered in the codewars a long time ago, but never really done anything. This video makes me wanna to actually try it.

  • @johnnyphoney5669
    @johnnyphoney5669 6 років тому +1

    `undefined` is also used to pass just some type as an argument to a function, but usually `Proxy` data-type is preferred way to do so, but it would probably blow out newbie's mind.

  • @mrigankabasuroychowdhury6329
    @mrigankabasuroychowdhury6329 6 років тому +3

    10:45 XD

  • @bW9ydGhvbg
    @bW9ydGhvbg 6 років тому +2

    i used a little bit of dirty trickery in my solution but it handles empty string correctly and doesn't use (!!), which is often considered bad in haskell programming.
    ```
    getMiddle : String -> String
    getMiddle s = take m $ drop n s
    where n = (negate $ div (negate $ length s) 2) - 1
    m = if even s then 2 else 1

    • @ritaferland5838
      @ritaferland5838 6 років тому

      nice solution, had a similar one and saw yours after I posted mine haha

  • @skaramicke
    @skaramicke Рік тому

    Imagine the vast universe of website emacs editors that would open up to you if you remove some keybindings in your browser. And then imagine how clunky that browser would be.

  • @WeatheRay
    @WeatheRay 6 років тому +1

    What is your opinion of using a recursive function to remove the first and last items from the list/string until the length is 1 or 2?

    • @Tsoding
      @Tsoding  6 років тому +2

      I'm not against them. I usually use recursive functions when I can't find anything useful for the situation in the standard library.

  • @naughtrussel5787
    @naughtrussel5787 3 роки тому

    "We are Haskell people" - hahaha

  • @Knigh7z
    @Knigh7z 6 років тому +2

    more streams pls 8)

  • @bocckoka
    @bocckoka 6 років тому

    you foresaw that it won't compile, didn't you?

  • @SuperManitu1
    @SuperManitu1 6 років тому +8

    God emacs keybindings are bad. Dont you suffer from constant wrist pain? I do if I use any editor that forces me to use control

    • @Knigh7z
      @Knigh7z 6 років тому +8

      he rebinds ctrl to caps lock, which makes sense given the old keyboards: www.catonmat.net/images/why-vim-uses-hjkl/lsi-adm3a-full-keyboard.jpg

    • @SuperManitu1
      @SuperManitu1 6 років тому +3

      Knigh7z I see, yeah I rebinded escape to capslock, I guess you know why :D

    • @johnnyphoney5669
      @johnnyphoney5669 6 років тому +1

      That's why I created this tool: github.com/unclechu/xlib-keys-hack to be able to use Caps Lock and Enter as the control keys (but not only for that).

    • @AhmedKhaled-sj1zx
      @AhmedKhaled-sj1zx 6 років тому

      don't warry there are tonzzzzzzzzzzzzz of other emacs bindings just use any of them
      Actually I use Evil emacs (vi like binding)

    • @karelnovak8818
      @karelnovak8818 6 років тому

      rebind ctrl to caps lock.

  • @Knigh7z
    @Knigh7z 6 років тому +1

    I remember you mentioning on stream (watched the vod) that you'd like a Haskell with s-expressions ... have you seen lexi's work on Hackett? github.com/lexi-lambda/hackett

    • @Tsoding
      @Tsoding  6 років тому +1

      No, I haven't seen it. Thanks! I'll take a look. :)

  • @ritaferland5838
    @ritaferland5838 6 років тому +2

    getMiddle :: String -> String
    getMiddle s = take n $ drop ((l - 1) `div` 2) s
    where l = length s
    n = if (odd l) then 1 else 2

  • @AdamSchelenbergCom
    @AdamSchelenbergCom 5 років тому

    So my solution is kinda ugly:
    getMiddle :: String -> String
    getMiddle s
    | length s `mod` 2 == 0 = (s !! (x - 1)) : (s !! x) : []
    | length s == 1 = s
    | otherwise = (s !! x) : []
    where x = div (length s) 2