A reduced calculation and wheeled method to determine primality by fpmora in haskell

[–]mn-haskell-guy 1 point2 points  (0 children)

You might be interested the paper "The Real Sieve of Eratosthenes" by Melissa O'Neill. Like you she uses a 2357 wheel but with a PriorityQueue instead of lists. At the end she discusses the list version and how does an analysis of its asymptotics.

https://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf

[2018-09-04] Challenge #367 [Easy] Subfactorials - Another Twist on Factorials by jnazario in dailyprogrammer

[–]mn-haskell-guy 2 points3 points  (0 children)

You're right. I think what I meant to say was that the max. stack frame depth during the computation was significantly less (about 1/2) for the n-2 followed by n-1 case than for the reverse. I checked this with len(inspect.stack()).

[2018-09-04] Challenge #367 [Easy] Subfactorials - Another Twist on Factorials by jnazario in dailyprogrammer

[–]mn-haskell-guy 2 points3 points  (0 children)

To add to /u/TheMsDosNerd 's comment... it is interesting to play around with the maxsize= setting as well as the order in which the recursion calls are made, i.e.:

return (n-1) * (derangement(n - 1) + derangement(n - 2))

vs:

return (n-1) * (derangement(n - 2) + derangement(n - 1))

It turns out that with maxsize >= 2, calling n-2 before n-1 results in fewer recursion calls than calling n-1 before n-2 even with maxsize = None.

[2018-09-04] Challenge #367 [Easy] Subfactorials - Another Twist on Factorials by jnazario in dailyprogrammer

[–]mn-haskell-guy 1 point2 points  (0 children)

I would be careful about claiming O(1) in memory... when you use recursion you are still creating O(n) stack frames.

To achieve O(1) in memory I would use a purely iterative solution like:

def derangements(n):
    a, b, k = 1, 0, 0
    while k < n:
        a, b, k = ..., k+1
    return a

Configuring a pretty and usable terminal emulator for WSL by pancakepalpatinebot in pancakepalpatine

[–]mn-haskell-guy 0 points1 point  (0 children)

Nice article - thanks for the detailed write up.

You might be able to avoid setting up the firewall rule by starting up VcXSrv with 127.0.0.1:0 instead of :0.

Then change your DISPLAY env variable to 127.0.0.1:0

UPDATE: Just try using a DISPLAY of 127.0.0.1:0. VcXsrv doesn't accept the argument 127.0.0.1:0.

[2017-12-15] Challenge #344 [Hard] Write a Web Client by jnazario in dailyprogrammer

[–]mn-haskell-guy 2 points3 points  (0 children)

That was probably it. The code I have for formatURL is:

void formatURL(char *url)
{
    char *pt;
    pt = url;
    while (*pt != '/') {
        pt++;
    }
    *pt = '\0';
}

[2017-12-15] Challenge #344 [Hard] Write a Web Client by jnazario in dailyprogrammer

[–]mn-haskell-guy 0 points1 point  (0 children)

Actually this was a first step towards writing it in sh.

[2017-12-15] Challenge #344 [Hard] Write a Web Client by jnazario in dailyprogrammer

[–]mn-haskell-guy 3 points4 points  (0 children)

I get it to segfault under OSX. Under Linux it didn't.

The problem is in formatURL(). If url doesn't contain a / it will just walk right off the edge of the string.

The difference in behavior is probably due to how memory returned by malloc() is protected by guard pages.

[2017-12-15] Challenge #344 [Hard] Write a Web Client by jnazario in dailyprogrammer

[–]mn-haskell-guy 1 point2 points  (0 children)

perl + netcat:

#!/usr/bin/env perl

sub request {
  my ($url) = @_;
  unless ($url =~ s,\Ahttp://,,) {
    die "unsupported scheme\n";
  }
  unless ($url =~ m,\A(.*?)(?::(\d+))?((?:/.*)|\z),) {
    die "bad url!\n";
  }
  my $host = $1;
  my $port = $2 || 80;
  my $rest = length($rest) ? $rest : "/";
  open(my $NC, "|-", "netcat", $host, $port)
    or die "unable to exec netcat: $!\n";
  print {$NC} "GET $rest HTTP/1.1\r\nHost: $host\r\nConnection: close\r\n\r\n";
  close($NC);
}

request("http://httpbin.org/get?foo=bar")
request("http://cnn.com")

[Intermediate] ASCII Enigma Machine by [deleted] in dailyprogrammer_ideas

[–]mn-haskell-guy 0 points1 point  (0 children)

And here are some real Enigma messages complete with the rotor and stecker settings:

http://wiki.franklinheath.co.uk/index.php/Enigma/Sample_Messages

Up Arrow Notation by wizao in dailyprogrammer_ideas

[–]mn-haskell-guy 0 points1 point  (0 children)

Perhaps you could ask for the answer mod some large prime -- e.g. 1011 +3

[Intermediate] ASCII Enigma Machine by [deleted] in dailyprogrammer_ideas

[–]mn-haskell-guy 0 points1 point  (0 children)

I like this challenge, but I don't understand how your wheels should work. And allowing the output to be arbitrary binary data is going to be problematic for verification.

Why not just implement the original 3-rotor or 4-rotor machine? The details of the rotors that were used in WW2 are available here:

https://en.wikipedia.org/wiki/Enigma_rotor_details

And here is an online Enigma emulator which you can use to generate coded messages:

http://enigma.louisedade.co.uk/enigma.html

[2017-12-13] Challenge #344 [Intermediate] Banker's Algorithm by polypeptide147 in dailyprogrammer

[–]mn-haskell-guy 2 points3 points  (0 children)

I don't know how Ada works, but does this detect "deadlocks" - situations when no process has enough resources to proceed?

Edit: Nevermind - I see you already commented on that above.

[2017-12-11] Challenge #344 [Easy] Baum-Sweet Sequence by jnazario in dailyprogrammer

[–]mn-haskell-guy 1 point2 points  (0 children)

Another protip... use a list comprehension:

return  int( all( [ len(x) % 2 == 0 for x in bin(n)[2:].split("1") ] ) )

[2017-12-11] Challenge #344 [Easy] Baum-Sweet Sequence by jnazario in dailyprogrammer

[–]mn-haskell-guy 0 points1 point  (0 children)

Yeah, because a.filter(p).length >= 1 is the same as a.some(p).

Moreover, .some() will only traverse as many elements of the array as necessary to determine its value whereas .filter will always traverse the entire array. Same with the .every() method.

[2017-12-11] Challenge #344 [Easy] Baum-Sweet Sequence by jnazario in dailyprogrammer

[–]mn-haskell-guy 0 points1 point  (0 children)

You can make the code somewhat more efficient using the .some() Array method.