But can it do this?
    
    
        for n <- 10..98,
            k <- (n + 1)..99,
            rem(n, 10) != 0 && rem(k, 10) != 0,
            d = gcd(n, k),
            d > 1,
            dn = digits(n),
            dk = digits(k),
            {a, b} <- intersection(dn, dk),
            a != 0,
            nr = div(n, d),
            kr = div(k, d),
            dab = gcd(a, b),
            ar = div(a, dab),
            br = div(b, dab),
            nr == ar && kr == br do
          {n, k, a, b}
        end
    
    
    Run

from Elixir (taken from 
<https://github.com/greenfork/project_euler/blob/master/problem33.exs)>.

General ideas:

  * Several iterating variables, definition at any time in the comprehension
  * Assignments, checks - all is done linearly



In Nim it would be the following: 
    
    
    collect(newSeq):
      for n in 10..98:
        for k in (n+1)..99:
          if n mod 10 != 0 and k mod 10 != 0:
            let d = gcd(n, k)
            if d > 1:
              let
                dn = digits(n)
                dk = digits(k)
              for (a, b) in intersection(dn, dk):
                if a != 0:
                  let
                    nr = n div d
                    kr = k div d
                    dab = gcd(a, b)
                    ar = a div dab
                    br = b div dab
                  if nr == ar and kr == br:
                    (n, k, a, b)
    
    
    
    Run

Nim variant is "more powerful" because we can do literally anything inside it 
and it is much harder to understand because during list comprehension we don't 
really want to do "literally anything", just a set of common actions.

Reply via email to