I don't think there's much to codegolf. The "obvious" solution (even() (($1%2))
) is both shorter and faster. Don't think it can be optimized much more.
balsoft
The difference is that ((
is a "compound command", similar to [[
(evaluate conditional expression), while $(( ))
is "aritmetic expansion". They behave in almost exactly the same way but are used in different contexts - the former uses "exit codes" while the latter returns a string, so the former would be used where you would expect a command, while the latter would be used where you expect an expression. A function definition expects a compound command, so that's what we use. If we used $(( ))
directly, it wouldn't parse:
$ even() $((($1+1)&1))
bash: syntax error near unexpected token `$((($1+1)&1))'
We would have to do something like
even() { return $(($1&1)); }
(notice how this is inverted from the ((
case - ((
actually inverts 0 -> exit code 1 and any other result to exit code 0, so that it matches bash semantics of exit code 0 being "true" and any other exit code being "false" when used in a conditional)
But this is a bit easier to understand and as such wouldn't cut it, as any seasoned bash expert will tell you. Can't be irreplaceable if anyone on your team can read your code, right?
I can't think of many use-cases for ((
. I guess if you wanted to do some arithmetic in a conditional?
if (( $1&1 )); then echo "odd!"; else echo "even!"; fi
But this is pretty contrived. This is probably the reason you've never heard of it.
This ((
vs. $(( ))
thing is similar to how there is (
compound command (run in a subshell), and $( )
(command substitution). You can actually use the former to define a function too (as it's a compound command):
real_exit() { exit 1; }
fake_exit() ( exit 1 )
Calling real_exit
will exit from the shell, while calling fake_exit
will do nothing as the exit 1
command is executed in a separate subshell. Notice how you can also do the same in a command substition (because it runs in a subshell too):
echo $(echo foo; exit 1)
Will run successfully and output foo
.
((
being paired with $((
, and (
with $(
, is mostly just a syntactic rhyme rather than anything consistent. E.g. {
and ${
do very different things, and $[[
just doesn't exist.
Bash is awful. It's funny but also sad that we're stuck with it.
I doubt even releasing the files with his name plastered all over them wouldn't do much at this point. His "I could stand in the middle of Fifth Avenue and shoot somebody, and I wouldn't lose any voters, OK?" was an understatement. He could literally rape children on a remote pedo island and still wouldn't lose many voters. It's pretty much an openly fascist party now, they actually don't give a damn as long as they can abuse people they don't like, and he's like the perfect enabler for them - legally but even more importantly culturally.
Of course there are some people who are just clueless and thought he would fix inflation or something, but those will be kept carefully misinformed by Twitter/Fox/etc.
I don't see any good way out of this situation for the US or the world, unfortunately. It's also just so awful that racism and hate of like a dozen million people, combined with misinformation in another couple dozen can have such a devastating effect on 8 billion.
Yeah, I agree that Elixir is a fine language for some tasks. I personally find the readability somewhat average, but it's very maintainable (due to how it enables clear program structure), the error handling is great, and the lightweight process system is amazing.
See: man bash
, "Compound Commands" and "Shell Function Definitions"
I wish to all web developers who make a custom dropdown for dates in which you can't just type the god damn date in to use this style of date selection for everything.
Amateur! I can read and understand that almost right away. Now I present a better solution:
even() ((($1+1)&1))
~~(I mean, it's funny cause it's unreadable, but I suspect this is also one of the most efficient bash implementations possible)~~
(Actually the obvious one is a slight bit faster. But this impl for odd
is the fastest one as far as I can tell odd() (($1&1))
)
No, silly. You ask chatgpt to write (steal) a loop that would generate all those lines. Haven't you heard about meta-vibe template-programming?
I mean, it would be almost this exact thing in almost any language.
fn is_even(n: i64) -> bool {
n % 2 == 0
}
even n = n `rem` 2 == 0
def is_even(n):
return n % 2 == 0
etc
You kid, but Idris2 documentation literally proposes almost this exact impl: https://idris2.readthedocs.io/en/latest/tutorial/typesfuns.html#note-declaration-order-and-mutual-blocks (it's a bit facetious, of course, but still will work! the actual impl in the language is a lot more boring: https://github.com/idris-lang/Idris2/blob/main/libs/base/Data/Integral.idr)
Lots of interesting answers here. I figured I'll pitch in too.
IMHO there is no one true, universal meaning of life - just as there is no one meaning of any piece of art. I think the idea that everything around you must have a single meaning is a relatively modern one, which came from the requirements of efficient communication (which should indeed be precise and not open to interpretation).
As it stands, it is up to you to interpret the world around you and find different meanings for yourself, just as you should do with art. If you are struggling to start, consider those questions: What do you enjoy? What makes you happy? What do you think is "good", even if it makes you sad or uncomfortable? All those things are your personal interpretations of meaning of life. Or go ahead and make up something else, I'm not your dad.
I was pondering why people fight so hard to beat diseases and live a few more years. What are they planning to do? Why exert effort just to be here longer when you don’t have a reason?
As for this, I think when people realize the proximity of death and temporal nature of their life, they are much better at coming up with meanings. Maybe it is to see your partner or your children for a couple more years. Maybe it's another couple of gaming sessions with your pals. Whatever it is, when you realize you don't have much of it left, the importance of it typically rises dramatically from your perspective. If you're struggling to visualize something so dramatic, imagine that your favourite food will be completely banned and criminalized in your country in couple weeks. Wouldn't you want to enjoy it more before that happens?
As far as I remember, things other than credit/debit cards in Google Wallet are pretty much images that you can scan like you would a paper ticket. Maybe download that ticket somehow — if some other app provides the same android "activity" as Google Wallet (so it shows up in "Open WIth" menu when you clicj that button), you can use it to avoid Google completely. If it's hardcoded to use Google Wallet, make a separate account just for this ticket. Then just open the ticket in the app, take a screenshot, and use your favorite gallery app to scan it in at ticket gates.