Skip to content

Instantly share code, notes, and snippets.

@jeremyheiler
Last active August 29, 2015 13:58
Show Gist options
  • Save jeremyheiler/10015006 to your computer and use it in GitHub Desktop.
Save jeremyheiler/10015006 to your computer and use it in GitHub Desktop.
USING: kernel math math.functions sequences ;
IN: euler1
: euler1 ( x -- y )
iota [ dup [ 3 divisor? ] [ 5 divisor? ] bi or [ drop 0 ] unless ] map-sum ;
@jeremyheiler
Copy link
Author

Thanks! Appreciate it.

  1. Is there a good way to search for things? I'm using the offline help, but I feel like it's hard to find things unless I know exactly what I'm looking for, or am able to know what vocabulary to look in.
  2. Duh. I'm not sure what I was thinking. It took me a while to find iota, as I was thinking "range" the whole time (a la Clojure). Though, I guess I didn't dive too hard because I didn't see [1,b].
    3 & 4. Excellent.

@elasticdog
Copy link

You bet! If you keep posting gists, I'd be glad to review stuff.

The online documentation is a bit easier to search because it has all of the vocabularies loaded, where your local image won't. There are words like apropos, see, about and so on to help explore, but discoverability is admittedly a bit difficult. The docs are great, but it's still hard to narrow things down if you don't know what you're looking for...but that gets easier. Scanning through the "Vocabulary Index" in the help can give you a good idea of the types of stuff that's covered, and also -completing things while paying attention to the stack effect declaration displayed at the bottom of the listener can also be useful. The #concatenative chatroom is also helpful and friendly folks are always willing to review code and offer advice.

http://elasticdog.com/2008/12/beginning-factor-shufflers-and-combinators/#iota 😄

Using numeric ranges can be handy; my first attempt at this problem (from many years ago) looked like:

: euler1 ( x -- y )
    0 999 3 <range> sum 0 999 5 <range> sum + 0 999 15 <range> sum - ;

@jeremyheiler
Copy link
Author

Thanks again!

That's a clever way to solve the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment