![]() |
While reading up on [C]logrotate[/C] I came across the [C]cron[/C] daemon, which runs programs on a scheduled basis. For the less adept users of Gnome-based Linux systems, there is a convenient graphical tool for scheduling such tasks. Each user (including root) has a [C]crontab[/C] file, which determines when commands are to be executed. According to this helpful page:
[QUOTE]Each line [of the [C]crontab[/C] file] has five time-and-date fields, followed by a command, followed by a newline character ('\n'). The fields are separated by spaces. The five time-and-date fields cannot contain spaces. The five time-and-date fields are as follows: minute (0-59), hour (0-23, 0 = midnight), day (1-31), month (1-12), weekday (0-6, 0 = Sunday). [C]01 04 1 1 1 /usr/bin/somedirectory/somecommand[/C] The above example will run /usr/bin/somedirectory/somecommand at 4:01am on January 1st plus every Monday in January. [/QUOTE] There's also some special syntax for indeterminate values. One that seems useful is [C]*[/C]. The time fields with an asterisk in them tell [C]cron[/C] to run the command on every instance of that time period (every minute, hour, day, etc.). I messed around with some old Haskell kata that I had trouble with a month or two ago, when I was just starting. [URL="https://www.codewars.com/kata/sum-without-highest-and-lowest-number/"]Sum without highest and lowest number[/URL] had a weird [C]Maybe [Int][/C] type that is still confusing to work with; definitely pretty weird for a level 8 kata, especially since most of the other answers use a lot of Maybe functions that are just as weird :max: |
[QUOTE=jvang;495148]I messed around with some old Haskell kata that I had trouble with a month or two ago, when I was just starting. [URL="https://www.codewars.com/kata/sum-without-highest-and-lowest-number/"]Sum without highest and lowest number[/URL] had a weird [C]Maybe [Int][/C] type that is still confusing to work with; definitely pretty weird for a level 8 kata, especially since most of the other answers use a lot of Maybe functions that are just as weird :max:[/QUOTE]
The only point in using Maybe [Int] would be if you need to distinguish between receiving an empty list and receiving no list at all. I don't think that is necessary here. |
[QUOTE=Nick;495167]The only point in using Maybe [Int] would be if you need to distinguish between receiving an empty list and receiving no list at all.
I don't think that is necessary here.[/QUOTE] Yeah, I wasn't sure about that either :ermm: My dad has never learned elementary math, since he missed several years of the fundamentals. He's taking the Prealgebra course from Art of Problem Solving, and is having a blast with it. But there is one thing so far that is very difficult for him to grasp, and I'm not sure how to explain it:[$$]\begin{array}{cc} \text{if} & y - x = 7 \\ \text{then} & x - y = \ ?\end{array}[/$$] He doesn't know why this doesn't make sense to him, nor what about it doesn't make sense. Now that we've worked it out he gets that taking the inverse of the expression means that the result is the inverse of the other side, but he doesn't understand why. I'm not sure how to present it. I'm used to being able to just visualize how to work on an expression to make it equivalent to another, but for me it's as basic as walking; how is it explainable? :unsure: |
[CODE]x - y
= (-1)(-1)x - y = (-1)(-x) - y = (-1)(-x) - (-1)(-1)y = (-1)(-x) - (-1)(-y) = (-1)(-x - (-y)) = (-1)(-x + y) = (-1)(y - x) = (-1)7 = -7 [/CODE] I should comment each step with its ring operation rule. We are "factoring out -1". |
How about a numeric example?
3 - 4 = 1 4 - 3 = -1 ? Or -(y - x) = (-y) - (-x) = -y + x = x - y ? Or -(y - x) = -1 x (y - x) ? Does any of these alternate explanations lead to the "aha!" moment? |
y-x=7
add x to both sides: y = 7 + x subtract y from both sides: 0 = 7 + x - y subtract 7 from both sides: -7 = x - y Now, repeat a thousand times with different symbols for 7, x and y. Those three steps will seem like a PITA, so you start learning the multiply by (-1) on both sides trick... |
Would multiplying both the left and right side with -1 bring some clue?
Or,well, adding/subtracting x/y/7 in both sides? Generally this means going to "very basic", when you have "a+b=c", then you can say "a=c-b", i.e. you can move one variable on the other side and change its sign. Why does this work? Because we take as axiom the fact that, given an equality, we can do something with the left side, and do the same thing with the right side, and the equality won't change. If I have a bucket of apples and a bucket of oranges, and I know that the two quantities are equal, then adding one apple to the first and one orange to the second, the quantities will remain equal. Adding two. Adding a lot. Subtracting a lot. This is how the integers are made, by adding one, adding one, adding one, etc. Then the multiplication is done by adding some integer, adding some integer, etc. So, given "a+b=c", we have two quantities, one on the left side of '=' and one on the right. If we subtract one on both sides, they remain equal. Also, if we subtract b in both sides, they remain equal. This is an axiom. So, a+b-b=c-b. Then, due to associative property of addition, we can group +b-b and get rid of it. This is what allows the food seller at the corner of the street to give you the correct change, without making subtractions, for example, you buy a 13 dollars sandwich and pay with a fifty bucks bill, he will say "13, 14, 15" (and put two of a dollar in your hand) "20" (and put a five), "30, 40, 50" (and put 3 bills of 10). He does not need to subtract "50-13=37" and count you 37. (You may be surprised, but some people I know learned this during they went to the university, I told this fact and they were very surprised, haha, they said "waaa... what? what the hack, I was always subtracting", they didn't know this is possible, and always struggled to make subtraction in their head every time they went shopping - this is not a joke) Edit: whaaa... so many crossposts |
Thanks for all the responses! I'll show them to my dad and see if any help him.
I was working on [URL="https://www.codewars.com/kata/largest-product-in-a-series/"]Largest product in a series[/URL], and decided that I wanted to make a function similar to [C]subsequences[/C] that would take every combination of 5 consecutive elements, then work on the list of lists (maybe [C]map[/C] the [C]product[/C] function across them, then take the [C]maximum[/C]?). However, my code is producing an error: [CODE]makeList5 str = [take 5 str] ++ [makeList5 (tail str)][/CODE] which returns [CODE]<interactive>:5:1: error: * Occurs check: cannot construct the infinite type: a ~ [a] Expected type: [a] -> [a] Actual type: [a] -> [[a]] * Relevant bindings include makeList5 :: [a] -> [a] (bound at <interactive>:5:1)[/CODE] I figured that adding an [C]if[/C] clause that would stop returning lists at the end of the input would fix it, but now I have even more errors. How would one go about constructing this sort of function, or modify mine to fix the error? :unsure: More on [C]cron[/C]: For the [C]crontab[/C] file's date/time columns, there are some shortened strings that represent common times to run commands. These are: @reboot - Run once, at startup. @yearly - Run once a year, "0 0 1 1 *". @annually - (same as @yearly) @monthly - Run once a month, "0 0 1 * *". @weekly - Run once a week, "0 0 * * 0". @daily - Run once a day, "0 0 * * *". @midnight - (same as @daily) @hourly - Run once an hour, "0 * * * *". You can also run GUI applications with [C]cron[/C]. To do so, you need to add [C]env DISPLAY=:0[/C] between the date/time fields and the command. [C]DISPLAY=:0[/C] refers to the current display, display 0, which can be changed for alternate displays. Access to [C]crontab[/C] can be restricted from normal users. To do so, one must create either a [C]/etc/cron.allow[/C] or a [C]/etc/cron.deny[/C] file. If [C]/etc/cron.allow[/C] exists, normal users must be listed in it to be able to use [C]crontab[/C]. If [C]/etc/cron.deny[/C]exists, only users who are not listed in it ay use [C]crontab[/C] (however, if it exists but is empty, only users listed in [C]/etc/cron.allow[/C] may use [C]crontab[/C]). If neither file exists (the default for some Linux systems, like Ubuntu and Debian), then all users may use [C]crontab[/C]. [C]cron[/C] is surprisingly versatile and complex, and there's an [C]anacron[/C] thingy for me to read about too :whee: |
[QUOTE=jvang;495268][C]cron[/C] is surprisingly versatile and complex[/QUOTE]
[CODE]@reboot ~/prime/mprime -d </dev/null >>~/prime/mprime.log 2>/dev/null & 4,14,24,34,44,54 * * * * ~/mfaktc/submit_spider ~/mfaktc/ >/dev/null[/CODE] FWIW.... |
[QUOTE=chalsall;495272][CODE]submit_spider[/QUOTE]
What's that? :ermm: I think I got the gist of the rest of your code (run mprime on startup). Apparently [C]cat[/C] has a similar command, [C]tac[/C]. I can see how it would be useful, if a log file recorded from past to present with the latest entries at the bottom. But I can't see a good use for [C]rev[/C]; when would you need that other than to reverse what has already been reversed? |
[QUOTE=jvang;495268]How would one go about constructing this sort of function, or modify mine to fix the error? :unsure:[/QUOTE]
If you want to approach it in this way, adjust your code to something like this: [CODE] makeList5 :: String->[String] makeList5 str = if length str < 5 then [] else (take 5 str):makeList5 (tail str)[/CODE] |
| All times are UTC. The time now is 21:53. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.