mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   jvang (https://www.mersenneforum.org/forumdisplay.php?f=153)
-   -   ¿Learning how to learn… (https://www.mersenneforum.org/showthread.php?t=23429)

jvang 2018-09-05 00:28

[QUOTE=Nick;495313]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][/QUOTE]

Hmm, I guess I did my [C]if[/C] statement incorrectly. How is the cons operator working with a list to its left? I thought it was of the type [C]a -> [a] -> [a][/C]…

Well, I got stuck on another point; the makeList5 function outputs a list of strings; I tried mapping map digitToInt and mapping read, and neither worked... How are you supposed to make that work? Some StackExchange answers said to use :: to define the type of read manually, but that makes the errors longer :jvang:

I showed my dad the math stuff to see if it helped; @masser's helped the most. I showed him that we can say that [$]z = y - x[/$] and substitute that into the original equations. The classwork was dealing with negation of individual numbers, and he got confused when they jumped to more complicated numbers. Thanks for the help!

He did notice two irregularities in your suggestions:

[QUOTE=axn;495187]How about a numeric example?

3 - 4 = 1
4 - 3 = -1
?[/QUOTE]

:ermm:

[QUOTE=LaurV;495189]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.[/QUOTE]

If the buckets hold quantities such that [$]12a = 11b[/$], then [$]12a + a \neq 11b + b[/$], but [$]12a + a = 11b + a[/$] or [$]12a + b = 11b + b[/$]. But perhaps I'm being a bit nitpicky :razz:

axn 2018-09-05 02:39

[QUOTE=jvang;495377]He did notice two irregularities in your suggestions:



:ermm:
[/QUOTE]

:missingteeth:

LaurV 2018-09-05 03:35

[QUOTE=jvang;495377]But perhaps I'm being a bit nitpicky :razz:[/QUOTE]
You are! :razz: You missed the part where I say "the quantities being equal". Not the weights, volumes, other parameters. 12 is not equal to 11. It may be that the weight of 12 apples is the weight of 11 oranges, but it was not what I said.

xilman 2018-09-05 08:58

[QUOTE=jvang;495285]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]You would be surprised...

Consider something like [C]rev | sort | rev[/C] which I've done moderately often to sort a file from the right rather than the left. Another idiom is [C]rev | colrm 7 | rev[/C] to keep at most the last six characters of each line, no matter how long each line may be.

Doubtless other uses will come to you now that you've been given a couple of hints.

Nick 2018-09-05 09:27

[QUOTE=jvang;495377]Hmm, I guess I did my [C]if[/C] statement incorrectly. How is the cons operator working with a list to its left? I thought it was of the type [C]a -> [a] -> [a][/C]…
[/QUOTE]
You're right, but "a" can be any type - including a list of something else!
[QUOTE=jvang;495377]
Well, I got stuck on another point; the makeList5 function outputs a list of strings; I tried mapping map digitToInt and mapping read, and neither worked... How are you supposed to make that work? Some StackExchange answers said to use :: to define the type of read manually, but that makes the errors longer :jvang:[/QUOTE]
You have 3 types here: characters, strings (which are lists of characters)
and lists of strings (which are list of lists of characters).
To keep things simple, don't work with all 3 at once, but split your code up so that you
are working with the first two or the last two only.
For this program, you could:
[LIST=1][*]Write a function product5::String->Int which takes a string of digits and returns their product;[*]then apply "map" to product5 and the output of your makeList5 function;[*]then take the maximum.[/LIST]

jvang 2018-09-06 00:42

[QUOTE=LaurV;495397]You are! :razz: You missed the part where I say "the quantities being equal". Not the weights, volumes, other parameters. 12 is not equal to 11. It may be that the weight of 12 apples is the weight of 11 oranges, but it was not what I said.[/QUOTE]

Alright, that seems more understandable :buddy:

[QUOTE=xilman;495412]You would be surprised...

