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.
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.
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
`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.
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
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.
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
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
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.
True
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.
just wanted to share this solution
getmiddel :: String -> String
getmiddel "" = ""
getmiddel [x] = [x]
getmiddel [x,y] = [x,y]
getmiddel (x:xs) = getmiddel (init xs)
This blew my mind! Thanks for sharing!
ow thanks! ur welcome
sharing mine as well
getMiddle :: String -> String
getMiddle s
| (ls
Wow nice
init is O(n), though
Ha, try one of the purples in Haskell in real time!
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
Thank you so much for these videos!!
I like your videos. Can you do a harder problem next time? Especially, dynamic programming problems in Haskell would be interesting.
Newbie question, but how do you do to put the equal signs in the same column like in 10:23?
multiply = (*)
Or on the other spectrum of elegance...
multiply multiply'' = (curry . uncurry $ (\multiply' -> (*) . id $ multiply')) multiply''
Am I doing it wrong? multiply a b = getSolo $ do return $ 0 & do return $ fromJust $ do return $ head $ do return $ a * b
I registered in the codewars a long time ago, but never really done anything. This video makes me wanna to actually try it.
`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.
10:45 XD
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
nice solution, had a similar one and saw yours after I posted mine haha
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.
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?
I'm not against them. I usually use recursive functions when I can't find anything useful for the situation in the standard library.
"We are Haskell people" - hahaha
more streams pls 8)
you foresaw that it won't compile, didn't you?
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
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
Knigh7z I see, yeah I rebinded escape to capslock, I guess you know why :D
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).
don't warry there are tonzzzzzzzzzzzzz of other emacs bindings just use any of them
Actually I use Evil emacs (vi like binding)
rebind ctrl to caps lock.
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
No, I haven't seen it. Thanks! I'll take a look. :)
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
Nice
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