Day 36: Hacker Rank has Linux Challenges!?

I finally finished section 6 from the awk manual and I discovered that Hacker Rank has an entire section on Linux Challenges!

TLDR;

Okay, so here are the highlights of what I did:

  • I watched the YouTube recording of lecture 4 of the MIT Missing Semester Course. I wanted to see if I could take more information away now that I have practiced with all of the tools mentioned a bit. I learned a bit more but it was a great revision overall.
  • I continued with my notes on the awk programming language. I finished section 6 which is kind of a big deal. Section 6 is a pretty big seciton. I will start section 7 if I feel like I need to learn more.

Notes from gawk manual – Expressions


Comparison Operators

Comparison expressions have the value one if true and zero if false.

  • x < y -> True if x is less than y
  • x <= y -> True if x is less than or equal to y
  • x > y -> True if x is greater than y
  • x >= y -> True if x is greater than or equal to y
  • x == y -> True if x is equal to y
  • x != y -> True if x is not equal to y
  • x ~ y -> True if the string x matches the regexp denoted by y
  • x !~ y -> True if the string x does not match the regexp denoted by y
  • subscript in array -> True if the array array has an element with the subscript subscript

Boolean Expressions

  • boolean1 && boolean2
  • boolean1 || boolean2
  • ! boolean

Conditional Expressions (ternary Operator in JavaScript)

# syntax

selector ? if-true-exp : if-false-exp

6.4 Function Calls

gawk has:

  • built-in functions
  • custom functions that we can write in awk
  • functions we can import from C and/or C++ (in gawk only???)
# syntax

sqrt(x^2 + y^2)        one argument
atan2(y, x)            two arguments
rand()                 no arguments

6.5 Operator Precedence

BEDMASS/PEMDAS Math operations applies in awk as well.

A list of precedence for all awk operators:

  1. (…) Grouping.
  2. $ Field reference.
  3. ++ -- Increment, decrement.
  4. ^ Exponentiation. These operators group right to left.
  5. + - ! Unary plus, minus, logical “not.”
  6. * / % Multiplication, division, remainder.
  7. + - Addition, subtraction.
  8. String concatenation e.g. ("hello" " world")
  9. < <= == != > >= >> | Relational and redirection. Note that the I/O redirection operators in print and printf statements belong to the statement level, not to expressions. The redirection does not produce an expression that could be the operand of another operator. As a result, it does not make sense to use a redirection operator near another operator of lower precedence without parentheses. Such combinations (e.g., print foo > a ? b : c) result in syntax errors. The correct way to write this statement is print foo > (a ? b : c).
  10. ~ !~ Matching, nonmatching.
  11. in Array membership.
  12. && Logical “and.”
  13. || Logical “or.”
  14. ?: Conditional. This operator groups right to left.
  15. = += -= *= /= %= ^= Assignment. These operators group right to left.

Conclusion

That’s all for today. If you are interested in the MIT course you can check out the video lecture I’m currently going through. The lecture is helpful but isn’t sufficient by itself. Anyways, until next time PEACE!