Skip to main content
added 516 characters in body
Source Link
johnk
  • 459
  • 2
  • 4

Rebol - 164 133 130 (139 with 404 check)

Parses the html using the parse sub-language of Rebol. Checks the first 98 pages. I realised I have the same constraint as the python solution (ignoring- too many repeats hit 404 errors) and stop the execution. Thanks to @rgchris for many improvements! Updated to check up to 98 pages.

s: 0 repeat n 99[parse read join http://stackoverflow.com/questions?sort=featured&page= n[15[thru{>+}copy x to{<}(s: s + do x)]]]s

With error checking for 404s (139):

s: 0 repeat n 99[attempt[parse read join http://stackoverflow.com/questions?sort=featured&page= n[15[thru{>+}copy x to{<}(s: s + do x)]]]]s

Test

>> s: 0 repeat n 20[parse read join http://stackoverflow.com/questions?sort=featured&page= n[15[thru{>+}copy x to{<}(s: s + do x)]]]s
== 23600

>> s: 0 repeat n 99[attempt[parse read join http://stackoverflow.com/questions?sort=featured&page= n[15[thru{>+}copy x to{<}(s: s + do x)]]]]s
Script: none Version: none Date: none
== 36050

Rebol - 164 133 130

Parses the html using the parse sub-language of Rebol. Checks the first 98 pages (ignoring errors). Thanks to @rgchris for many improvements! Updated to check up to 98 pages.

s: 0 repeat n 99[parse read join http://stackoverflow.com/questions?sort=featured&page= n[15[thru{>+}copy x to{<}(s: s + do x)]]]s

Test

>> s: 0 repeat n 20[parse read join http://stackoverflow.com/questions?sort=featured&page= n[15[thru{>+}copy x to{<}(s: s + do x)]]]s
== 23600

Rebol - 164 133 130 (139 with 404 check)

Parses the html using the parse sub-language of Rebol. Checks the first 98 pages. I realised I have the same constraint as the python solution - too many repeats hit 404 errors and stop the execution. Thanks to @rgchris for many improvements! Updated to check up to 98 pages.

s: 0 repeat n 99[parse read join http://stackoverflow.com/questions?sort=featured&page= n[15[thru{>+}copy x to{<}(s: s + do x)]]]s

With error checking for 404s (139):

s: 0 repeat n 99[attempt[parse read join http://stackoverflow.com/questions?sort=featured&page= n[15[thru{>+}copy x to{<}(s: s + do x)]]]]s

Test

>> s: 0 repeat n 20[parse read join http://stackoverflow.com/questions?sort=featured&page= n[15[thru{>+}copy x to{<}(s: s + do x)]]]s
== 23600

>> s: 0 repeat n 99[attempt[parse read join http://stackoverflow.com/questions?sort=featured&page= n[15[thru{>+}copy x to{<}(s: s + do x)]]]]s
Script: none Version: none Date: none
== 36050
added 33 characters in body; edited body
Source Link
johnk
  • 459
  • 2
  • 4

Rebol - 164 133 130

Parses the html using the parse sub-language of Rebol. Checks the first 1998 pages (ignoring errors). Thanks to @rgchris for many improvements! Updated to check up to 98 pages.

s: 0 repeat n 20[parse99[parse read join http://stackoverflow.com/questions?sort=featured&page= n[15[thru{>+}copy x to{<}(s: s + do x)]]]s

Test

>> s: 0 repeat n 20[parse read join http://stackoverflow.com/questions?sort=featured&page= n[15[thru{>+}copy x to{<}(s: s + do x)]]]s
== 23600

Explanation

Rebol ignores whitespace, hence you can put it all on one line like that if you choose. PARSE takes two inputs, and the first argument (read join ...) is fairly self-explanatory. But here are some comments on the parse dialect instructions, in a more traditional indentation:

s: 0
repeat n 2099 [
    parse read join http://stackoverflow.com/questions?sort=featured&page= n [
        ;-- match the enclosed pattern 15 times (the rule will fail politely when there are less entries)
        15 [
            ;-- seek the match position up THRU (and including) the string >+
            thru {>+}
            ;-- copy contents at the current position up TO (but not including) <
            copy x to {<}
            ;-- (Basically, run some non-dialected Rebol if this match point is reached) the do is a bit dangerous as it runs the string as code
            (s: s + do x)
        ]
    ]
]
;-- evaluator returns last value, we want the value in S
;-- (not the result of PARSE, that's a boolean on whether the end of input was reached)
s

Rebol - 164 133 130

Parses the html using the parse sub-language of Rebol. Checks the first 19 pages (ignoring errors). Thanks to @rgchris for many improvements!

s: 0 repeat n 20[parse read join http://stackoverflow.com/questions?sort=featured&page= n[15[thru{>+}copy x to{<}(s: s + do x)]]]s

Test

>> s: 0 repeat n 20[parse read join http://stackoverflow.com/questions?sort=featured&page= n[15[thru{>+}copy x to{<}(s: s + do x)]]]s
== 23600

Explanation

Rebol ignores whitespace, hence you can put it all on one line like that if you choose. PARSE takes two inputs, and the first argument (read join ...) is fairly self-explanatory. But here are some comments on the parse dialect instructions, in a more traditional indentation:

s: 0
repeat n 20 [
    parse read join http://stackoverflow.com/questions?sort=featured&page= n [
        ;-- match the enclosed pattern 15 times (the rule will fail politely when there are less entries)
        15 [
            ;-- seek the match position up THRU (and including) the string >+
            thru {>+}
            ;-- copy contents at the current position up TO (but not including) <
            copy x to {<}
            ;-- (Basically, run some non-dialected Rebol if this match point is reached) the do is a bit dangerous as it runs the string as code
            (s: s + do x)
        ]
    ]
]
;-- evaluator returns last value, we want the value in S
;-- (not the result of PARSE, that's a boolean on whether the end of input was reached)
s

Rebol - 164 133 130

Parses the html using the parse sub-language of Rebol. Checks the first 98 pages (ignoring errors). Thanks to @rgchris for many improvements! Updated to check up to 98 pages.

s: 0 repeat n 99[parse read join http://stackoverflow.com/questions?sort=featured&page= n[15[thru{>+}copy x to{<}(s: s + do x)]]]s

Test

>> s: 0 repeat n 20[parse read join http://stackoverflow.com/questions?sort=featured&page= n[15[thru{>+}copy x to{<}(s: s + do x)]]]s
== 23600

Explanation

Rebol ignores whitespace, hence you can put it all on one line like that if you choose. PARSE takes two inputs, and the first argument (read join ...) is fairly self-explanatory. But here are some comments on the parse dialect instructions, in a more traditional indentation:

s: 0
repeat n 99 [
    parse read join http://stackoverflow.com/questions?sort=featured&page= n [
        ;-- match the enclosed pattern 15 times (the rule will fail politely when there are less entries)
        15 [
            ;-- seek the match position up THRU (and including) the string >+
            thru {>+}
            ;-- copy contents at the current position up TO (but not including) <
            copy x to {<}
            ;-- (Basically, run some non-dialected Rebol if this match point is reached) the do is a bit dangerous as it runs the string as code
            (s: s + do x)
        ]
    ]
]
;-- evaluator returns last value, we want the value in S
;-- (not the result of PARSE, that's a boolean on whether the end of input was reached)
s
added 95 characters in body
Source Link
johnk
  • 459
  • 2
  • 4

Rebol - 164 133133 130

Parses the html using the parse sub-language of Rebol. Checks the first 19 pages (ignoring errors). Thanks to @rgchris for many improvements!

s: 0 repeat n 20[parse read join http://stackoverflow.com/questions?sort=featured&page= n[any[thrun[15[thru{>+}copy x to{<}(s: s + loaddo x)]]]s

Test

>> s: 0 repeat n 20[parse read join http://stackoverflow.com/questions?sort=featured&page= n[any[thrun[15[thru{>+}copy x to{<}(s: s + loaddo x)]]]s
== 2415023600

Explanation

Rebol ignores whitespace, hence you can put it all on one line like that if you choose. PARSE takes two inputs, and the first argument (read join ...) is fairly self-explanatory. But here are some comments on the parse dialect instructions, in a more traditional indentation:

s: 0
repeat n 20 [
    parse read join http://stackoverflow.com/questions?sort=featured&page= n [
        ;-- match the enclosed pattern ANY15 times (zerothe orrule morewill numberfail ofpolitely timeswhen there are less entries)
        any15 [
            ;-- seek the match position up THRU (and including) the string >+
            thru {>+}
            ;-- copy contents at the current position up TO (but not including) <
            copy x to {<}
            ;-- (Basically, run some non-dialected Rebol if this match point is reached) the do is a bit dangerous as it runs the string as code
            (s: s + loaddo x)
        ]
    ]
]
;-- evaluator returns last value, we want the value in S
;-- (not the result of PARSE, that's a boolean on whether the end of input was reached)
s

Rebol - 164 133

Parses the html using the parse sub-language of Rebol. Checks the first 19 pages (ignoring errors). Thanks to @rgchris for improvements!

s: 0 repeat n 20[parse read join http://stackoverflow.com/questions?sort=featured&page= n[any[thru{>+}copy x to{<}(s: s + load x)]]]s

Test

>> s: 0 repeat n 20[parse read join http://stackoverflow.com/questions?sort=featured&page= n[any[thru{>+}copy x to{<}(s: s + load x)]]]s
== 24150

Explanation

Rebol ignores whitespace, hence you can put it all on one line like that if you choose. PARSE takes two inputs, and the first argument (read join ...) is fairly self-explanatory. But here are some comments on the parse dialect instructions, in a more traditional indentation:

s: 0
repeat n 20 [
    parse read join http://stackoverflow.com/questions?sort=featured&page= n [
        ;-- match the enclosed pattern ANY (zero or more number of times)
        any [
            ;-- seek the match position up THRU (and including) the string >+
            thru {>+}
            ;-- copy contents at the current position up TO (but not including) <
            copy x to {<}
            ;-- (Basically, run some non-dialected Rebol if this match point is reached)
            (s: s + load x)
        ]
    ]
]
;-- evaluator returns last value, we want the value in S
;-- (not the result of PARSE, that's a boolean on whether the end of input was reached)
s

Rebol - 164 133 130

Parses the html using the parse sub-language of Rebol. Checks the first 19 pages (ignoring errors). Thanks to @rgchris for many improvements!

s: 0 repeat n 20[parse read join http://stackoverflow.com/questions?sort=featured&page= n[15[thru{>+}copy x to{<}(s: s + do x)]]]s

Test

>> s: 0 repeat n 20[parse read join http://stackoverflow.com/questions?sort=featured&page= n[15[thru{>+}copy x to{<}(s: s + do x)]]]s
== 23600

Explanation

Rebol ignores whitespace, hence you can put it all on one line like that if you choose. PARSE takes two inputs, and the first argument (read join ...) is fairly self-explanatory. But here are some comments on the parse dialect instructions, in a more traditional indentation:

s: 0
repeat n 20 [
    parse read join http://stackoverflow.com/questions?sort=featured&page= n [
        ;-- match the enclosed pattern 15 times (the rule will fail politely when there are less entries)
        15 [
            ;-- seek the match position up THRU (and including) the string >+
            thru {>+}
            ;-- copy contents at the current position up TO (but not including) <
            copy x to {<}
            ;-- (Basically, run some non-dialected Rebol if this match point is reached) the do is a bit dangerous as it runs the string as code
            (s: s + do x)
        ]
    ]
]
;-- evaluator returns last value, we want the value in S
;-- (not the result of PARSE, that's a boolean on whether the end of input was reached)
s
edited body
Source Link
johnk
  • 459
  • 2
  • 4
Loading
added 3 characters in body
Source Link
johnk
  • 459
  • 2
  • 4
Loading
deleted 127 characters in body
Source Link
johnk
  • 459
  • 2
  • 4
Loading
deleted 60 characters in body
Source Link
johnk
  • 459
  • 2
  • 4
Loading
edited body
Source Link
johnk
  • 459
  • 2
  • 4
Loading
Source Link
johnk
  • 459
  • 2
  • 4
Loading