> and add visualisations to it Might I suggest a different animation. The current one swaps two elements (bars) by vertically shrinking the taller bar and growing the shorter one. Instead, the bars should stay the same height but move horizontally. I would rather see values move than slots in the array morph to the new value they should hold. The current animation feels like you are pumping water from one tank to ano…
Bubble sort in pure CSS
41–50 of 73 posts
Re: Bubble sort in pure CSS
#42This is scary good. Well done. If your product have any frontend and you have the power to decide ensure at least one of your hires can write CSS at this level.
If someone asked me to write CSS at this level for an interview I'd probably question the job, because if you have to write CSS at this level for work something is horribly wrong.
*Obviously, abusing CSS isn’t everyone’s idea of fun.
Re: Bubble sort in pure CSS
#43> (oneIsGreater * origArray[0]) + (twoIsGreater * origArray[1]) There is a reason why conjunction (AND) is also called logical multiplication, and disjunction (OR) logical addition. There is not much difference between this and: (oneIsGreater ? origArray[0] : 0) | (twoIsGreater ? origArray[1] : 0) This is often useful to think about when working on bitset or SIMD algorithms.
> There is a reason why conjunction (AND) is also called logical multiplication, and disjunction (OR) logical addition. Really? The connection between AND and multiplication is obvious, but disjunction doesn't behave like addition. (For one thing, just like AND, it destroys information, which multiplication does do and addition doesn't.) Addition would usually be XOR. In fact, AND and XOR are what you get when you ap…
Re: Bubble sort in pure CSS
#44> and add visualisations to it Might I suggest a different animation. The current one swaps two elements (bars) by vertically shrinking the taller bar and growing the shorter one. Instead, the bars should stay the same height but move horizontally. I would rather see values move than slots in the array morph to the new value they should hold. The current animation feels like you are pumping water from one tank to ano…
Re: Bubble sort in pure CSS
#45Earlier quoted context omitted.
Is there a way to express OR (not XOR) using integer arithmetic without case distinction or special functions in the natural numbers mod 2? Meaning, using only elementary arithmetic and modulo? Seems like there should be either an obvious answer or an interesting one :)
a + b + a * b
Re: Bubble sort in pure CSS
#46This is scary good. Well done. If your product have any frontend and you have the power to decide ensure at least one of your hires can write CSS at this level.
If someone asked me to write CSS at this level for an interview I'd probably question the job, because if you have to write CSS at this level for work something is horribly wrong.
Re: Bubble sort in pure CSS
#47Earlier quoted context omitted.
Those you know it well can abuse it in a fun way. Probably not useful in practice. Nevertheless this proves talent of the one who wrote it.
A better test for someone using CSS would be activities that CSS is typically used for. Have them make a complex layout that is responsive at multiple display sizes, or have them architect a set of reusable classes for a design library or something. You may think that this sort of cleverness is generalizable: that someone who would come up with this solution would also be good at laying out web components. But there…
Re: Bubble sort in pure CSS
#48Earlier quoted context omitted.
Yeah that makes sense of course. Should have specified "special function", was aiming at "algebraic" or "polynomial" I guess. Then the answer seems to be no, right? Edit: The abs() function seems to be enough, awesome: https://math.stackexchange.com/a/1641271
The abs function works because it is equal to the maximum of x and -x. The logical "and" and logical "or" functions are precisely particular cases of the minimum and maximum functions. The so-called "exclusive or" function is simultaneously a particular case of addition and of subtraction, i.e. addition modulo 2 and subtraction modulo 2 are the same function. Therefore applying the 4 functions minimum, maximum, addit…
Re: Bubble sort in pure CSS
#49> and add visualisations to it Might I suggest a different animation. The current one swaps two elements (bars) by vertically shrinking the taller bar and growing the shorter one. Instead, the bars should stay the same height but move horizontally. I would rather see values move than slots in the array morph to the new value they should hold. The current animation feels like you are pumping water from one tank to ano…
The current one also broke in my case (mobile safari). The three smallest bars just sort of disappeared right before the last swap.
Re: Bubble sort in pure CSS
#50Earlier quoted context omitted.
a + b + a * b
This is the obvious solution I was looking for. Thanks! (and I rightfully feel stupid now)
a or b = a + b - (a * b)
The last term is equivalent to a conjunction. Which also makes sense when you think of probability:
P(a or b) = P(a) + P(b) - P(a and b)