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)

Xyzzy 2018-07-22 01:02

Right now we are just messing around with the numbers to see if a pattern pops up.

Is this interesting?[CODE]Prelude> solution x = sum [0,3..x] + sum [0,5..x] - sum [0,15..x]

Prelude> [solution x / x^2 | x <- [10,100,1000,10000,100000,1000000,10000000]]
[0.18,0.2313,0.233163,0.23331663,0.2333316663,0.233333166663,0.23333331666663]
[/CODE]:mike:

jvang 2018-07-22 03:24

[QUOTE=xilman;492205]Hint: 6 = 2*3[/QUOTE]

Hmm...

Through a combination of using the GHCi and some Google (whee [URL="https://stackoverflow.com/questions/2177781/how-to-calculate-modulus-of-large-numbers"]StackOverflow[/URL]!) I've learned quite a bit about modulo, but the link is pretty confusing to me... the gist I got from that and some [URL="https://stackoverflow.com/questions/26014318/trying-to-better-understand-modulo-calculation"]other links[/URL] is that breaking down the input and using mod on the little parts and appending the result to the other part ends up equivalent to taking the modulus of the larger number.

I'm not really sure of how to translate this to Haskell; I can get an input Integer or Int to a list of digits, but I don't know how to properly use recursion to take the modulus of the first element and append the next one to it...

Learned a bit about working with Maybe types. Just is weird to get used to, but there's fromJust (import Data.Maybe) to help you work with other types. There's also listToMaybe, returning Nothing for an empty list and the first element for other cases (in Maybe format). I ended up using both in [URL="https://www.codewars.com/kata/57da7f901b5ff148ad00030d"]Sum of Integer Justs and Nothings[/URL]. Turns out everyone else had reasonably simple solutions, whereas mine is a weird list comprehension...

[CODE]module SumOfJustsAndNothings where
import Data.Maybe
sumJusts :: [Maybe Integer] -> Maybe Integer
sumJusts [Nothing] = Just 0
sumJusts x = listToMaybe ((sum (map fromJust [n | n <- x, n /= Nothing])):[])[/CODE]

[QUOTE=Xyzzy;492254]We are having trouble with this: [url]https://www.codewars.com/kata/multiples-of-3-and-5-redux[/url][/QUOTE]

I ended up with two solutions to this that work. One is kinda weird and I don't fully understand it, but the other one is slightly simpler. I think that it uses simple relational algebra (or just algebraic relations, not too sure about this). One thing I saw that was common between mine and a lot of the other solutions is using a where statement to define new functions, or just defining them outside of a where statement. I need to look into this more :jvang:

@R. Gerbicz, I noticed that, while starting up mprime on my desktop, your name was associated with the PRP error-checking. I presume that you had something to do with that? :grin:

Nick 2018-07-22 07:20

[QUOTE]Right now we are just messing around with the numbers to see if a pattern pops up.[/QUOTE]Let n be a positive integer, and \( s=1+2+3+\ldots +n\).
Then we also have \( s=n+(n-1)+(n-2)+\ldots +3+2+1\).
What happens if we add up corresponding terms on the right?
\[\begin{eqnarray*}
1+n & = & n+1 \\
2+(n-1) & = & n+1 \\
3+(n-2) & = & n+1 \\
\vdots \\
(n-1)+2 & = & n+1 \\
n+1 & = & n+1 \\
\end{eqnarray*}\]
So it follows that
\[ 2s=\underbrace{(n+1)+(n+1)+\ldots +(n+1)}_{n} = n(n+1) \]
hence
\[ s=\frac{n(n+1)}{2}. \]
Now multiply everything by 3 or by 5...

xilman 2018-07-22 14:18

[QUOTE=jvang;492272]Hmm...[/QUOTE]My hint was about evaluating x^6 in fewer than five multiplications. The naive way is x^6 = x*x*x*x*x*x which uses five.

However, x^6 = (x^2)^3 (my hint). Let y=x*x (one multiplication) and then evaluate its cube y*y*y (two more multiplications).

Three multiplications altogether.

jvang 2018-07-23 02:34

[QUOTE=Nick;492280]Now multiply everything by 3 or by 5...[/QUOTE]

Wow, that's some nice math. I can see clearly now!

[QUOTE=xilman;492296]My hint was about evaluating x^6 in fewer than five multiplications. The naive way is x^6 = x*x*x*x*x*x which uses five.

However, x^6 = (x^2)^3 (my hint). Let y=x*x (one multiplication) and then evaluate its cube y*y*y (two more multiplications).

Three multiplications altogether.[/QUOTE]

