Skip to content

Factor solution example to some Project Euler problems

Notifications You must be signed in to change notification settings

my-LinkedIn/project-euler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 

Repository files navigation

A glimpse of Factor or solving problem almost with just oneliner code

Factor is a concatenative, stack-based programming language with high-level features.

I just used Online Factor Compiler to harness them. Feel free to do the same... it's just a Copy and Paste away. Enjoy!

I begin now to have a good grasp of what the Forth language is like... I just remember it was cited among others outstanding ones in our Computer Science primer course years ago.

Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve... Math'n code 😉

The joy of weekend Coding or Recreational programming ❤️❤️❤️

Problem #1

! Multiples of 3 or 5
! https://projecteuler.net/problem=1

USING: kernel math prettyprint sequences ;
1000 <iota> [ [ 5 mod ] [ 3 mod ] bi [ 0 = ] either? ] filter sum .

Problem #2

! Even Fibonacci Numbers
! https://projecteuler.net/problem=2

USING: kernel math prettyprint sequences ;
4,000,000 [ 1 0 ] dip '[ [ + ] 2keep dup _ < ] [ ] produce 3nip [ even? ] filter sum .

Problem #3

! Largest Prime Factor
! https://projecteuler.net/problem=3

USING: math.primes.factors prettyprint sequences ;
600851475143 factors last .

Problem #5

! Smallest Multiple
! https://projecteuler.net/problem=5

USING: math.functions ranges sequences ;
20 [1..b] 1 [ lcm ] reduce

Problem #6

! Sum Square Difference
! https://projecteuler.net/problem=6

USING: kernel math ranges sequences ;
100 [1..b] [ 0 [ sq + ] reduce ] [ sum sq ] bi - abs

Problem #7

! 10001st Prime
! https://projecteuler.net/problem=7

USING: lists math.primes.lists prettyprint ;
10001 lprimes lnth .

Problem #10

! Summation of Primes
! https://projecteuler.net/problem=10

USING: math.primes prettyprint sequences ;
2000000 primes-upto sum .

Problem #15

! Lattice Paths
! https://projecteuler.net/problem=15

USING: kernel math math.combinatorics prettyprint ;
20 dup 2 * swap nCk .

Problem #16

! Power Digit Sum
! https://projecteuler.net/problem=16

USING: math.functions math.parser prettyprint sequences ;
2 1000 ^ number>string string>digits sum .

Problem #17

! Number Letter Counts
! https://projecteuler.net/problem=17

USING: ascii kernel math.text.english prettyprint ranges sequences ;
1000 [1..b] SBUF" " clone [ number>text append! ] reduce [ Letter? ] count .

Problem #19

! Counting Sundays
! https://projecteuler.net/problem=19

USING: calendar kernel prettyprint ranges sequences ;
1901 2000 [a..b] [ 12 [1..b] [ 1 (day-of-week) ] with map ] map concat [ 0 = ] count .

Problem #20

! Factorial Digit Sum
! https://projecteuler.net/problem=20

USING: kernel math math.factorials math.parser prettyprint sequences ;    
100 factorial number>string string>digits sum .