Saturday, November 16, 2013

Problem 63 - Rebol (a long sequence of redos)

This and the next few posts are actually going to be in the reverse order that I solved a set of problems, in order to keep with the technical rules of this challenge. Problem 66 involves solving Pell's Equation, which as some quick Wikipedia ready is enough to find out, is solved relatively easily using the convergent's of continued fractions.  So, I solved problem 66 in Python, reusing some of the code from Problem 65, then resolved problem 65 using Dart, as my solution was most portable to a nice language like dart with arbitrary precision integer arithmetic and classes, and then to fill the last hole, I solved problem 63 in Rebol.

Rebol is an interesting language...it's advertising scheme revolves around the fact that it is a very fast, very small (the compiler is <1 MB), and yet very powerful language...and though I didn't need to use too much of the arguable 'power' (most of which involves its capabilities for large-scale programs, including GUI stuff), it seems like a nice enough language, once you get past some of the odd syntax (everything is in square brackets, "either" replaces if-else, functions can be declared in multiple ways, though I still only understand the 'func' identifier (which is in some ways different from 'does')). Anyway, here is a solution, runs in about 20ms on my machine:
log-10: func [x] [return (log-e x) / (log-e 10)]

ans: 0
j: 1
b: 1
while [b < 10] [
    i: b
    while [i < 10] [
        digs: 1 + (to integer! (j * log-10 (i)))
        either digs = j [
            ans: ans + 1
        ] [
            b: i + 1
        ]
        i: i + 1
    ]
    j: j + 1
]
print ans

No comments:

Post a Comment