Consider something like [C]rev | sort | rev[/C] which I've done moderately often to sort a file from the right rather than the left. Another idiom is [C]rev | colrm 7 | rev[/C] to keep at most the last six characters of each line, no matter how long each line may be.

Doubtless other uses will come to you now that you've been given a couple of hints.[/QUOTE]

I am surprised! I'd never have thought of that...

[QUOTE=Nick;495414]You're right, but "a" can be any type - including a list of something else!

You have 3 types here: characters, strings (which are lists of characters)
and lists of strings (which are list of lists of characters).
To keep things simple, don't work with all 3 at once, but split your code up so that you
are working with the first two or the last two only.
For this program, you could:
[LIST=1][*]Write a function product5::String->Int which takes a string of digits and returns their product;[*]then apply "map" to product5 and the output of your makeList5 function;[*]then take the maximum.[/LIST][/QUOTE]

Of course, now that I figured out how to do it this way, it didn't do what I needed it to do. Mapping [C]map digitToInt[/C] was more effective:

[CODE]module LargestProduct where
import Data.Char
greatestProduct :: String -> Int
greatestProduct str = maximum $ map product (map (map digitToInt) (makeList5 str))
makeList5 str = if length str < 5 then [] else (take 5 str):makeList5 (tail str)[/CODE]

Before I figured out that it was not going in the right direction, I had come up with about 4 different functions that I was stringing together :ermm:

I looked up "Linux user groups" and ended up reading about some non-profits or something when I was trying to figure out permissions. But there were a couple of helpful pages.

You can use [C]ls -l[/C] to see permissions on files; [URL="https://stackoverflow.com/questions/17578647/what-does-terminal-command-ls-l-show"]a helpful StackEnchange answer[/URL] details the meaning of each data point.

[QUOTE]The first letter in the permissions column show the file's type. A 'd' means a directory and a '-' means a normal file (there are other characters, but those are the basic ones).

The next nine characters are divided into 3 groups, each one a permission. Each letter in a group correspond to the read, write and execute permission, and each group correspond to the owner of the file, the group of the file and then for everyone else.

[ File type ][ Owner permissions ][ Group permissions ][ Everyone permissions ]

The characters can be one of four options:
r = read permission
w = write permission
x = execute permission
- = no permission[/QUOTE]

I'm guessing that "group of the file" refers to the group of the owner of the file?

jvang 2018-09-07 02:00

Working on a new kata, [URL="https://www.codewars.com/kata/compute-the-largest-sum-of-all-contiguous-subsequences"]Compute the Largest Sum of all Contiguous Subsequences[/URL]. I figured that I could use [C]tails[/C] and [C]inits[/C] to get all contiguous subsequences, but it's only returning some of them. I'm pretty sure that the code below returns contiguous subsequences that include either the first or last element, or nothing at all. How can I output the other subsequences, which tend to include the largest sums? I tried to use [C]drop[/C] and [C]take[/C], but I don't know how to accommodate random tests with random numbers of elements...

[CODE]module LargestSum where
import Data.List
largestSum :: [Int] -> Int
largestSum x = maximum (map maxx (map (map sum) $ tails (inits x)))
--largestSum x = maximum (map sum $ tails x ++ inits x) [C]this is alternate code that I think can replace the above, but I'm keeping both in case I'm wrong[/C]
maxx [] = 0
maxx x = maximum x[/CODE]

Nick 2018-09-07 07:56

[QUOTE=jvang;495517]How can I output the other subsequences, which tend to include the largest sums?[/QUOTE]
Writing tails(inits(x)), you are applying tails not to a list of integers but to a list of lists of integers.
If you want to use inits, try applying it to x then to tail x (not tails x) recursively.

henryzz 2018-09-07 08:33

[QUOTE=jvang;495455]
You can use [C]ls -l[/C] to see permissions on files; [URL="https://stackoverflow.com/questions/17578647/what-does-terminal-command-ls-l-show"]a helpful StackEnchange answer[/URL] details the meaning of each data point.



