when the python code looks more like nonsense than c
@mr.k8660 Жыл бұрын
yh the string looked like haskel or something
@miteshranjanpanda1776 Жыл бұрын
@@mr.k8660 regex
@yante7 Жыл бұрын
me when regex
@vaisakh_km11 ай бұрын
@@mr.k8660 the string is regex.... which is as bad as haskel...
@csolisr Жыл бұрын
I know that regex is powerful, but today I learned there's a regex to determine if a number is prime, dear lord that's needlessly clever
@s.hariharan6958 Жыл бұрын
i solved some problem using regex in javascript in free code camp that was so fun 😅 with no sence of thinking logics ..
@GSBarlev Жыл бұрын
I found an explanation for it on Stack Exchange. Mind-blowing.
@no_name479611 ай бұрын
^(2|3|5|7|11|13|17|19|23|29|31|37|41|43|47|53|59|61|67|71|73|79|83|89|97)$ This regex matches only primes under 100 ;-)
@Edouard.Choiniere Жыл бұрын
In the C version, you don’t have to check up to n/2. You only have to check up to sqrt(n), or the last integer number of sqrt(n) (floor).
@mrfli24 Жыл бұрын
yup. If it's composite, it must be a multiplier of some number up to sqrt(n).
@xarkenz Жыл бұрын
an easy way I've found to do this while avoiding a square root is just having the for loop condition be "i * i 0) return false;" inside the loop and "return true;" after the loop 😭
@Edouard.Choiniere Жыл бұрын
@@xarkenz Im not sure that doing i*i n times in the loop is really better than computing a sqrt once, out of the loop. Not only overhead, but numbers will get big at a point. Im sure there are some ways that completely avoiding floating points are needed, like in some specific embedded scenarios
@xarkenz Жыл бұрын
@@Edouard.Choiniere ooh, i didn't think about that. i guess in terms of complexity, i think sqrt is O(1) and multiplication is O(n). and about the numbers getting big... i think the only time an overflow could occur is when (i-1)*(i-1)
@jhgvvetyjj6589 Жыл бұрын
And by using long long instead of int, the 131234747345 will even work
@martingeorgiev999 Жыл бұрын
a c dev would never do it so inefficiently
@truebender Жыл бұрын
pathetic. as one of the c++ devs, I can just simply make a header file
@azeek Жыл бұрын
nodejs: proceeds to install whole universe before doing anything
@norielgames4765 Жыл бұрын
Now check how fast both are and how much memory they use.
@vaisakh_km Жыл бұрын
why should? lets be real... 99% projects out there only going to used by max 1000 people who don't see difference of 0.1 sec and 0.001 sec or 1mb vs 10 mb edit: you were taking this algorithm taking up too much memory and not a blew at python..? i agree with you...
@Faunarr Жыл бұрын
@@vaisakh_km Considering that prime numbers mainly have a scientific application, then yes that matters quite a lot. And if you just want to check for primes you can just google it and you get your result instantly.
@eig520311 ай бұрын
the python solution was more like a regex solution...
@bryceblazegamingyt97418 ай бұрын
@@vaisakh_km bc python sucks by a much larger margin than a millisecond. Also 0.1 is literally ten times slower than 0.001 seconds so your point makes no sense
@vaisakh_km8 ай бұрын
@@bryceblazegamingyt9741 ok, i won't write a rendering engine using python, but to parse some csv to json, it's more than enough... anyone can wait a min for it
@kienha9036 Жыл бұрын
I thought the joke was having the Python version importing C one
@ENNEN420 Жыл бұрын
And here I thought python was supposed to be MORE readable than C. I guess C chads can't stop winning
@xWatexx Жыл бұрын
There’s regex for telling if a number is Prime? That’s news to me.
@Dev-Siri Жыл бұрын
when c looks easier than python:
@5cover Жыл бұрын
it's not specifically python, you could to this in any language with builtin regex support BUT WHAT THE HELL? A regex to match prime numbers? How?
@KanashimiMusic Жыл бұрын
It doesn't actually match the number, it makes a string that is N characters long and checks if it can split the string into at least two substrings of equal length
@diobrando7642 Жыл бұрын
I was flabbergasted, but then I remembered, regular expression have a complexity of O(n) where n is the length of the string they're analyzing. Sadly, even if you used a regular expression in C, the first program would have been more efficient nonetheless, since it has to iterate just sqrt(n) times (not n/2)
@velox__ Жыл бұрын
Not all regex engines have guaranteed O(n) complexity.
@diobrando7642 Жыл бұрын
@@velox__ it's an approximation, but all regular expressions can be implemented as finite state automata, so it's generally O(n)
@velox__ Жыл бұрын
@@diobrando7642 yes, but not all are implemented like that :) I was being padentic anyway
@KanashimiMusic Жыл бұрын
@@diobrando7642 For actual regular expressions, what you're saying would be correct - however, note how this Regex uses a capture group and, more importantly, a back reference. Back references to capture groups require the algorithm to remember something it previously found and match it again, which already isn't possible using finite state automata. Additionally (afaik), it also needs to make several attempts regarding how many characters actually belong into the capture group until the back reference matches. All of this means that the complexity of this is VERY far away from being O(n).
@diobrando7642 Жыл бұрын
@@KanashimiMusic thank you for this input, I know regex implementations can differ from theoretical regular expressions, I just wanted to say that in the best case (so considering a regular expression which is implemented with a finite state Automata) that would still be O(n) vs O(√n) (I could have worded it better)
@slava6105 Жыл бұрын
I thought my world broke on "check divisibility by 7" with regex. Now my world is falling apart with "check if prime with regex".
@SuperQuwertz Жыл бұрын
Really cool video, I like the style! :D
@blaze_arch6864 Жыл бұрын
Awesomee video, Virbox! ^_^ C is best programming language ever 😎
@Ne-vc5pm Жыл бұрын
No dependency manager? Zero safety? No bches?😢😢
@blaze_arch6864 Жыл бұрын
@@Ne-vc5pm Yes. 😎
@truebender Жыл бұрын
@@Ne-vc5pmvalgrind.
@giuyoАй бұрын
C++ is better than C tho
@nevokrien95 Жыл бұрын
Never ever saw this type of python code
@brawldude2656 Жыл бұрын
Just write a regex that covers all composite numbers... I see no problem with that
@flamakespark Жыл бұрын
clearly a fake comparison, C program should've ended with SegFault - average Python dev copium
@adershvarshnei5198 Жыл бұрын
What font is that on the c version?
@squid13579 Жыл бұрын
regex in python looks more dangerous than c.🤣
@callyral Жыл бұрын
did you just use a regex to determine if a number is prime???
@um80785 ай бұрын
Brother what is that font
@bundzsi Жыл бұрын
As a person who is learning Python at the moment, this made no fucking sense
@Henry14arsenal2007 Жыл бұрын
Can anyone explain wtf is happening in the Python version?
@konstantink07 Жыл бұрын
look up regex
@prepareyourpainis Жыл бұрын
Drugs, probably
@santirruki4743 Жыл бұрын
coding in comic sans:
@anon-fz2bo10 ай бұрын
bro u can solve that with a simple for loop lmao, idt time complexity matters if ur writing it in C, itll still be blazingly fast. ie static const uint8_t is_prime(const unsigned long x) { size_t matches = 0; for (auto i = 1; i
@lavaquark Жыл бұрын
I think you know that this is not how you check if a number is prime
@Jonas-gm4my11 ай бұрын
Can some smart guy explain the regex hack to me?
@Voidkitty_ Жыл бұрын
Me dividing the number by every int smaller than its sqrt
@sayamqazi Жыл бұрын
Shouldnt do by every int Only the prime ints
@Voidkitty_ Жыл бұрын
@@sayamqazi that's harder to do with every int you can have a variable start at 2 and then add on and then add two and then keep adding two until the variable is greater than the sqrt
@EntityPlantt11 ай бұрын
I love how the title clarifies that Python users aren't normal programmers
@RetroEcoChicken Жыл бұрын
how do you know a coding language is useless? ++ is not recognized.
@ollicron7397 Жыл бұрын
Use the simpy module dude.
@GSBarlev Жыл бұрын
Huh. Seems overly complicated. I would have just done: import primelib print(primelib.isprime(n)) (examples of primelib include sympy and primespy)
@lonelyshpee7873 Жыл бұрын
The correct way to code in Python is to leave as much as possible up to libraries written in C.
@mrfli24 Жыл бұрын
It sounds pythonic to me. Great work. haha.
@cmaxz817 Жыл бұрын
Python dev tries not to pass data to libraries written in C challenge (impossible)
@_kitaes_ Жыл бұрын
and primelib is written in c lol
@KanashimiMusic Жыл бұрын
Bro it's a joke
@disconnect3d487 Жыл бұрын
song>?
@GSBarlev Жыл бұрын
He credits the original songwriter at the end 😉
@originalnamegoeshere Жыл бұрын
C devs are normal now?
@sdkdoom11 ай бұрын
lmao imagine only knowing how to use others libraries and calling yourself a programmer
@彭煥城-t7r Жыл бұрын
The code is really bad
@EnterOne100 Жыл бұрын
bool prime = n > 1
@freerussianman Жыл бұрын
def check_prime(number: int): if number % 2 == 0: return True else: return False while 1: value = int(input()) print(check_prime(value))
@_kitaes_ Жыл бұрын
check_even*
@KanashimiMusic Жыл бұрын
bro got "even" and "prime" confused wth
@Razumist-e2g Жыл бұрын
@@KanashimiMusic, default python "programmer"
@Rallidars Жыл бұрын
Дякую за твої відео дуже цікаві та круті
@Virbox Жыл бұрын
приємно чути)
@ulysseyang9733 Жыл бұрын
Python is all about library. That's why I like C more.
@Dr-Zed Жыл бұрын
Normal vs Python 😂
@imaz0mbie_ Жыл бұрын
linux users when they see 1 byte of bloat: 😡
@MrAbrazildo Жыл бұрын
#include bool is_prime (const int N, const int i) { return i*i > N ? true : (N % i ? is_prime (N, i + 2) : false); } int main ( ) { //Automated tests: #define _(B, N) assert (B == is_prime (N, 3)); assert (N % 2) // Don't test even numbers: 2 is the only 1. _( true, 5); _(true, 13); _(false, 9); _(false, 21); _(true, 11); _(false, 123); _(true, 313); _(false, 909); _( true, 1021);// _(false, 454); _( true, 797); _(false, 9909); return 0;//EXIT_SUCCESS; }
@moonyl53412 ай бұрын
matt parker did a video on something similar its ^.?$|^(..+?)\1+$