Thanks for pointing that out! Yes, I agree that I might have created confusion with different kinds of folds in this video. I'm going to address that in the next one. :)
I've learned more since starting my journey with haskell 3 months ago than a years worth of imperative languages. Evidently they're not actually imperative. Love the videos. Keep them coming please.
These are great. Thank you. A note on [1 .. ]. Haskell does not remember the previous number in the list, that is, it doesn't keep that in memory. Once the number is displayed to your screen, the memory is released, allowing you to print an infinite list and exit it at your leisure.
You're right but if you print `xs` like here, you're holding onto the head of your list so it can't be garbage collected... Which means occupied memory will keep increasing until there's not enough to continue. When you print an infinite list without putting it into a variable (or without using the variable afterward in a function), it will often get optimized to a tight loop in assembly anyway (if you compile your code).
To count numbers which are simultaneously multiples of asLcm and divisors of bsGcd, you can count the number of divisors of the quotient bsGcd / asLcm (return 0 if asLcm doesn't divide bsGcd). To count divisors of a number, you can do the obvious thing (filter a list of candidates, take the length), or use multiplicativity of the number of divisors. A prime power p^a has a+1 divisors, and the number of divisors of a product of coprime numbers is the product of the number of divisors. For instance, the number of divisors of 16 = 2^4 is 4+1=5, the number of divisors of 27 = 3^3 is 3+1=4, the number of divisors of 432 = 2^4 * 3^3 is 5 * 4 = 20.
C-x SPACE enters the rectangle mode, move up and down to make the rectangle spawn across multiple likes. How did you insert "l1" without M-x string-insert-rectangle ? Did you just do C-t ?
here's one that i came up with, a bit more elegant slove :: [Int] -> [Int] -> Int solve as bs | gcd' `isMultipleOf` lcm' = length [lcm',2*lcm'...gcd'] | otherwise = 0 where lcm' = fold lcm as gcd' = fold gcd bs isMultipleOf = (==0) . mod
Something wrong with you, don't you wanna to try dangerous stuff? Just run that [1..] and show to the kids how it blows up! Anyway, you would have a lot of time to interrupt it by ^C.
P.S. When you're looking at it, rows of numbers are shifting, filling a pattern, you could see the matrix, the god, why didn't you share this magic toy with the world?
It has to do with the fact there are many Emacs keybindings starting with Ctrl + C (most of the major mode commands). The ^C in emacs shells/REPLs/etc is actually done with ^C^C (that's right: the same thing done twice).
I believe that your fold is actually foldr1, not foldl1, since the innermost elements are to the right. hackage.haskell.org/package/base-4.9.1.0/docs/src/GHC.List.html#foldr1 foldl1 (+) [1..4] corresponds to ((1 + 2) + 3) + 4 foldr1 (+) [1..4] corresponds to 1 + (2 + (3 + 4)) Foldl would look like this: foldl :: (b -> a -> b) -> b -> [a] -> [b] foldl f acc (x:xs) = foldl f (f acc x) xs foldl f acc [] = acc
Thanks for pointing that out! Yes, I agree that I might have created confusion with different kinds of folds in this video. I'm going to address that in the next one. :)
until i searched its solution on youtube , i was thinking how stupid i might be as unable to solve an easy category question, hackerrank shouldnt have put this in easy category.
Yeah, I know some of what you said. Actually i'm lisper -newbie lisper- and when I read that (haskell is PURE and lisp is not) in this point I feel like lisp betrayal of truth of functional way and you know other stuff. I know -not sure- that lisp is pure by default but you have power to you know have mutable var and stuff like that
@@AhmedKhaled-sj1zx how do you learn lisp I saw it in course called programming languages on coursers but in racket dress and it is weird I saw in the same course language called sml and it has this brilliant feature pattern marching
@@aymanayman9000 Hello Ayman, hope yoi doing well in Ramada, I the course you are talk about, Prof. Don actually didn't explain the lisp feature well, because it's not the course interest. I know lisp from book called SICP. And I use 3 or 4 programs written in lisp (most of them is scheme lisp). SICP ~was~ is a very dense/rich/elegant programming textbook for beginners. And it is my way into lisp (scheme lisp)
I think you actually implemented foldl1 as foldr1, but it still works because lcm and gcd are commutative.
Thanks for pointing that out! Yes, I agree that I might have created confusion with different kinds of folds in this video. I'm going to address that in the next one. :)
Technically, it doesn't matter which fold you choose because gcd and lcd are associative. They're also commutative, but that is unrelated.
You may find this video interesting ua-cam.com/video/24XK4LPoCXc/v-deo.html
I've learned more since starting my journey with haskell 3 months ago than a years worth of imperative languages. Evidently they're not actually imperative. Love the videos. Keep them coming please.
These are great. Thank you.
A note on [1 .. ]. Haskell does not remember the previous number in the list, that is, it doesn't keep that in memory. Once the number is displayed to your screen, the memory is released, allowing you to print an infinite list and exit it at your leisure.
You're right but if you print `xs` like here, you're holding onto the head of your list so it can't be garbage collected... Which means occupied memory will keep increasing until there's not enough to continue.
When you print an infinite list without putting it into a variable (or without using the variable afterward in a function), it will often get optimized to a tight loop in assembly anyway (if you compile your code).
If I wanted to continue thinking imperatively, I would not be learning Haskell. Keep teaching Haskell!
These are gold, man. Keep it up. Much love from America
"Lets do some imperative programming... with implicit recursion!"
To count numbers which are simultaneously multiples of asLcm and divisors of bsGcd, you can count the number of divisors of the quotient bsGcd / asLcm (return 0 if asLcm doesn't divide bsGcd).
To count divisors of a number, you can do the obvious thing (filter a list of candidates, take the length), or use multiplicativity of the number of divisors. A prime power p^a has a+1 divisors, and the number of divisors of a product of coprime numbers is the product of the number of divisors.
For instance, the number of divisors of 16 = 2^4 is 4+1=5, the number of divisors of 27 = 3^3 is 3+1=4, the number of divisors of 432 = 2^4 * 3^3 is 5 * 4 = 20.
Great video as always! waiting for more from the series :D
C-x SPACE enters the rectangle mode, move up and down to make the rectangle spawn across multiple likes. How did you insert "l1" without M-x string-insert-rectangle ? Did you just do C-t ?
muy bueno ....gracias¡¡¡
"fold" mmm ;) You sneaky devil!
here's one that i came up with, a bit more elegant
slove :: [Int] -> [Int] -> Int
solve as bs
| gcd' `isMultipleOf` lcm' = length [lcm',2*lcm'...gcd']
| otherwise = 0
where lcm' = fold lcm as
gcd' = fold gcd bs
isMultipleOf = (==0) . mod
Something wrong with you, don't you wanna to try dangerous stuff? Just run that [1..] and show to the kids how it blows up! Anyway, you would have a lot of time to interrupt it by ^C.
The last time I tried that inside of Emacs ^C didn't work for some reason. :(
P.S. When you're looking at it, rows of numbers are shifting, filling a pattern, you could see the matrix, the god, why didn't you share this magic toy with the world?
It has to do with the fact there are many Emacs keybindings starting with Ctrl + C (most of the major mode commands). The ^C in emacs shells/REPLs/etc is actually done with ^C^C (that's right: the same thing done twice).
wait, you implemented foldr1, not foldl1, right?
Yes, I might have created confusion with different kinds of folds in this video. I'm going to address that in the next one. :)
I believe that your fold is actually foldr1, not foldl1, since the innermost elements are to the right. hackage.haskell.org/package/base-4.9.1.0/docs/src/GHC.List.html#foldr1
foldl1 (+) [1..4] corresponds to ((1 + 2) + 3) + 4
foldr1 (+) [1..4] corresponds to 1 + (2 + (3 + 4))
Foldl would look like this:
foldl :: (b -> a -> b) -> b -> [a] -> [b]
foldl f acc (x:xs) = foldl f (f acc x) xs
foldl f acc [] = acc
Thanks for pointing that out! Yes, I agree that I might have created confusion with different kinds of folds in this video. I'm going to address that in the next one. :)
Sounds great! Thanks for the videos!
The way you explain takeWhile would work with the filter function, you should have used another instance.
Great video nonetheless !
красава, четкие уроки у тебя
until i searched its solution on youtube , i was thinking how stupid i might be as unable to solve an easy category question, hackerrank shouldnt have put this in easy category.
Clean cose😍😍😍
gg
So Haskell is not pure ?!
Well, I guess otherwise it would've been useless. :)
Yeah, I know some of what you said.
Actually i'm lisper -newbie lisper- and when I read that (haskell is PURE and lisp is not) in this point I feel like lisp betrayal of truth of functional way and you know other stuff.
I know -not sure- that lisp is pure by default but you have power to you know have mutable var and stuff like that
@@AhmedKhaled-sj1zx how do you learn lisp I saw it in course called programming languages on coursers but in racket dress and it is weird I saw in the same course language called sml and it has this brilliant feature pattern marching
@@aymanayman9000
Hello Ayman, hope yoi doing well in Ramada, I the course you are talk about, Prof. Don actually didn't explain the lisp feature well, because it's not the course interest. I know lisp from book called SICP. And I use 3 or 4 programs written in lisp (most of them is scheme lisp). SICP ~was~ is a very dense/rich/elegant programming textbook for beginners. And it is my way into lisp (scheme lisp)
@@AhmedKhaled-sj1zx thanks
{- Solution using List comprehension -}
let cs = [ x | x