I'm guessing that "group of the file" refers to the group of the owner of the file?[/QUOTE]

You might find [url]https://unix.stackexchange.com/questions/137703/difference-between-ls-l-and-ll[/url] useful. ll is an alias for ls -l on most systems.

I am not sure whether the owner actually has to be part of the group although they usually will be.

jvang 2018-09-08 01:16

[QUOTE=Nick;495535]Writing tails(inits(x)), you are applying tails not to a list of integers but to a list of lists of integers.
If you want to use inits, try applying it to x then to tail x (not tails x) recursively.[/QUOTE]

Mapping [C]inits[/C] to [C]tails[/C] was all that I needed. Thanks for pointing that out!

[QUOTE=henryzz;495539]You might find [url]https://unix.stackexchange.com/questions/137703/difference-between-ls-l-and-ll[/url] useful. ll is an alias for ls -l on most systems.[/QUOTE]

On my Kubuntu installation, [C]ll = ls -alF[/C], which brings up a bunch of information :max:

[URL="https://insights.stackoverflow.com/survey/2018"]This StackExchange developer survey results thingy[/URL] is a neat read, but very long. Expect to take 30 minutes to read it in its entirety!

Notable mention: the average annual salary of Haskell developers in the US is ~$100k! :showoff: [SIZE="1"]Although it seems that many developers are making a lot of money...[/SIZE]

I'm reading about [C]/etc/fstab[/C], which seems pretty complex. I don't think I understand filesystems well enough to understand the idea of "mounting" a partition. [URL="https://help.ubuntu.com/community/Fstab"]The Ubuntu wiki page on [C]fstab[/C][/URL] states:

[QUOTE]In a nutshell, mounting is the process where a raw (physical) partition is prepared for access and assigned a location on the file system tree (or mount point).[/QUOTE]

What do they mean by a "raw" partition? Is that unformatted, inaccessible to the system, or something else?

It seems that the purpose of the [C]fstab[/C] configuration file is to define what is generally allowed to be mounted to the main filesystem. One of the bullet points mentions that, if a device is not specified in [C]fstab[/C], only root may mount it. However, the syntax for entries in the file looks pretty specific, and I don't understand it well enough to determine how likely one is to have a device that is not listed. The examples look complicated too :unsure:

Nick 2018-09-08 10:27

[QUOTE=jvang;495599]I don't think I understand filesystems well enough to understand the idea of "mounting" a partition.
What do they mean by a "raw" partition? Is that unformatted, inaccessible to the system, or something else?[/QUOTE]
On most modern Linux systems, the first hard disk is called sda, the second (if present) is called sdb, etc.
The partitions of the first hard disk are called sda1, sda2 etc.
These are the names by which the superuser can access them in the /dev directory, but only for reading or writing sectors of the partition as a whole.
That is why they are called raw devices.
For example, if your 3rd partition is the same size as your 2nd partition and you want to make it an exact copy (overwriting anything already present), you could give a command such as:

[CODE]dd if=/dev/sda2 of=/dev/sda3[/CODE]If the disk has a 4th partition and you want to format it, you could use something like this:
[CODE]mke2fs -t ext4 /dev/sda4[/CODE](Be warned: a single typo at this level can be enough to lose everything on your disks!)
Once the partition is formatted, you can create directories and files on it, but Linux/Unix systems do not use drive letters to specify disks/partitions:
instead, as superuser, you attach the new partition at some point on the existing directory tree by mounting it.
For example, after you have given the command:
[CODE]mount /dev/sda4 /mnt[/CODE]any user on your computer can create a file under "/mnt" and it will be stored in the root directory of the 4th partition.
All users can type "mount" (without arguments) to see what is mounted where.
The file /etc/fstab tells the computer what to mount when booting and (optionally) gives permission to ordinary users to perform certain mount commands.


All times are UTC. The time now is 21:53.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.