Oh. How did I not see that? I really need to go back over some of my fundamentals :bangheadonwall:

So reducing the number of multiplications is not only smarter, but maybe also faster for a computer to do? The other trick with modulo is [I]much[/I] faster, so I was thinking about how this would affect a program.

The cons (:) operator has a lot of uses, from (x:xs) syntax to converting data into list form with :[]. The whole syntactic sugar thing is interesting...

Going to Denver, Colorado. We stopped in Wichita, Kansas for the night and will get to the hotel in Aurora tomorrow.

R. Gerbicz 2018-07-23 18:46

[QUOTE=jvang;492272]
@R. Gerbicz, I noticed that, while starting up mprime on my desktop, your name was associated with the PRP error-checking. I presume that you had something to do with that? :grin:[/QUOTE]

Yeah, I've discovered it, for the original discussion see [url]http://mersenneforum.org/showthread.php?t=22471&p=465431[/url].
And this also mentioned at [url]https://www.mersenne.org/[/url] .

jvang 2018-07-25 16:34

[QUOTE=R. Gerbicz;492360]Yeah, I've discovered it, for the original discussion see [url]http://mersenneforum.org/showthread.php?t=22471&p=465431[/url].
And this also mentioned at [url]https://www.mersenne.org/[/url] .[/QUOTE]

Oh, that looks complicated...neat though! That was a pretty recent development. From what I could comprehend from part of that thread, your check made the first checks much more accurate?

henryzz 2018-07-26 16:14

Discovered the trace function in Haskell today. It is very useful when debugging code in codewars as it allows you to output a string to the stderr while also returning something.

henryzz 2018-07-26 21:10

[url]https://www.codewars.com/kata/harshad-or-niven-numbers/haskell[/url] is a nice challenging puzzle.

chalsall 2018-07-26 21:24

Just to share...

An angle investor of mine made sure I took notes. He yelled at me if I forgot to do this. (And please trust me, that dude was just a little bit scary!)

The below are notes I took today, because of a complete connectivity outage.

[quote]Trouble Ticket Number 20180726.1125 -- 442 5448

Technician arrived ~1510.

Confirmed signal wasn't being received at the CPE.
Confirmed signal wasn't being received at the demarcation point (after running away because it briefly rained while I weeded).
Placed a signal injector Service Provider direction at the demarcation point, and then went hunting for the break without another word.


1519 -- Climbed the immediate pole, didn't appear to find the break.


1537 -- Still at the pole; lots of banging...


1550 -- Was trying to open the Neighbour's star box. I said "Could I please ask you not to do that.

"I can't find the cable on the pole.

"Well, you won't find it there. The fibre for that house runs straight from the demarcation point to inside the house which I don't have access to. Why don't you test the connectivity at the demarcation point?

He does. Finds light.

"I still can't find your connection; I've pulled on all the cables and I haven't found it.

"I'm an experienced network technician. Please let me help. Why don't you go over to the pole and pull.

He does. "Did you feel a pull?" he asks. "Yes, this one" and I pull back.

This proves the fibre run hasn't been crushed, and presents to him the exact fibre run he needs to deal with.

"Thanks!" he says, and then climbs back up the pole clipping at things I can't see.

Still, as of 1605, don't have connectivity...

(This would be funny if it wasn't so sad. The guy seems to be trying, but doesn't have a clue what he is doing...)


1610 -- He determined that he needed to replace the fiber run from the pole to the demarcation point because he wasn't getting a back-signal.

He used the existing fibre run as a pull for the new run. This again demonstrates that the fibre cable wasn't crushed.

I offered to help, having had experience pulling cable. Because of my bad back I instructed him to pull, and I'll feed.

I also offered him a bottle of soda water, which he gladly accepted.

We successfully pulled the cable at 1624.

I said to him "be careful; the cable is about to get a bit twisted if you pull any more.

He said "Be careful with that, you don't want to bend it.

No shit, sherlock...


1642 -- The guy is still working. And I still don't have any connectivity.


1706 -- Connectivity restored. It ended up being bad splice on the last metre to the demarcation point.[/quote]

jvang 2018-07-30 01:36

[QUOTE=henryzz;492535][url]https://www.codewars.com/kata/harshad-or-niven-numbers/haskell[/url] is a nice challenging puzzle.[/QUOTE]

Hmm, that one's interesting...

School starts in two weeks, so I'll be setting up my personal laptop. All I should need is a word processor (LibreOffice or some online thingy like Google Docs) and internet access, so I think I'll stick with OpenSUSE Leap. It looks fine and should be really stable.


All times are UTC. The time now is 10:06.

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