]> gitweb.factorcode.org Git - factor.git/commitdiff
project-euler: Rewrap, update links, add copyrights, tests
authorGiftpflanze <gifti@tools.wmflabs.org>
Fri, 8 Sep 2023 12:53:55 +0000 (14:53 +0200)
committerGiftpflanze <gifti@tools.wmflabs.org>
Fri, 8 Sep 2023 12:53:55 +0000 (14:53 +0200)
111 files changed:
extra/project-euler/001/001.factor
extra/project-euler/002/002.factor
extra/project-euler/003/003.factor
extra/project-euler/004/004.factor
extra/project-euler/005/005.factor
extra/project-euler/006/006.factor
extra/project-euler/007/007.factor
extra/project-euler/008/008.factor
extra/project-euler/009/009.factor
extra/project-euler/010/010.factor
extra/project-euler/011/011.factor
extra/project-euler/012/012.factor
extra/project-euler/013/013.factor
extra/project-euler/014/014.factor
extra/project-euler/015/015.factor
extra/project-euler/016/016.factor
extra/project-euler/017/017.factor
extra/project-euler/018/018.factor
extra/project-euler/019/019.factor
extra/project-euler/020/020.factor
extra/project-euler/021/021.factor
extra/project-euler/022/022.factor
extra/project-euler/023/023.factor
extra/project-euler/024/024.factor
extra/project-euler/025/025.factor
extra/project-euler/026/026.factor
extra/project-euler/027/027.factor
extra/project-euler/028/028.factor
extra/project-euler/029/029.factor
extra/project-euler/030/030.factor
extra/project-euler/031/031.factor
extra/project-euler/032/032.factor
extra/project-euler/033/033.factor
extra/project-euler/034/034.factor
extra/project-euler/035/035.factor
extra/project-euler/036/036.factor
extra/project-euler/037/037.factor
extra/project-euler/038/038.factor
extra/project-euler/039/039.factor
extra/project-euler/040/040.factor
extra/project-euler/041/041.factor
extra/project-euler/042/042.factor
extra/project-euler/043/043.factor
extra/project-euler/044/044.factor
extra/project-euler/045/045.factor
extra/project-euler/046/046.factor
extra/project-euler/047/047.factor
extra/project-euler/048/048.factor
extra/project-euler/049/049.factor
extra/project-euler/050/050.factor
extra/project-euler/051/051.factor
extra/project-euler/052/052.factor
extra/project-euler/053/053.factor
extra/project-euler/054/054.factor
extra/project-euler/055/055.factor
extra/project-euler/056/056.factor
extra/project-euler/057/057.factor
extra/project-euler/058/058.factor
extra/project-euler/059/059.factor
extra/project-euler/060/060.factor
extra/project-euler/061/061.factor
extra/project-euler/061/authors.txt [new file with mode: 0644]
extra/project-euler/062/062.factor
extra/project-euler/063/063.factor
extra/project-euler/064/064-tests.factor [new file with mode: 0644]
extra/project-euler/064/064.factor
extra/project-euler/064/authors.txt [new file with mode: 0644]
extra/project-euler/065/065.factor
extra/project-euler/067/067.factor
extra/project-euler/069/069.factor
extra/project-euler/070/070.factor
extra/project-euler/071/071.factor
extra/project-euler/072/072.factor
extra/project-euler/073/073.factor
extra/project-euler/074/074.factor
extra/project-euler/075/075.factor
extra/project-euler/076/076.factor
extra/project-euler/079/079.factor
extra/project-euler/081/081.factor
extra/project-euler/085/085.factor
extra/project-euler/087/087-tests.factor [new file with mode: 0644]
extra/project-euler/087/087.factor
extra/project-euler/087/authors.txt [new file with mode: 0644]
extra/project-euler/089/089.factor
extra/project-euler/092/092.factor
extra/project-euler/097/097.factor
extra/project-euler/099/099.factor
extra/project-euler/100/100.factor
extra/project-euler/102/102.factor
extra/project-euler/112/112.factor
extra/project-euler/116/116.factor
extra/project-euler/117/117.factor
extra/project-euler/124/124.factor
extra/project-euler/134/134.factor
extra/project-euler/148/148.factor
extra/project-euler/150/150.factor
extra/project-euler/151/151.factor
extra/project-euler/164/164.factor
extra/project-euler/169/169.factor
extra/project-euler/173/173.factor
extra/project-euler/175/175.factor
extra/project-euler/186/186.factor
extra/project-euler/188/188.factor
extra/project-euler/190/190.factor
extra/project-euler/203/203.factor
extra/project-euler/206/206.factor
extra/project-euler/215/215.factor
extra/project-euler/255/255.factor
extra/project-euler/265/265.factor
extra/project-euler/463/463.factor
extra/project-euler/508/508.factor

index 75cab48c8f32882a2cc3090cde6de9c71a856684..2c5879d4862c9869ddf42c9d8e32534c4f4c21e7 100644 (file)
@@ -1,16 +1,17 @@
 ! Copyright (c) 2007-2009 Aaron Schaefer, Slava Pestov.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: kernel math math.functions ranges project-euler.common sequences
-    sets ;
+USING: kernel math math.functions ranges project-euler.common
+sequences sets ;
 IN: project-euler.001
 
-! https://projecteuler.net/index.php?section=problems&id=1
+! https://projecteuler.net/problem=1
 
 ! DESCRIPTION
 ! -----------
 
-! If we list all the natural numbers below 10 that are multiples of 3 or 5, we
-! get 3, 5, 6 and 9. The sum of these multiples is 23.
+! If we list all the natural numbers below 10 that are multiples
+! of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is
+! 23.
 
 ! Find the sum of all the multiples of 3 or 5 below 1000.
 
index b1dbc7e0d098a7d6f7463c6a0ae56df2dba2fd9a..86e5b7cf22ac27f5bdc36e2252491ca28728d7fc 100644 (file)
@@ -3,18 +3,19 @@
 USING: kernel math sequences project-euler.common ;
 IN: project-euler.002
 
-! https://projecteuler.net/index.php?section=problems&id=2
+! https://projecteuler.net/problem=2
 
 ! DESCRIPTION
 ! -----------
 
-! Each new term in the Fibonacci sequence is generated by adding the previous
-! two terms. By starting with 1 and 2, the first 10 terms will be:
+! Each new term in the Fibonacci sequence is generated by adding
+! the previous two terms. By starting with 1 and 2, the first 10
+! terms will be:
 
 !     1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
 
-! Find the sum of all the even-valued terms in the sequence which do not exceed
-! four million.
+! Find the sum of all the even-valued terms in the sequence
+! which do not exceed four million.
 
 
 ! SOLUTION
index 8dccc10f9bf06ace5b01a61737c3ffcf79362972..f04c15cefc0f01b1d12b10d2b887b52471f00d76 100644 (file)
@@ -3,7 +3,7 @@
 USING: math.primes.factors sequences project-euler.common ;
 IN: project-euler.003
 
-! https://projecteuler.net/index.php?section=problems&id=3
+! https://projecteuler.net/problem=3
 
 ! DESCRIPTION
 ! -----------
index 5cc7a4d3097f5738405e5cf7a13349c4eb30f469..1116fe28e679a625fd762496b343609094b7f82c 100644 (file)
@@ -4,15 +4,17 @@ USING: kernel math math.functions project-euler.common ranges
 sequences sets sorting ;
 IN: project-euler.004
 
-! https://projecteuler.net/index.php?section=problems&id=4
+! https://projecteuler.net/problem=4
 
 ! DESCRIPTION
 ! -----------
 
-! A palindromic number reads the same both ways. The largest palindrome made
-! from the product of two 2-digit numbers is 9009 = 91 * 99.
+! A palindromic number reads the same both ways. The largest
+! palindrome made from the product of two 2-digit numbers is
+! 9009 = 91 * 99.
 
-! Find the largest palindrome made from the product of two 3-digit numbers.
+! Find the largest palindrome made from the product of two
+! 3-digit numbers.
 
 
 ! SOLUTION
index 6c76547f95029b3f8c773b40aba2dd47c51a832c..a495b2e7bb5fe8bacf54bcaecc95e84769643182 100644 (file)
@@ -3,15 +3,16 @@
 USING: math project-euler.common ranges sequences ;
 IN: project-euler.005
 
-! https://projecteuler.net/index.php?section=problems&id=5
+! https://projecteuler.net/problem=5
 
 ! DESCRIPTION
 ! -----------
 
-! 2520 is the smallest number that can be divided by each of the numbers from 1
-! to 10 without any remainder.
+! 2520 is the smallest number that can be divided by each of the
+! numbers from 1 to 10 without any remainder.
 
-! What is the smallest number that is evenly divisible by all of the numbers from 1 to 20?
+! What is the smallest number that is evenly divisible by all of
+! the numbers from 1 to 20?
 
 
 ! SOLUTION
index 16579c758e3d4e0731f6f27d808f733d1585a12b..8d3360b1b0c09b1f86c31b133dafaf6722b6337a 100644 (file)
@@ -3,7 +3,7 @@
 USING: kernel math ranges sequences project-euler.common ;
 IN: project-euler.006
 
-! https://projecteuler.net/index.php?section=problems&id=6
+! https://projecteuler.net/problem=6
 
 ! DESCRIPTION
 ! -----------
@@ -14,11 +14,12 @@ IN: project-euler.006
 ! The square of the sum of the first ten natural numbers is,
 !    (1 + 2 + ... + 10)² = 55² = 3025
 
-! Hence the difference between the sum of the squares of the first ten natural
-! numbers and the square of the sum is 3025 - 385 = 2640.
+! Hence the difference between the sum of the squares of the
+! first ten natural numbers and the square of the sum is 3025 -
+! 385 = 2640.
 
-! Find the difference between the sum of the squares of the first one hundred
-! natural numbers and the square of the sum.
+! Find the difference between the sum of the squares of the
+! first one hundred natural numbers and the square of the sum.
 
 
 ! SOLUTION
index e0876aa0911d65ab3e47d490888c0fa1216036f8..21cf1bbf849406357f108f5dc37b03a740ad4759 100644 (file)
@@ -3,13 +3,13 @@
 USING: project-euler.common ;
 IN: project-euler.007
 
-! https://projecteuler.net/index.php?section=problems&id=7
+! https://projecteuler.net/problem=7
 
 ! DESCRIPTION
 ! -----------
 
-! By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see
-! that the 6th prime is 13.
+! By listing the first six prime numbers: 2, 3, 5, 7, 11, and
+! 13, we can see that the 6th prime is 13.
 
 ! What is the 10001st prime number?
 
index 6f52810e5d5682437ed87b0585dad55e0c311ceb..2b24f7649c45ac38c33f6c32931a0f317c2ddcd2 100644 (file)
@@ -1,14 +1,16 @@
 ! Copyright (c) 2007, 2008 Aaron Schaefer.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: grouping math.order math.parser sequences project-euler.common ;
+USING: grouping math.order math.parser sequences
+project-euler.common ;
 IN: project-euler.008
 
-! https://projecteuler.net/index.php?section=problems&id=8
+! https://projecteuler.net/problem=8
 
 ! DESCRIPTION
 ! -----------
 
-! Find the greatest product of five consecutive digits in the 1000-digit number.
+! Find the greatest product of five consecutive digits in the
+! 1000-digit number.
 
 !     73167176531330624919225119674426574742355349194934
 !     96983520312774506326239578318016984801869478851843
index 93213ae0df9f9103056f7cf5a1ffe625bec5a64c..98b591762c3c0fec5a5ef41321a3036295ce66a6 100644 (file)
@@ -3,18 +3,19 @@
 USING: kernel make math sequences sorting project-euler.common ;
 IN: project-euler.009
 
-! https://projecteuler.net/index.php?section=problems&id=9
+! https://projecteuler.net/problem=9
 
 ! DESCRIPTION
 ! -----------
 
-! A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
+! A Pythagorean triplet is a set of three natural numbers, a < b
+! < c, for which,
 !     a² + b² = c²
 
 ! For example, 3² + 4² = 9 + 16 = 25 = 5².
 
-! There exists exactly one Pythagorean triplet for which a + b + c = 1000.
-! Find the product abc.
+! There exists exactly one Pythagorean triplet for which a + b +
+! c = 1000. Find the product abc.
 
 
 ! SOLUTION
index 241578b0d5082d12850a5ddf7786c4ee11b4b1c7..81c184b6f10a2bb8914f96f0a8c7ac4f64ee75c9 100644 (file)
@@ -3,7 +3,7 @@
 USING: math.primes sequences project-euler.common ;
 IN: project-euler.010
 
-! https://projecteuler.net/index.php?section=problems&id=10
+! https://projecteuler.net/problem=10
 
 ! DESCRIPTION
 ! -----------
index 82cca5b080f4ba772535ecd4a70b6e1e58f79fed..b0512ea4e48cbef2ba4ba77a327e8c5878babeec 100644 (file)
@@ -1,15 +1,16 @@
 ! Copyright (c) 2007, 2008 Aaron Schaefer.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: grouping kernel make math.order sequences project-euler.common ;
+USING: grouping kernel make math.order sequences
+project-euler.common ;
 IN: project-euler.011
 
-! https://projecteuler.net/index.php?section=problems&id=11
+! https://projecteuler.net/problem=11
 
 ! DESCRIPTION
 ! -----------
 
-! In the 20x20 grid below, four numbers along a diagonal line have been marked
-! in red.
+! In the 20x20 grid below, four numbers along a diagonal line
+! have been marked in red.
 
 !     08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
 !     49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
index effb2bc4834bc84dafae2ea05bb87a50d8221312..327ac5da00faf1732dcfcc48efaf3acafea87fd0 100644 (file)
@@ -3,14 +3,14 @@
 USING: kernel math project-euler.common ;
 IN: project-euler.012
 
-! https://projecteuler.net/index.php?section=problems&id=12
+! https://projecteuler.net/problem=12
 
 ! DESCRIPTION
 ! -----------
 
-! The sequence of triangle numbers is generated by adding the natural numbers.
-! So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first
-! ten terms would be:
+! The sequence of triangle numbers is generated by adding the
+! natural numbers. So the 7th triangle number would be 1 + 2 + 3
+! + 4 + 5 + 6 + 7 = 28. The first ten terms would be:
 
 !     1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
 
@@ -24,10 +24,11 @@ IN: project-euler.012
 !     21: 1,3,7,21
 !     28: 1,2,4,7,14,28
 
-! We can see that the 7th triangle number, 28, is the first triangle number to
-! have over five divisors.
+! We can see that the 7th triangle number, 28, is the first
+! triangle number to have over five divisors.
 
-! Which is the first triangle number to have over five-hundred divisors?
+! Which is the first triangle number to have over five-hundred
+! divisors?
 
 
 ! SOLUTION
index 11d5624efd13bb995a13586c1fef8281d37f83f1..1e398078d1b367d95bd9012523e7adcb3e2ef8f5 100644 (file)
@@ -3,13 +3,13 @@
 USING: math.parser sequences project-euler.common ;
 IN: project-euler.013
 
-! https://projecteuler.net/index.php?section=problems&id=13
+! https://projecteuler.net/problem=13
 
 ! DESCRIPTION
 ! -----------
 
-! Work out the first ten digits of the sum of the following one-hundred
-! 50-digit numbers.
+! Work out the first ten digits of the sum of the following
+! one-hundred 50-digit numbers.
 
 !     37107287533902102798797998220837590246510135740250
 !     46376937677490009712648124896970078050417018260538
index 49efd89ec22aee802031f300beec5840186cef07..0297644636a52779f72324d5f35ec58a425d8a77 100644 (file)
@@ -1,31 +1,35 @@
 ! Copyright (c) 2007 Aaron Schaefer.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: combinators.short-circuit kernel make math math.functions ranges
-    sequences project-euler.common ;
+USING: combinators.short-circuit kernel make math math.functions
+ranges sequences project-euler.common ;
 IN: project-euler.014
 
-! https://projecteuler.net/index.php?section=problems&id=14
+! https://projecteuler.net/problem=14
 
 ! DESCRIPTION
 ! -----------
 
-! The following iterative sequence is defined for the set of positive integers:
+! The following iterative sequence is defined for the set of
+! positive integers:
 
 !     n -> n / 2  (n is even)
 !     n -> 3n + 1 (n is odd)
 
-! Using the rule above and starting with 13, we generate the following
-! sequence:
+! Using the rule above and starting with 13, we generate the
+! following sequence:
 
 !     13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1
 
-! It can be seen that this sequence (starting at 13 and finishing at 1)
-! contains 10 terms. Although it has not been proved yet (Collatz Problem), it
-! is thought that all starting numbers finish at 1.
+! It can be seen that this sequence (starting at 13 and
+! finishing at 1) contains 10 terms. Although it has not been
+! proved yet (Collatz Problem), it is thought that all starting
+! numbers finish at 1.
 
-! Which starting number, under one million, produces the longest chain?
+! Which starting number, under one million, produces the longest
+! chain?
 
-! NOTE: Once the chain starts the terms are allowed to go above one million.
+! NOTE: Once the chain starts the terms are allowed to go above
+! one million.
 
 
 ! SOLUTION
index c5e4495dcf95749abec5f6c832fadb3ecaaf2e78..e1e5a539f382a61f5dbbe1f41b51d7f4268c0cf1 100644 (file)
@@ -3,13 +3,13 @@
 USING: kernel math math.combinatorics project-euler.common ;
 IN: project-euler.015
 
-! https://projecteuler.net/index.php?section=problems&id=15
+! https://projecteuler.net/problem=15
 
 ! DESCRIPTION
 ! -----------
 
-! Starting in the top left corner of a 2x2 grid, there are 6 routes (without
-! backtracking) to the bottom right corner.
+! Starting in the top left corner of a 2x2 grid, there are 6
+! routes (without backtracking) to the bottom right corner.
 
 ! How many routes are there through a 20x20 grid?
 
index 34298139d2ba20c1db184ea964341a2388f581cf..05442690e07c3414d1da8bc32f9a2d92de66c449 100644 (file)
@@ -3,12 +3,13 @@
 USING: math.functions project-euler.common sequences ;
 IN: project-euler.016
 
-! https://projecteuler.net/index.php?section=problems&id=16
+! https://projecteuler.net/problem=16
 
 ! DESCRIPTION
 ! -----------
 
-! 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
+! 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 =
+! 26.
 
 ! What is the sum of the digits of the number 2^1000?
 
index 5e153df32ce9ef82e757b8dad74c9a85a78685ff..20cac742aa7c482545f6f48adea1ae5fee93fa79 100644 (file)
@@ -4,27 +4,29 @@ USING: ascii kernel ranges math.text.english sequences
 project-euler.common ;
 IN: project-euler.017
 
-! https://projecteuler.net/index.php?section=problems&id=17
+! https://projecteuler.net/problem=17
 
 ! DESCRIPTION
 ! -----------
 
-! If the numbers 1 to 5 are written out in words: one, two, three, four, five;
-! there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.
+! If the numbers 1 to 5 are written out in words: one, two,
+! three, four, five; there are 3 + 3 + 5 + 4 + 4 = 19 letters
+! used in total.
 
-! If all the numbers from 1 to 1000 (one thousand) inclusive were written out
-! in words, how many letters would be used?
+! If all the numbers from 1 to 1000 (one thousand) inclusive
+! were written out in words, how many letters would be used?
 
-! NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and
-! forty-two) contains 23 letters and 115 (one hundred and fifteen) contains
-! 20 letters.
+! NOTE: Do not count spaces or hyphens. For example, 342 (three
+! hundred and forty-two) contains 23 letters and 115 (one
+! hundred and fifteen) contains 20 letters.
 
 
 ! SOLUTION
 ! --------
 
 : euler017 ( -- answer )
-    1000 [1..b] SBUF" " clone [ number>text append! ] reduce [ Letter? ] count ;
+    1000 [1..b] SBUF" " clone [ number>text append! ] reduce
+    [ Letter? ] count ;
 
 ! [ euler017 ] 100 ave-time
 ! 15 ms ave run time - 1.71 SD (100 trials)
index a077681f9d983874f25c2866b1b17d5dede661b0..4fd84115b029a32098c32549a68ac17782e95d06 100644 (file)
@@ -3,7 +3,7 @@
 USING: kernel project-euler.common ranges sequences ;
 IN: project-euler.018
 
-! https://projecteuler.net/index.php?section=problems&id=18
+! https://projecteuler.net/problem=18
 
 ! DESCRIPTION
 ! -----------
index 3d95d50e625d0d178f3f862571793aabf7f7bf04..e38b14370be85bfb9941e61965d8a6bdbfe2bf58 100644 (file)
@@ -4,31 +4,32 @@ USING: calendar kernel math.order project-euler.common ranges
 sequences ;
 IN: project-euler.019
 
-! https://projecteuler.net/index.php?section=problems&id=19
+! https://projecteuler.net/problem=19
 
 ! DESCRIPTION
 ! -----------
 
-! You are given the following information, but you may prefer to do some
-! research for yourself.
+! You are given the following information, but you may prefer to
+! do some research for yourself.
 
 !     * 1 Jan 1900 was a Monday.
-!     * Thirty days has September, April, June and November.  All the rest have
-!       thirty-one, Saving February alone, Which has twenty-eight, rain or
-!       shine.  And on leap years, twenty-nine.
-!     * A leap year occurs on any year evenly divisible by 4, but not on a
-!       century unless it is divisible by 400.
+!     * Thirty days has September, April, June and November.
+!     All the rest have thirty-one, Saving February alone, Which
+!     has twenty-eight, rain or shine.  And on leap years,
+!     twenty-nine.
+!     * A leap year occurs on any year evenly divisible by 4,
+!     but not on a century unless it is divisible by 400.
 
-! How many Sundays fell on the first of the month during the twentieth century
-! (1 Jan 1901 to 31 Dec 2000)?
+! How many Sundays fell on the first of the month during the
+! twentieth century (1 Jan 1901 to 31 Dec 2000)?
 
 
 ! SOLUTION
 ! --------
 
-! Use Zeller congruence, which is implemented in the "calendar" module
-! already, as "(day-of-week) ( year month day -- n )" where n is
-! the day of the week (Sunday is 0).
+! Use Zeller congruence, which is implemented in the "calendar"
+! module already, as "(day-of-week) ( year month day -- n )"
+! where n is the day of the week (Sunday is 0).
 
 : euler019 ( -- answer )
     1901 2000 [a..b] [
index 4be60d40a726fe61892495d626ab3500f48f3912..bfa4411b970c235d58979270d8daccb3117127c1 100644 (file)
@@ -3,7 +3,7 @@
 USING: math.combinatorics project-euler.common sequences ;
 IN: project-euler.020
 
-! https://projecteuler.net/index.php?section=problems&id=20
+! https://projecteuler.net/problem=20
 
 ! DESCRIPTION
 ! -----------
index a3e691e40db0424b0a80c5f8ffeff903ad137ac2..d95586c53afe1780e5a5f996d41d45ec875c4c82 100644 (file)
@@ -4,20 +4,20 @@ USING: combinators.short-circuit kernel project-euler.common
 ranges sequences ;
 IN: project-euler.021
 
-! https://projecteuler.net/index.php?section=problems&id=21
+! https://projecteuler.net/problem=21
 
 ! DESCRIPTION
 ! -----------
 
-! Let d(n) be defined as the sum of proper divisors of n (numbers less than n
-! which divide evenly into n).
+! Let d(n) be defined as the sum of proper divisors of n
+! (numbers less than n which divide evenly into n).
 
-! If d(a) = b and d(b) = a, where a != b, then a and b are an amicable pair and
-! each of a and b are called amicable numbers.
+! If d(a) = b and d(b) = a, where a != b, then a and b are an
+! amicable pair and each of a and b are called amicable numbers.
 
-! For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44,
-! 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4,
-! 71 and 142; so d(284) = 220.
+! For example, the proper divisors of 220 are 1, 2, 4, 5, 10,
+! 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. The proper
+! divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220.
 
 ! Evaluate the sum of all the amicable numbers under 10000.
 
index ff27a5a9ff11a16cea174fa1aa7aa8954f1d93c2..8f17b3a7ace38c07c8cd3a493b063189e74cc910 100644 (file)
@@ -4,20 +4,21 @@ USING: ascii io.encodings.ascii io.files kernel math
 project-euler.common sequences sorting splitting ;
 IN: project-euler.022
 
-! https://projecteuler.net/index.php?section=problems&id=22
+! https://projecteuler.net/problem=22
 
 ! DESCRIPTION
 ! -----------
 
-! Using names.txt (right click and 'Save Link/Target As...'), a 46K text file
-! containing over five-thousand first names, begin by sorting it into
-! alphabetical order. Then working out the alphabetical value for each name,
-! multiply this value by its alphabetical position in the list to obtain a name
-! score.
+! Using names.txt (right click and 'Save Link/Target As...'), a
+! 46K text file containing over five-thousand first names, begin
+! by sorting it into alphabetical order. Then working out the
+! alphabetical value for each name, multiply this value by its
+! alphabetical position in the list to obtain a name score.
 
-! For example, when the list is sorted into alphabetical order, COLIN, which is
-! worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN
-! would obtain a score of 938 * 53 = 49714.
+! For example, when the list is sorted into alphabetical order,
+! COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th
+! name in the list. So, COLIN would obtain a score of 938 * 53 =
+! 49714.
 
 ! What is the total of all the name scores in the file?
 
index 0b6fa66fcf1c40250ad2652d49bef99986e0dc49..86f0e3fa70e4c5d994117cfa22488a005dcc08bc 100644 (file)
@@ -1,38 +1,41 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: kernel math ranges project-euler.common
-sequences sets ;
+USING: kernel math ranges project-euler.common sequences sets ;
 IN: project-euler.023
 
-! https://projecteuler.net/index.php?section=problems&id=23
+! https://projecteuler.net/problem=23
 
 ! DESCRIPTION
 ! -----------
 
-! A perfect number is a number for which the sum of its proper divisors is
-! exactly equal to the number. For example, the sum of the proper divisors of
-! 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number.
+! A perfect number is a number for which the sum of its proper
+! divisors is exactly equal to the number. For example, the sum
+! of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28,
+! which means that 28 is a perfect number.
 
-! A number whose proper divisors are less than the number is called deficient
-! and a number whose proper divisors exceed the number is called abundant.
+! A number whose proper divisors are less than the number is
+! called deficient and a number whose proper divisors exceed the
+! number is called abundant.
 
-! As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest
-! number that can be written as the sum of two abundant numbers is 24. By
-! mathematical analysis, it can be shown that all integers greater than 28123
-! can be written as the sum of two abundant numbers. However, this upper limit
-! cannot be reduced any further by analysis even though it is known that the
-! greatest number that cannot be expressed as the sum of two abundant numbers
-! is less than this limit.
+! As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16,
+! the smallest number that can be written as the sum of two
+! abundant numbers is 24. By mathematical analysis, it can be
+! shown that all integers greater than 28123 can be written as
+! the sum of two abundant numbers. However, this upper limit
+! cannot be reduced any further by analysis even though it is
+! known that the greatest number that cannot be expressed as the
+! sum of two abundant numbers is less than this limit.
 
-! Find the sum of all the positive integers which cannot be written as the sum
-! of two abundant numbers.
+! Find the sum of all the positive integers which cannot be
+! written as the sum of two abundant numbers.
 
 
 ! SOLUTION
 ! --------
 
-! The upper limit can be dropped to 20161 which reduces our search space
-! and every even number > 46 can be expressed as a sum of two abundants
+! The upper limit can be dropped to 20161 which reduces our
+! search space and every even number > 46 can be expressed as a
+! sum of two abundants
 
 <PRIVATE
 
index 7e03201cc938813a9d44425d37afd8d835a1c98f..7e5758d224276940f01af2125a2c51ccf2b7e628 100644 (file)
@@ -3,20 +3,21 @@
 USING: math.combinatorics project-euler.common sequences ;
 IN: project-euler.024
 
-! https://projecteuler.net/index.php?section=problems&id=24
+! https://projecteuler.net/problem=24
 
 ! DESCRIPTION
 ! -----------
 
-! A permutation is an ordered arrangement of objects. For example, 3124 is one
-! possible permutation of the digits 1, 2, 3 and 4. If all of the permutations
-! are listed numerically or alphabetically, we call it lexicographic order. The
+! A permutation is an ordered arrangement of objects. For
+! example, 3124 is one possible permutation of the digits 1, 2,
+! 3 and 4. If all of the permutations are listed numerically or
+! alphabetically, we call it lexicographic order. The
 ! lexicographic permutations of 0, 1 and 2 are:
 
 !     012   021   102   120   201   210
 
-! What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4,
-! 5, 6, 7, 8 and 9?
+! What is the millionth lexicographic permutation of the digits
+! 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
 
 
 ! SOLUTION
index 7f5977d97212f70fef499f041a3d7367aadbabdb..fe312d51126489a649882491f671aa440ee36397 100644 (file)
@@ -4,7 +4,7 @@ USING: kernel math math.constants math.functions math.parser
 project-euler.common sequences ;
 IN: project-euler.025
 
-! https://projecteuler.net/index.php?section=problems&id=25
+! https://projecteuler.net/problem=25
 
 ! DESCRIPTION
 ! -----------
@@ -30,7 +30,8 @@ IN: project-euler.025
 
 ! The 12th term, F12, is the first term to contain three digits.
 
-! What is the first term in the Fibonacci sequence to contain 1000 digits?
+! What is the first term in the Fibonacci sequence to contain
+! 1000 digits?
 
 
 ! SOLUTION
index 0a7ec11d85856b9843ede7d56652318668d30baf..c44a74a6cb76b25f04db3d09531765a5eb905e71 100644 (file)
@@ -4,13 +4,14 @@ USING: kernel math math.functions math.primes
 project-euler.common sequences ;
 IN: project-euler.026
 
-! https://projecteuler.net/index.php?section=problems&id=26
+! https://projecteuler.net/problem=26
 
 ! DESCRIPTION
 ! -----------
 
-! A unit fraction contains 1 in the numerator. The decimal representation of
-! the unit fractions with denominators 2 to 10 are given:
+! A unit fraction contains 1 in the numerator. The decimal
+! representation of the unit fractions with denominators 2 to 10
+! are given:
 
 !     1/2  =  0.5
 !     1/3  =  0.(3)
@@ -22,11 +23,11 @@ IN: project-euler.026
 !     1/9  =  0.(1)
 !     1/10 =  0.1
 
-! Where 0.1(6) means 0.166666..., and has a 1-digit recurring cycle. It can be
-! seen that 1/7 has a 6-digit recurring cycle.
+! Where 0.1(6) means 0.166666..., and has a 1-digit recurring
+! cycle. It can be seen that 1/7 has a 6-digit recurring cycle.
 
-! Find the value of d < 1000 for which 1/d contains the longest recurring cycle
-! in its decimal fraction part.
+! Find the value of d < 1000 for which 1/d contains the longest
+! recurring cycle in its decimal fraction part.
 
 
 ! SOLUTION
@@ -50,7 +51,8 @@ PRIVATE>
     swap 1 (mult-order) ;
 
 : period-length ( a/b -- n )
-    dup recurring-period? [ denominator 10 swap mult-order ] [ drop 0 ] if ;
+    dup recurring-period?
+    [ denominator 10 swap mult-order ] [ drop 0 ] if ;
 
 <PRIVATE
 
index a6aa6538b9a0ae8de1a80ee6ca4dd71205d11d41..2e5efbfb8f8398a569f3bde4ca47e8fd0d238b45 100644 (file)
@@ -3,7 +3,7 @@
 USING: kernel math math.primes project-euler.common sequences ;
 IN: project-euler.027
 
-! https://projecteuler.net/index.php?section=problems&id=27
+! https://projecteuler.net/problem=27
 
 ! DESCRIPTION
 ! -----------
@@ -12,14 +12,15 @@ IN: project-euler.027
 
 !     n² + n + 41
 
-! It turns out that the formula will produce 40 primes for the consecutive
-! values n = 0 to 39. However, when n = 40, 402 + 40 + 41 = 40(40 + 1) + 41 is
-! divisible by 41, and certainly when n = 41, 41² + 41 + 41 is clearly
-! divisible by 41.
+! It turns out that the formula will produce 40 primes for the
+! consecutive values n = 0 to 39. However, when n = 40, 402 + 40
+! + 41 = 40(40 + 1) + 41 is divisible by 41, and certainly when
+! n = 41, 41² + 41 + 41 is clearly divisible by 41.
 
-! Using computers, the incredible formula n² - 79n + 1601 was discovered, which
-! produces 80 primes for the consecutive values n = 0 to 79. The product of the
-! coefficients, -79 and 1601, is -126479.
+! Using computers, the incredible formula n² - 79n + 1601 was
+! discovered, which produces 80 primes for the consecutive
+! values n = 0 to 79. The product of the coefficients, -79 and
+! 1601, is -126479.
 
 ! Considering quadratics of the form:
 
@@ -28,9 +29,9 @@ IN: project-euler.027
 !     where |n| is the modulus/absolute value of n
 !     e.g. |11| = 11 and |-4| = 4
 
-! Find the product of the coefficients, a and b, for the quadratic expression
-! that produces the maximum number of primes for consecutive values of n,
-! starting with n = 0.
+! Find the product of the coefficients, a and b, for the
+! quadratic expression that produces the maximum number of
+! primes for consecutive values of n, starting with n = 0.
 
 
 ! SOLUTION
index d7a9d4c442e18c3bb89269222d176605fafe3122..2a84be37027ee8f4dd496f89de8328856343fe1d 100644 (file)
@@ -3,13 +3,13 @@
 USING: kernel math ranges sequences project-euler.common ;
 IN: project-euler.028
 
-! https://projecteuler.net/index.php?section=problems&id=28
+! https://projecteuler.net/problem=28
 
 ! DESCRIPTION
 ! -----------
 
-! Starting with the number 1 and moving to the right in a clockwise direction a
-! 5 by 5 spiral is formed as follows:
+! Starting with the number 1 and moving to the right in a
+! clockwise direction a 5 by 5 spiral is formed as follows:
 
 !     21 22 23 24 25
 !     20  7  8  9 10
@@ -19,7 +19,8 @@ IN: project-euler.028
 
 ! It can be verified that the sum of both diagonals is 101.
 
-! What is the sum of both diagonals in a 1001 by 1001 spiral formed in the same way?
+! What is the sum of both diagonals in a 1001 by 1001 spiral
+! formed in the same way?
 
 
 ! SOLUTION
index dff2c8bf9cc15025e3dbcda08a49e829eea3fc8a..2efd39fd9f1157a10f8044b4b7de372d6f7d6de0 100644 (file)
@@ -4,25 +4,27 @@ USING: kernel math.functions project-euler.common ranges
 sequences sets ;
 IN: project-euler.029
 
-! https://projecteuler.net/index.php?section=problems&id=29
+! https://projecteuler.net/problem=29
 
 ! DESCRIPTION
 ! -----------
 
-! Consider all integer combinations of a^b for 2 ≤ a ≤ 5 and 2 ≤ b ≤ 5:
+! Consider all integer combinations of a^b for 2 ≤ a ≤ 5 and
+! 2 ≤ b ≤ 5:
 
 !     2^2 = 4,  2^3 = 8,   2^4 = 16,  2^5 = 32
 !     3^2 = 9,  3^3 = 27,  3^4 = 81,  3^5 = 243
 !     4^2 = 16, 4^3 = 64,  4^4 = 256, 4^5 = 1024
 !     5^2 = 25, 5^3 = 125, 5^4 = 625, 5^5 = 3125
 
-! If they are then placed in numerical order, with any repeats removed, we get
-! the following sequence of 15 distinct terms:
+! If they are then placed in numerical order, with any repeats
+! removed, we get the following sequence of 15 distinct terms:
 
-!     4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125
+!     4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024,
+!     3125
 
-! How many distinct terms are in the sequence generated by a^b for 2 ≤ a ≤ 100
-! and 2 ≤ b ≤ 100?
+! How many distinct terms are in the sequence generated by a^b
+! for 2 ≤ a ≤ 100 and 2 ≤ b ≤ 100?
 
 
 ! SOLUTION
index d3ebcb8837169756fea78535f44d5598ba816703..ff98b21c9c31335737e014f132790ec2a9fa19f5 100644 (file)
@@ -1,15 +1,16 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: kernel math math.functions project-euler.common sequences ;
+USING: kernel math math.functions project-euler.common sequences
+;
 IN: project-euler.030
 
-! https://projecteuler.net/index.php?section=problems&id=30
+! https://projecteuler.net/problem=30
 
 ! DESCRIPTION
 ! -----------
 
-! Surprisingly there are only three numbers that can be written as the sum of
-! fourth powers of their digits:
+! Surprisingly there are only three numbers that can be written
+! as the sum of fourth powers of their digits:
 
 !     1634 = 1^4 + 6^4 + 3^4 + 4^4
 !     8208 = 8^4 + 2^4 + 0^4 + 8^4
@@ -19,8 +20,8 @@ IN: project-euler.030
 
 ! The sum of these numbers is 1634 + 8208 + 9474 = 19316.
 
-! Find the sum of all the numbers that can be written as the sum of fifth
-! powers of their digits.
+! Find the sum of all the numbers that can be written as the sum
+! of fifth powers of their digits.
 
 
 ! SOLUTION
index 02335d0a0feb294e4fadad11cf101d1aef2f630d..feb0add08762e292dd0af9df6112caebac51ec1e 100644 (file)
@@ -3,13 +3,13 @@
 USING: kernel math project-euler.common ;
 IN: project-euler.031
 
-! https://projecteuler.net/index.php?section=problems&id=31
+! https://projecteuler.net/problem=31
 
 ! DESCRIPTION
 ! -----------
 
-! In England the currency is made up of pound, £, and pence, p, and there are
-! eight coins in general circulation:
+! In England the currency is made up of pound, £, and pence, p,
+! and there are eight coins in general circulation:
 
 !     1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).
 
@@ -17,7 +17,8 @@ IN: project-euler.031
 
 !     1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p
 
-! How many different ways can £2 be made using any number of coins?
+! How many different ways can £2 be made using any number of
+! coins?
 
 
 
index 77bb5d13439a42359516d7911856f5ec38418771..af59bbcb13441ff3f732508625bff77b1e473491 100644 (file)
@@ -1,28 +1,31 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: kernel math math.combinatorics math.functions math.parser ranges
-    project-euler.common sequences sets ;
+USING: kernel math math.combinatorics math.functions math.parser
+ranges project-euler.common sequences sets ;
 IN: project-euler.032
 
-! https://projecteuler.net/index.php?section=problems&id=32
+! https://projecteuler.net/problem=32
 
 ! DESCRIPTION
 ! -----------
 
-! The product 7254 is unusual, as the identity, 39 × 186 = 7254, containing
-! multiplicand, multiplier, and product is 1 through 9 pandigital.
+! The product 7254 is unusual, as the identity, 39 × 186 = 7254,
+! containing multiplicand, multiplier, and product is 1 through
+! 9 pandigital.
 
-! Find the sum of all products whose multiplicand/multiplier/product identity
-! can be written as a 1 through 9 pandigital.
+! Find the sum of all products whose
+! multiplicand/multiplier/product identity can be written as a 1
+! through 9 pandigital.
 
-! HINT: Some products can be obtained in more than one way so be sure to only
-! include it once in your sum.
+! HINT: Some products can be obtained in more than one way so be
+! sure to only include it once in your sum.
 
 
 ! SOLUTION
 ! --------
 
-! Generate all pandigital numbers and then check if they fit the identity
+! Generate all pandigital numbers and then check if they fit the
+! identity
 
 <PRIVATE
 
index d3501f0cfe8dd36b1c6d48ddbf8cc3524bead3be..7246237db0a8de7d30a068dd317b706ab67ffce2 100644 (file)
@@ -3,29 +3,32 @@
 USING: kernel math ranges project-euler.common sequences ;
 IN: project-euler.033
 
-! https://projecteuler.net/index.php?section=problems&id=33
+! https://projecteuler.net/problem=33
 
 ! DESCRIPTION
 ! -----------
 
-! The fraction 49/98 is a curious fraction, as an inexperienced mathematician
-! in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which
-! is correct, is obtained by cancelling the 9s.
+! The fraction 49/98 is a curious fraction, as an inexperienced
+! mathematician in attempting to simplify it may incorrectly
+! believe that 49/98 = 4/8, which is correct, is obtained by
+! cancelling the 9s.
 
-! We shall consider fractions like, 30/50 = 3/5, to be trivial examples.
+! We shall consider fractions like, 30/50 = 3/5, to be trivial
+! examples.
 
-! There are exactly four non-trivial examples of this type of fraction, less
-! than one in value, and containing two digits in the numerator and
-! denominator.
+! There are exactly four non-trivial examples of this type of
+! fraction, less than one in value, and containing two digits in
+! the numerator and denominator.
 
-! If the product of these four fractions is given in its lowest common terms,
-! find the value of the denominator.
+! If the product of these four fractions is given in its lowest
+! common terms, find the value of the denominator.
 
 
 ! SOLUTION
 ! --------
 
-! Through analysis, you only need to check fractions fitting the pattern ax/xb
+! Through analysis, you only need to check fractions fitting the
+! pattern ax/xb
 
 <PRIVATE
 
index 3d807ab941c41df6fc7fbadfaf172dfddf14a9c2..19df35f5948f515f8ca36224dab35999ca4e7c2b 100644 (file)
@@ -3,15 +3,15 @@
 USING: kernel ranges project-euler.common sequences ;
 IN: project-euler.034
 
-! https://projecteuler.net/index.php?section=problems&id=34
+! https://projecteuler.net/problem=34
 
 ! DESCRIPTION
 ! -----------
 
 ! 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
 
-! Find the sum of all numbers which are equal to the sum of the factorial of
-! their digits.
+! Find the sum of all numbers which are equal to the sum of the
+! factorial of their digits.
 
 ! Note: as 1! = 1 and 2! = 2 are not sums they are not included.
 
@@ -19,14 +19,16 @@ IN: project-euler.034
 ! SOLUTION
 ! --------
 
-! We can reduce the upper bound a little by calculating 7 * 9! = 2540160, and
-! then reducing one of the 9! to 2! (since the 7th digit cannot exceed 2), so we
-! get 2! + 6 * 9! = 2177282 as an upper bound.
+! We can reduce the upper bound a little by calculating 7 * 9! =
+! 2540160, and then reducing one of the 9! to 2! (since the 7th
+! digit cannot exceed 2), so we get 2! + 6 * 9! = 2177282 as an
+! upper bound.
 
-! We can then take that one more step, and notice that the largest factorial
-! sum a 7 digit number starting with 21 or 20 is 2! + 1! + 5 * 9! or 1814403.
-! So there can't be any 7 digit solutions starting with 21 or 20, and therefore
-! our numbers must be less that 2000000.
+! We can then take that one more step, and notice that the
+! largest factorial sum a 7 digit number starting with 21 or 20
+! is 2! + 1! + 5 * 9! or 1814403. So there can't be any 7 digit
+! solutions starting with 21 or 20, and therefore our numbers
+! must be less that 2000000.
 
 <PRIVATE
 
index e37401431f0d9e436c8222aa3726fdcc00eeda28..c7f72766e78670a47b1466f6a817ef386172ec25 100644 (file)
@@ -3,13 +3,14 @@
 USING: kernel math math.primes project-euler.common sequences ;
 IN: project-euler.035
 
-! https://projecteuler.net/index.php?section=problems&id=35
+! https://projecteuler.net/problem=35
 
 ! DESCRIPTION
 ! -----------
 
-! The number, 197, is called a circular prime because all rotations of the
-! digits: 197, 971, and 719, are themselves prime.
+! The number, 197, is called a circular prime because all
+! rotations of the digits: 197, 971, and 719, are themselves
+! prime.
 
 ! There are thirteen such primes below 100:
 !     2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.
index f63b9d5d11a1ca282b051cc982a85af45e698944..0f28170dae067c253cec8c38c8d76895883be855 100644 (file)
@@ -1,27 +1,29 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See https://factorcode.org/license.txt for BSD license.
 USING: combinators.short-circuit kernel math.parser ranges
-    project-euler.common sequences ;
+project-euler.common sequences ;
 IN: project-euler.036
 
-! https://projecteuler.net/index.php?section=problems&id=36
+! https://projecteuler.net/problem=36
 
 ! DESCRIPTION
 ! -----------
 
-! The decimal number, 585 = 1001001001 (binary), is palindromic in both bases.
+! The decimal number, 585 = 1001001001 (binary), is palindromic
+! in both bases.
 
-! Find the sum of all numbers, less than one million, which are palindromic in
-! base 10 and base 2.
+! Find the sum of all numbers, less than one million, which are
+! palindromic in base 10 and base 2.
 
-! (Please note that the palindromic number, in either base, may not include
-! leading zeros.)
+! (Please note that the palindromic number, in either base, may
+! not include leading zeros.)
 
 
 ! SOLUTION
 ! --------
 
-! Only check odd numbers since the binary number must begin and end with 1
+! Only check odd numbers since the binary number must begin and
+! end with 1
 
 <PRIVATE
 
index 892af2bac3cc61e9634e8febb35df6f809bc1dee..9713a36184918b00603c4f9da327f32b22fac45d 100644 (file)
@@ -1,22 +1,25 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: kernel math math.parser math.primes sequences project-euler.common ;
+USING: kernel math math.parser math.primes sequences
+project-euler.common ;
 IN: project-euler.037
 
-! https://projecteuler.net/index.php?section=problems&id=37
+! https://projecteuler.net/problem=37
 
 ! DESCRIPTION
 ! -----------
 
-! The number 3797 has an interesting property. Being prime itself, it is
-! possible to continuously remove digits from left to right, and remain prime
-! at each stage: 3797, 797, 97, and 7. Similarly we can work from right to
-! left: 3797, 379, 37, and 3.
+! The number 3797 has an interesting property. Being prime
+! itself, it is possible to continuously remove digits from left
+! to right, and remain prime at each stage: 3797, 797, 97, and
+! 7. Similarly we can work from right to left: 3797, 379, 37,
+! and 3.
 
-! Find the sum of the only eleven primes that are both truncatable from left to
-! right and right to left.
+! Find the sum of the only eleven primes that are both
+! truncatable from left to right and right to left.
 
-! NOTE: 2, 3, 5, and 7 are not considered to be truncatable primes.
+! NOTE: 2, 3, 5, and 7 are not considered to be truncatable
+! primes.
 
 
 ! SOLUTION
index 11b7430189e23030df1d974598df47e91ab3044f..ceffdec347c544ede9a8c2b91f8d7ed9354d79f0 100644 (file)
@@ -3,7 +3,7 @@
 USING: kernel math ranges project-euler.common sequences ;
 IN: project-euler.038
 
-! https://projecteuler.net/index.php?section=problems&id=38
+! https://projecteuler.net/problem=38
 
 ! DESCRIPTION
 ! -----------
@@ -14,23 +14,26 @@ IN: project-euler.038
 !     192 × 2 = 384
 !     192 × 3 = 576
 
-! By concatenating each product we get the 1 to 9 pandigital, 192384576. We
-! will call 192384576 the concatenated product of 192 and (1,2,3)
+! By concatenating each product we get the 1 to 9 pandigital,
+! 192384576. We will call 192384576 the concatenated product of
+! 192 and (1,2,3)
 
-! The same can be achieved by starting with 9 and multiplying by 1, 2, 3, 4,
-! and 5, giving the pandigital, 918273645, which is the concatenated product of
-! 9 and (1,2,3,4,5).
+! The same can be achieved by starting with 9 and multiplying by
+! 1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is
+! the concatenated product of 9 and (1,2,3,4,5).
 
-! What is the largest 1 to 9 pandigital 9-digit number that can be formed as
-! the concatenated product of an integer with (1,2, ... , n) where n > 1?
+! What is the largest 1 to 9 pandigital 9-digit number that can
+! be formed as the concatenated product of an integer with
+! (1,2, ..., n) where n > 1?
 
 
 ! SOLUTION
 ! --------
 
-! Only need to search 4-digit numbers starting with 9 since a 2-digit number
-! starting with 9 would produce 8 or 11 digits, and a 3-digit number starting
-! with 9 would produce 7 or 11 digits.
+! Only need to search 4-digit numbers starting with 9 since a
+! 2-digit number starting with 9 would produce 8 or 11 digits,
+! and a 3-digit number starting with 9 would produce 7 or 11
+! digits.
 
 <PRIVATE
 
index 67eb4934aa451d10784468e44c18fc56e46f19ea..dcd1cefaf383120d9b1518a86a8c9cd10b024b6e 100644 (file)
@@ -4,29 +4,33 @@ USING: arrays kernel math ranges namespaces project-euler.common
 sequences sequences.extras ;
 IN: project-euler.039
 
-! https://projecteuler.net/index.php?section=problems&id=39
+! https://projecteuler.net/problem=39
 
 ! DESCRIPTION
 ! -----------
 
-! If p is the perimeter of a right angle triangle with integral length sides,
-! {a,b,c}, there are exactly three solutions for p = 120.
+! If p is the perimeter of a right angle triangle with integral
+! length sides, {a,b,c}, there are exactly three solutions for p
+! = 120.
 
 !     {20,48,52}, {24,45,51}, {30,40,50}
 
-! For which value of p < 1000, is the number of solutions maximized?
+! For which value of p < 1000, is the number of solutions
+! maximized?
 
 
 ! SOLUTION
 ! --------
 
-! Algorithm adapted from https://mathworld.wolfram.com/PythagoreanTriple.html
+! Algorithm adapted from
+! https://mathworld.wolfram.com/PythagoreanTriple.html
 ! Identical implementation as problem #75
 
-! Basically, this makes an array of 1000 zeros, recursively creates primitive
-! triples using the three transforms and then increments the array at index
-! [a+b+c] by one for each triple's sum AND its multiples under 1000 (to account
-! for non-primitive triples). The answer is just the index that has the highest
+! Basically, this makes an array of 1000 zeros, recursively
+! creates primitive triples using the three transforms and then
+! increments the array at index [a+b+c] by one for each triple's
+! sum AND its multiples under 1000 (to account for non-primitive
+! triples). The answer is just the index that has the highest
 ! number.
 
 SYMBOL: p-count
index 410b62bb8626447c91003e022ef547e39d608755..7b0f4bbe2f3f3270778745db6f2177037abadf7d 100644 (file)
@@ -3,20 +3,21 @@
 USING: kernel math math.parser sequences project-euler.common ;
 IN: project-euler.040
 
-! https://projecteuler.net/index.php?section=problems&id=40
+! https://projecteuler.net/problem=40
 
 ! DESCRIPTION
 ! -----------
 
-! An irrational decimal fraction is created by concatenating the positive
-! integers:
+! An irrational decimal fraction is created by concatenating the
+! positive integers:
 
 !     0.123456789101112131415161718192021...
 
-! It can be seen that the 12th digit of the fractional part is 1.
+! It can be seen that the 12th digit of the fractional part is
+! 1.
 
-! If dn represents the nth digit of the fractional part, find the value of the
-! following expression.
+! If dn represents the nth digit of the fractional part, find
+! the value of the following expression.
 
 !     d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000
 
index 5622cd1470e3bc836080aca0521925c2410392fc..6269a21abdc3c91b4af4b2a86531603a7fd63bec 100644 (file)
@@ -1,16 +1,17 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: kernel math.combinatorics math.primes sequences project-euler.common ;
+USING: kernel math.combinatorics math.primes sequences
+project-euler.common ;
 IN: project-euler.041
 
-! https://projecteuler.net/index.php?section=problems&id=41
+! https://projecteuler.net/problem=41
 
 ! DESCRIPTION
 ! -----------
 
-! We shall say that an n-digit number is pandigital if it makes use of all the
-! digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is
-! also prime.
+! We shall say that an n-digit number is pandigital if it makes
+! use of all the digits 1 to n exactly once. For example, 2143
+! is a 4-digit pandigital and is also prime.
 
 ! What is the largest n-digit pandigital prime that exists?
 
@@ -18,10 +19,11 @@ IN: project-euler.041
 ! SOLUTION
 ! --------
 
-! Check 7-digit pandigitals because if the sum of the digits in any number add
-! up to a multiple of three, then it is a multiple of three and can't be prime.
-! I assumed there would be a 7-digit answer, but technically a higher 4-digit
-! pandigital than the one given in the description was also possible.
+! Check 7-digit pandigitals because if the sum of the digits in
+! any number add up to a multiple of three, then it is a
+! multiple of three and can't be prime. I assumed there would be
+! a 7-digit answer, but technically a higher 4-digit pandigital
+! than the one given in the description was also possible.
 
 !     1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 45
 !     1 + 2 + 3 + 4 + 5 + 6 + 7 + 8     = 36
index 8faa7b5d6694193da8bedbd8e52552427518eb1a..fbf1c01e3e43ac09dd9e6e3f4264e4d584392a08 100644 (file)
@@ -1,10 +1,10 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: ascii io.encodings.ascii io.files kernel make math math.functions
-project-euler.common sequences splitting ;
+USING: ascii io.encodings.ascii io.files kernel make math
+math.functions project-euler.common sequences splitting ;
 IN: project-euler.042
 
-! https://projecteuler.net/index.php?section=problems&id=42
+! https://projecteuler.net/problem=42
 
 ! DESCRIPTION
 ! -----------
@@ -14,14 +14,15 @@ IN: project-euler.042
 
 !     1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
 
-! By converting each letter in a word to a number corresponding to its
-! alphabetical position and adding these values we form a word value. For
-! example, the word value for SKY is 19 + 11 + 25 = 55 = t10. If the word value
-! is a triangle number then we shall call the word a triangle word.
+! By converting each letter in a word to a number corresponding
+! to its alphabetical position and adding these values we form a
+! word value. For example, the word value for SKY is 19 + 11 +
+! 25 = 55 = t10. If the word value is a triangle number then we
+! shall call the word a triangle word.
 
-! Using words.txt (right click and 'Save Link/Target As...'), a 16K text file
-! containing nearly two-thousand common English words, how many are triangle
-! words?
+! Using words.txt (right click and 'Save Link/Target As...'), a
+! 16K text file containing nearly two-thousand common English
+! words, how many are triangle words?
 
 
 ! SOLUTION
index d8dc345fc32c580d429a430a85dfca8018343e40..8880f2dbcfe7d2920d97b6dd36801301b397a463 100644 (file)
@@ -1,20 +1,22 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: combinators.short-circuit kernel math math.functions math.combinatorics
-    ranges project-euler.common sequences sets sorting ;
+USING: combinators.short-circuit kernel math math.functions
+math.combinatorics ranges project-euler.common sequences sets
+sorting ;
 IN: project-euler.043
 
-! https://projecteuler.net/index.php?section=problems&id=43
+! https://projecteuler.net/problem=43
 
 ! DESCRIPTION
 ! -----------
 
-! The number, 1406357289, is a 0 to 9 pandigital number because it is made up
-! of each of the digits 0 to 9 in some order, but it also has a rather
-! interesting sub-string divisibility property.
+! The number, 1406357289, is a 0 to 9 pandigital number because
+! it is made up of each of the digits 0 to 9 in some order, but
+! it also has a rather interesting sub-string divisibility
+! property.
 
-! Let d1 be the 1st digit, d2 be the 2nd digit, and so on. In this way, we note
-! the following:
+! Let d1 be the 1st digit, d2 be the 2nd digit, and so on. In
+! this way, we note the following:
 
 !     * d2d3d4  = 406 is divisible by 2
 !     * d3d4d5  = 063 is divisible by 3
@@ -24,14 +26,15 @@ IN: project-euler.043
 !     * d7d8d9  = 728 is divisible by 13
 !     * d8d9d10 = 289 is divisible by 17
 
-! Find the sum of all 0 to 9 pandigital numbers with this property.
+! Find the sum of all 0 to 9 pandigital numbers with this
+! property.
 
 
 ! SOLUTION
 ! --------
 
-! Brute force generating all the pandigitals then checking 3-digit divisiblity
-! properties...this is very slow!
+! Brute force generating all the pandigitals then checking
+! 3-digit divisiblity properties...this is very slow!
 
 <PRIVATE
 
index 8e2e5a3ed558b309d03087571958466db16f49fc..8f4958b74baea667d8608d2188c35860b454a247 100644 (file)
@@ -4,27 +4,29 @@ USING: kernel math ranges math.order project-euler.common
 sequences layouts ;
 IN: project-euler.044
 
-! https://projecteuler.net/index.php?section=problems&id=44
+! https://projecteuler.net/problem=44
 
 ! DESCRIPTION
 ! -----------
 
-! Pentagonal numbers are generated by the formula, Pn=n(3n−1)/2. The first ten
-! pentagonal numbers are:
+! Pentagonal numbers are generated by the formula, Pn=n(3n−1)/2.
+! The first ten pentagonal numbers are:
 
 !     1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ...
 
-! It can be seen that P4 + P7 = 22 + 70 = 92 = P8. However, their difference,
-! 70 − 22 = 48, is not pentagonal.
+! It can be seen that P4 + P7 = 22 + 70 = 92 = P8. However,
+! their difference, 70 − 22 = 48, is not pentagonal.
 
-! Find the pair of pentagonal numbers, Pj and Pk, for which their sum and
-! difference is pentagonal and D = |Pk − Pj| is minimised; what is the value of D?
+! Find the pair of pentagonal numbers, Pj and Pk, for which
+! their sum and difference is pentagonal and D = |Pk − Pj| is
+! minimised; what is the value of D?
 
 
 ! SOLUTION
 ! --------
 
-! Brute force using a cartesian product and an arbitrarily chosen limit.
+! Brute force using a cartesian product and an arbitrarily
+! chosen limit.
 
 <PRIVATE
 
index 4025c6c8589174536d0ac04470d63f183afc18a2..f0c6ad52a2d785d28d6d9d052996192f3a50ffc7 100644 (file)
@@ -3,27 +3,29 @@
 USING: kernel math project-euler.common ;
 IN: project-euler.045
 
-! https://projecteuler.net/index.php?section=problems&id=45
+! https://projecteuler.net/problem=45
 
 ! DESCRIPTION
 ! -----------
 
-! Triangle, pentagonal, and hexagonal numbers are generated by the following
-! formulae:
+! Triangle, pentagonal, and hexagonal numbers are generated by
+! the following formulae:
 !     Triangle     Tn = n(n + 1) / 2    1, 3,  6, 10, 15, ...
 !     Pentagonal   Pn = n(3n − 1) / 2   1, 5, 12, 22, 35, ...
 !     Hexagonal    Hn = n(2n − 1)       1, 6, 15, 28, 45, ...
 
 ! It can be verified that T285 = P165 = H143 = 40755.
 
-! Find the next triangle number that is also pentagonal and hexagonal.
+! Find the next triangle number that is also pentagonal and
+! hexagonal.
 
 
 ! SOLUTION
 ! --------
 
-! All hexagonal numbers are also triangle numbers, so iterate through hexagonal
-! numbers until you find one that is pentagonal as well.
+! All hexagonal numbers are also triangle numbers, so iterate
+! through hexagonal numbers until you find one that is
+! pentagonal as well.
 
 <PRIVATE
 
index 87159ee6304242ac27d226fe8697f1043cdc7e92..e17351b7d7c0fd7d457791a51ad014309dd24738 100644 (file)
@@ -1,16 +1,17 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: kernel math math.functions math.primes ranges
-sequences project-euler.common ;
+USING: kernel math math.functions math.primes ranges sequences
+project-euler.common ;
 IN: project-euler.046
 
-! https://projecteuler.net/index.php?section=problems&id=46
+! https://projecteuler.net/problem=46
 
 ! DESCRIPTION
 ! -----------
 
-! It was proposed by Christian Goldbach that every odd composite number can be
-! written as the sum of a prime and twice a square.
+! It was proposed by Christian Goldbach that every odd composite
+! number can be written as the sum of a prime and twice a
+! square.
 
 !     9  =  7 + 2 * 1^2
 !     15 =  7 + 2 * 2^2
@@ -21,8 +22,8 @@ IN: project-euler.046
 
 ! It turns out that the conjecture was false.
 
-! What is the smallest odd composite that cannot be written as the sum of a
-! prime and twice a square?
+! What is the smallest odd composite that cannot be written as
+! the sum of a prime and twice a square?
 
 
 ! SOLUTION
index 1b9f548aaf8031d8cd8412a90db36bd5a8b4d48f..4cfb6f5f6fa471ff13719b97fcd1114becee53b1 100644 (file)
@@ -1,33 +1,36 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: arrays kernel math math.primes math.primes.factors
-    ranges namespaces sequences project-euler.common ;
+USING: arrays kernel math math.primes math.primes.factors ranges
+namespaces sequences project-euler.common ;
 IN: project-euler.047
 
-! https://projecteuler.net/index.php?section=problems&id=47
+! https://projecteuler.net/problem=47
 
 ! DESCRIPTION
 ! -----------
 
-! The first two consecutive numbers to have two distinct prime factors are:
+! The first two consecutive numbers to have two distinct prime
+! factors are:
 
 !     14 = 2 * 7
 !     15 = 3 * 5
 
-! The first three consecutive numbers to have three distinct prime factors are:
+! The first three consecutive numbers to have three distinct
+! prime factors are:
 
 !     644 = 2² * 7 * 23
 !     645 = 3 * 5 * 43
 !     646 = 2 * 17 * 19.
 
-! Find the first four consecutive integers to have four distinct primes
-! factors. What is the first of these numbers?
+! Find the first four consecutive integers to have four distinct
+! primes factors. What is the first of these numbers?
 
 
 ! SOLUTION
 ! --------
 
-! Brute force, not sure why it's incredibly slow compared to other languages
+! Brute force, not sure why it's incredibly slow compared to
+! other languages
 
 <PRIVATE
 
index c8ef4981b8903f3e322da0577f16ec6b1287f322..a7075e9b78849cef6ce9401af4d81371646ac3ee 100644 (file)
@@ -1,17 +1,18 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: kernel math math.functions ranges
-project-euler.common sequences ;
+USING: kernel math math.functions ranges project-euler.common
+sequences ;
 IN: project-euler.048
 
-! https://projecteuler.net/index.php?section=problems&id=48
+! https://projecteuler.net/problem=48
 
 ! DESCRIPTION
 ! -----------
 
 ! The series, 1^1 + 2^2 + 3^3 + ... + 10^10 = 10405071317.
 
-! Find the last ten digits of the series, 1^1 + 2^2 + 3^3 + ... + 1000^1000.
+! Find the last ten digits of the series,
+! 1^1 + 2^2 + 3^3 + ... + 1000^1000.
 
 
 ! SOLUTION
index a59e057013fe6f0282537f636e20e09f4d546aeb..21d53d111c79c5e7a9fcc162568c5ca1d713c97b 100644 (file)
@@ -5,20 +5,22 @@ sequences sets ;
 FROM: project-euler.common => permutations? ;
 IN: project-euler.049
 
-! https://projecteuler.net/index.php?section=problems&id=49
+! https://projecteuler.net/problem=49
 
 ! DESCRIPTION
 ! -----------
 
-! The arithmetic sequence, 1487, 4817, 8147, in which each of the terms
-! increases by 3330, is unusual in two ways: (i) each of the three terms are
-! prime, and, (ii) each of the 4-digit numbers are permutations of one another.
+! The arithmetic sequence, 1487, 4817, 8147, in which each of
+! the terms increases by 3330, is unusual in two ways: (i) each
+! of the three terms are prime, and, (ii) each of the 4-digit
+! numbers are permutations of one another.
 
-! There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes,
-! exhibiting this property, but there is one other 4-digit increasing sequence.
+! There are no arithmetic sequences made up of three 1-, 2-, or
+! 3-digit primes, exhibiting this property, but there is one
+! other 4-digit increasing sequence.
 
-! What 12-digit number do you form by concatenating the three terms in this
-! sequence?
+! What 12-digit number do you form by concatenating the three
+! terms in this sequence?
 
 
 ! SOLUTION
index a42a8235c1ee21e6a70353d7e3d6f27535680335..7c742de75e43de12c2b242ab714ceb7e9efb5fec 100644 (file)
@@ -4,40 +4,44 @@ USING: arrays kernel math math.order math.primes
 project-euler.common sequences ;
 IN: project-euler.050
 
-! https://projecteuler.net/index.php?section=problems&id=50
+! https://projecteuler.net/problem=50
 
 ! DESCRIPTION
 ! -----------
 
-! The prime 41, can be written as the sum of six consecutive primes:
+! The prime 41, can be written as the sum of six consecutive
+! primes:
 
 !     41 = 2 + 3 + 5 + 7 + 11 + 13
 
-! This is the longest sum of consecutive primes that adds to a prime below
-! one-hundred.
+! This is the longest sum of consecutive primes that adds to a
+! prime below one-hundred.
 
-! The longest sum of consecutive primes below one-thousand that adds to a
-! prime, contains 21 terms, and is equal to 953.
+! The longest sum of consecutive primes below one-thousand that
+! adds to a prime, contains 21 terms, and is equal to 953.
 
-! Which prime, below one-million, can be written as the sum of the most
-! consecutive primes?
+! Which prime, below one-million, can be written as the sum of
+! the most consecutive primes?
 
 
 ! SOLUTION
 ! --------
 
 ! 1) Create an sequence of all primes under 1000000.
-! 2) Start summing elements in the sequence until the next number would put you
-!    over 1000000.
-! 3) Check if that sum is prime, if not, subtract the last number added.
-! 4) Repeat step 3 until you get a prime number, and store it along with the
-!    how many consecutive numbers from the original sequence it took to get there.
-! 5) Drop the first number from the sequence of primes, and do steps 2-4 again
-! 6) Compare the longest chain from the first run with the second run, and store
-!    the longer of the two.
-! 7) If the sequence of primes is still longer than the longest chain, then
-!    repeat steps 5-7...otherwise, you've found the longest sum of consecutive
-!    primes!
+! 2) Start summing elements in the sequence until the next
+!    number would put you over 1000000.
+! 3) Check if that sum is prime, if not, subtract the last
+!    number added.
+! 4) Repeat step 3 until you get a prime number, and store it
+!    along with the how many consecutive numbers from the
+!    original sequence it took to get there.
+! 5) Drop the first number from the sequence of primes, and do
+!    steps 2-4 again
+! 6) Compare the longest chain from the first run with the
+!    second run, and store the longer of the two.
+! 7) If the sequence of primes is still longer than the longest
+!    chain, then repeat steps 5-7...otherwise, you've found the
+!    longest sum of consecutive primes!
 
 <PRIVATE
 
index 8b3cb03aeca0c2f99e472a914bc93b86bba34aba..cd5bc931213c2dacf89fa90a67ed740767e5f6e0 100644 (file)
@@ -1,35 +1,35 @@
 ! Copyright (C) 2009 Jon Harper.
 ! See https://factorcode.org/license.txt for BSD license.
+USING: assocs kernel math math.combinatorics math.functions
+math.order math.parser math.primes ranges namespaces
+project-euler.common sequences sets ;
+IN: project-euler.051
 
-! https://projecteuler.net/index.php?section=problems&id=1
+! https://projecteuler.net/problem=51
 
 ! DESCRIPTION
 ! -----------
 
-
-! By replacing the first digit of *3, it turns out that
-! six of the nine possible values:
-! 13, 23, 43, 53, 73, and 83, are all prime.
-! By replacing the third and fourth digits of 56**3 with the same digit,
-! this 5-digit number is the first example having seven primes among
-! the ten generated numbers, yielding the family:
-! 56003, 56113, 56333, 56443, 56663, 56773, and 56993.
-! Consequently 56003, being the first member of this family,
-! is the smallest prime with this property.
+! By replacing the first digit of *3, it turns out that six of
+! the nine possible values: 13, 23, 43, 53, 73, and 83, are all
+! prime. By replacing the third and fourth digits of 56**3 with
+! the same digit, this 5-digit number is the first example
+! having seven primes among the ten generated numbers, yielding
+! the family: 56003, 56113, 56333, 56443, 56663, 56773, and
+! 56993. Consequently 56003, being the first member of this
+! family, is the smallest prime with this property.
 !
 ! Find the smallest prime which, by replacing part of the number
-! (not necessarily adjacent digits) with the same digit,
-! is part of an eight prime value family.
+! (not necessarily adjacent digits) with the same digit, is part
+! of an eight prime value family.
 
 ! SOLUTION
 ! --------
 
-! for each prime number, count the families it belongs to. When one reaches count of 8, stop, and get the smallest number by replacing * with ones.
+! for each prime number, count the families it belongs to. When
+! one reaches count of 8, stop, and get the smallest number by
+! replacing * with ones.
 
-USING: assocs kernel math math.combinatorics math.functions
-math.order math.parser math.primes ranges namespaces
-project-euler.common sequences sets ;
-IN: project-euler.051
 <PRIVATE
 SYMBOL: family-count
 SYMBOL: large-families
index c5d73ec3af7cf0beb8b2ae1424bb05a17bd9c6ab..fd00c6e1b2a6d84bc082a408847e6b3b169b6206 100644 (file)
@@ -1,25 +1,27 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See https://factorcode.org/license.txt for BSD license.
 USING: combinators.short-circuit kernel math math.functions
-    project-euler.common sequences sorting grouping ;
+project-euler.common sequences sorting grouping ;
 IN: project-euler.052
 
-! https://projecteuler.net/index.php?section=problems&id=52
+! https://projecteuler.net/problem=52
 
 ! DESCRIPTION
 ! -----------
 
-! It can be seen that the number, 125874, and its double, 251748, contain
-! exactly the same digits, but in a different order.
+! It can be seen that the number, 125874, and its double,
+! 251748, contain exactly the same digits, but in a different
+! order.
 
-! Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x,
-! contain the same digits.
+! Find the smallest positive integer, x, such that 2x, 3x, 4x,
+! 5x, and 6x, contain the same digits.
 
 
 ! SOLUTION
 ! --------
 
-! Analysis shows the number must be odd, divisible by 3, and larger than 123456
+! Analysis shows the number must be odd, divisible by 3, and
+! larger than 123456
 
 <PRIVATE
 
index 1df1975cce40cc034d6ee44ff6e13d1ed5bf7aab..27d70b414ba819590fdd7a4e3ed46967d9a5d6ec 100644 (file)
@@ -1,14 +1,16 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: kernel math math.combinatorics ranges sequences project-euler.common ;
+USING: kernel math math.combinatorics ranges sequences
+project-euler.common ;
 IN: project-euler.053
 
-! https://projecteuler.net/index.php?section=problems&id=53
+! https://projecteuler.net/problem=53
 
 ! DESCRIPTION
 ! -----------
 
-! There are exactly ten ways of selecting three from five, 12345:
+! There are exactly ten ways of selecting three from five,
+! 12345:
 
 !     123, 124, 125, 134, 135, 145, 234, 235, 245, and 345
 
@@ -18,9 +20,11 @@ IN: project-euler.053
 !     nCr = n! / r! * (n - r)!
 ! where r ≤ n, n! = n * (n − 1) * ... * 3 * 2 * 1, and 0! = 1.
 
-! It is not until n = 23, that a value exceeds one-million: 23C10 = 1144066.
+! It is not until n = 23, that a value exceeds one-million:
+! 23C10 = 1144066.
 
-! How many values of nCr, for 1 ≤ n ≤ 100, are greater than one-million?
+! How many values of nCr, for 1 ≤ n ≤ 100, are greater than
+! one-million?
 
 
 ! SOLUTION
index 53033a50f32d28dc053859c51e974edce378e3c8..2b5fd4a10ec6c71934efdf37cee527bc5fd8f443 100644 (file)
@@ -1,16 +1,16 @@
 ! Copyright (c) 2009 Aaron Schaefer.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: arrays io.encodings.ascii io.files kernel math.order poker
-    project-euler.common sequences ;
+USING: arrays io.encodings.ascii io.files kernel math.order
+poker project-euler.common sequences ;
 IN: project-euler.054
 
-! https://projecteuler.net/index.php?section=problems&id=54
+! https://projecteuler.net/problem=54
 
 ! DESCRIPTION
 ! -----------
 
-! In the card game poker, a hand consists of five cards and are ranked, from
-! lowest to highest, in the following way:
+! In the card game poker, a hand consists of five cards and are
+! ranked, from lowest to highest, in the following way:
 
 !     * High Card: Highest value card.
 !     * One Pair: Two cards of the same value.
@@ -20,18 +20,20 @@ IN: project-euler.054
 !     * Flush: All cards of the same suit.
 !     * Full House: Three of a kind and a pair.
 !     * Four of a Kind: Four cards of the same value.
-!     * Straight Flush: All cards are consecutive values of same suit.
+!     * Straight Flush: All cards are consecutive values of same
+!       suit.
 !     * Royal Flush: Ten, Jack, Queen, King, Ace, in same suit.
 
 ! The cards are valued in the order:
 !     2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace.
 
-! If two players have the same ranked hands then the rank made up of the
-! highest value wins; for example, a pair of eights beats a pair of fives (see
-! example 1 below). But if two ranks tie, for example, both players have a pair
-! of queens, then highest cards in each hand are compared (see example 4
-! below); if the highest cards tie then the next highest cards are compared,
-! and so on.
+! If two players have the same ranked hands then the rank made
+! up of the highest value wins; for example, a pair of eights
+! beats a pair of fives (see example 1 below). But if two ranks
+! tie, for example, both players have a pair of queens, then
+! highest cards in each hand are compared (see example 4 below);
+! if the highest cards tie then the next highest cards are
+! compared, and so on.
 
 ! Consider the following five hands dealt to two players:
 
@@ -54,12 +56,13 @@ IN: project-euler.054
 !            Full House          Full House
 !            With Three Fours    With Three Threes     Player 1
 
-! The file, poker.txt, contains one-thousand random hands dealt to two players.
-! Each line of the file contains ten cards (separated by a single space): the
-! first five are Player 1's cards and the last five are Player 2's cards. You
-! can assume that all hands are valid (no invalid characters or repeated
-! cards), each player's hand is in no specific order, and in each hand there is
-! a clear winner.
+! The file, poker.txt, contains one-thousand random hands dealt
+! to two players. Each line of the file contains ten cards
+! (separated by a single space): the first five are Player 1's
+! cards and the last five are Player 2's cards. You can assume
+! that all hands are valid (no invalid characters or repeated
+! cards), each player's hand is in no specific order, and in
+! each hand there is a clear winner.
 
 ! How many hands does Player 1 win?
 
index daf340e87b63012dba19c9ffce80663a11a7eff7..535c62d7683d79d32be0c92f9e2b04f479cb2bb0 100644 (file)
@@ -3,12 +3,13 @@
 USING: kernel math project-euler.common sequences ;
 IN: project-euler.055
 
-! https://projecteuler.net/index.php?section=problems&id=55
+! https://projecteuler.net/problem=55
 
 ! DESCRIPTION
 ! -----------
 
-! If we take 47, reverse and add, 47 + 74 = 121, which is palindromic.
+! If we take 47, reverse and add, 47 + 74 = 121, which is
+! palindromic.
 
 ! Not all numbers produce palindromes so quickly. For example,
 
@@ -18,25 +19,27 @@ IN: project-euler.055
 
 ! That is, 349 took three iterations to arrive at a palindrome.
 
-! Although no one has proved it yet, it is thought that some numbers, like 196,
-! never produce a palindrome. A number that never forms a palindrome through
-! the reverse and add process is called a Lychrel number. Due to the
-! theoretical nature of these numbers, and for the purpose of this problem, we
-! shall assume that a number is Lychrel until proven otherwise. In addition you
-! are given that for every number below ten-thousand, it will either (i) become a
-! palindrome in less than fifty iterations, or, (ii) no one, with all the
-! computing power that exists, has managed so far to map it to a palindrome. In
-! fact, 10677 is the first number to be shown to require over fifty iterations
-! before producing a palindrome: 4668731596684224866951378664 (53 iterations,
-! 28-digits).
-
-! Surprisingly, there are palindromic numbers that are themselves Lychrel
-! numbers; the first example is 4994.
+! Although no one has proved it yet, it is thought that some
+! numbers, like 196, never produce a palindrome. A number that
+! never forms a palindrome through the reverse and add process
+! is called a Lychrel number. Due to the theoretical nature of
+! these numbers, and for the purpose of this problem, we shall
+! assume that a number is Lychrel until proven otherwise. In
+! addition you are given that for every number below
+! ten-thousand, it will either (i) become a palindrome in less
+! than fifty iterations, or, (ii) no one, with all the computing
+! power that exists, has managed so far to map it to a
+! palindrome. In fact, 10677 is the first number to be shown to
+! require over fifty iterations before producing a palindrome:
+! 4668731596684224866951378664 (53 iterations, 28-digits).
+
+! Surprisingly, there are palindromic numbers that are
+! themselves Lychrel numbers; the first example is 4994.
 
 ! How many Lychrel numbers are there below ten-thousand?
 
-! NOTE: Wording was modified slightly on 24 April 2007 to emphasise the
-! theoretical nature of Lychrel numbers.
+! NOTE: Wording was modified slightly on 24 April 2007 to
+! emphasise the theoretical nature of Lychrel numbers.
 
 
 ! SOLUTION
index 4c5d0258217a889fc65bd4b1bfec154000bf1df2..ba6e0f0b9e6d21bb9d3b46a173149d944f2d361f 100644 (file)
@@ -4,17 +4,18 @@ USING: kernel math.functions ranges project-euler.common
 sequences math.order ;
 IN: project-euler.056
 
-! https://projecteuler.net/index.php?section=problems&id=56
+! https://projecteuler.net/problem=56
 
 ! DESCRIPTION
 ! -----------
 
-! A googol (10^100) is a massive number: one followed by one-hundred zeros;
-! 100^100 is almost unimaginably large: one followed by two-hundred zeros.
-! Despite their size, the sum of the digits in each number is only 1.
+! A googol (10^100) is a massive number: one followed by
+! one-hundred zeros; 100^100 is almost unimaginably large: one
+! followed by two-hundred zeros. Despite their size, the sum of
+! the digits in each number is only 1.
 
-! Considering natural numbers of the form, a^b, where a, b < 100, what is the
-! maximum digital sum?
+! Considering natural numbers of the form, a^b, where a, b <
+! 100, what is the maximum digital sum?
 
 
 ! SOLUTION
index 61991e26be1dac556e029448d3f258ea6be676df..24dedcf28938487f913d14a1da82113bd44c6f90 100644 (file)
@@ -3,13 +3,13 @@
 USING: kernel math math.parser project-euler.common sequences ;
 IN: project-euler.057
 
-! https://projecteuler.net/index.php?section=problems&id=57
+! https://projecteuler.net/problem=57
 
 ! DESCRIPTION
 ! -----------
 
-! It is possible to show that the square root of two can be expressed
-! as an infinite continued fraction.
+! It is possible to show that the square root of two can be
+! expressed as an infinite continued fraction.
 
 !     √ 2 = 1 + 1/(2 + 1/(2 + 1/(2 + ... ))) = 1.414213...
 
@@ -20,13 +20,13 @@ IN: project-euler.057
 !     1 + 1/(2 + 1/(2 + 1/2)) = 17/12 = 1.41666...
 !     1 + 1/(2 + 1/(2 + 1/(2 + 1/2))) = 41/29 = 1.41379...
 
-! The next three expansions are 99/70, 239/169, and 577/408, but the
-! eighth expansion, 1393/985, is the first example where the number of
-! digits in the numerator exceeds the number of digits in the
-! denominator.
+! The next three expansions are 99/70, 239/169, and 577/408, but
+! the eighth expansion, 1393/985, is the first example where the
+! number of digits in the numerator exceeds the number of digits
+! in the denominator.
 
-! In the first one-thousand expansions, how many fractions contain a
-! numerator with more digits than denominator?
+! In the first one-thousand expansions, how many fractions
+! contain a numerator with more digits than denominator?
 
 ! SOLUTION
 ! --------
index 0c3d38e256310e02383379a9d8252cd3588c1737..9dbf4ad8f705e43e1144a772ccf782fccc212873 100644 (file)
@@ -4,13 +4,13 @@ USING: kernel math math.primes project-euler.common ranges
 sequences ;
 IN: project-euler.058
 
-! https://projecteuler.net/index.php?section=problems&id=58
+! https://projecteuler.net/problem=58
 
 ! DESCRIPTION
 ! -----------
 
-! Starting with 1 and solveling anticlockwise in the following way, a square
-! solve with side length 7 is formed.
+! Starting with 1 and solveling anticlockwise in the following
+! way, a square solve with side length 7 is formed.
 
 !     37 36 35 34 33 32 31
 !     38 17 16 15 14 13 30
@@ -20,14 +20,16 @@ IN: project-euler.058
 !     42 21 22 23 24 25 26
 !     43 44 45 46 47 48 49
 
-! It is interesting to note that the odd squares lie along the bottom right
-! diagonal, but what is more interesting is that 8 out of the 13 numbers lying
-! along both diagonals are prime; that is, a ratio of 8/13 ≈ 62%.
+! It is interesting to note that the odd squares lie along the
+! bottom right diagonal, but what is more interesting is that 8
+! out of the 13 numbers lying along both diagonals are prime;
+! that is, a ratio of 8/13 ≈ 62%.
 
-! If one complete new layer is wrapped around the solve above, a square solve
-! with side length 9 will be formed. If this process is continued, what is the
-! side length of the square solve for which the ratio of primes along both
-! diagonals first falls below 10%?
+! If one complete new layer is wrapped around the solve above, a
+! square solve with side length 9 will be formed. If this
+! process is continued, what is the side length of the square
+! solve for which the ratio of primes along both diagonals first
+! falls below 10%?
 
 
 ! SOLUTION
index d354c86431c652c345c0a2398b5c73df12208ce8..a896c95d1e95450fc6db18d106fbf0b8be0269d3 100644 (file)
@@ -5,49 +5,55 @@ io.files kernel make math math.parser project-euler.common
 sequences sequences.private sets sorting splitting ;
 IN: project-euler.059
 
-! https://projecteuler.net/index.php?section=problems&id=59
+! https://projecteuler.net/problem=59
 
 ! DESCRIPTION
 ! -----------
 
-! Each character on a computer is assigned a unique code and the preferred
-! standard is ASCII (American Standard Code for Information Interchange). For
-! example, uppercase A = 65, asterisk (*) = 42, and lowercase k = 107.
-
-! A modern encryption method is to take a text file, convert the bytes to
-! ASCII, then XOR each byte with a given value, taken from a secret key. The
-! advantage with the XOR function is that using the same encryption key on the
-! cipher text, restores the plain text; for example, 65 XOR 42 = 107, then 107
-! XOR 42 = 65.
-
-! For unbreakable encryption, the key is the same length as the plain text
-! message, and the key is made up of random bytes. The user would keep the
-! encrypted message and the encryption key in different locations, and without
-! both "halves", it is impossible to decrypt the message.
-
-! Unfortunately, this method is impractical for most users, so the modified
-! method is to use a password as a key. If the password is shorter than the
-! message, which is likely, the key is repeated cyclically throughout the
-! message. The balance for this method is using a sufficiently long password
-! key for security, but short enough to be memorable.
-
-! Your task has been made easy, as the encryption key consists of three lower
-! case characters. Using cipher1.txt (right click and 'Save Link/Target
-! As...'), a file containing the encrypted ASCII codes, and the knowledge that
-! the plain text must contain common English words, decrypt the message and
-! find the sum of the ASCII values in the original text.
+! Each character on a computer is assigned a unique code and the
+! preferred standard is ASCII (American Standard Code for
+! Information Interchange). For example, uppercase A = 65,
+! asterisk (*) = 42, and lowercase k = 107.
+
+! A modern encryption method is to take a text file, convert the
+! bytes to ASCII, then XOR each byte with a given value, taken
+! from a secret key. The advantage with the XOR function is that
+! using the same encryption key on the cipher text, restores the
+! plain text; for example, 65 XOR 42 = 107, then 107 XOR 42 =
+! 65.
+
+! For unbreakable encryption, the key is the same length as the
+! plain text message, and the key is made up of random bytes.
+! The user would keep the encrypted message and the encryption
+! key in different locations, and without both "halves", it is
+! impossible to decrypt the message.
+
+! Unfortunately, this method is impractical for most users, so
+! the modified method is to use a password as a key. If the
+! password is shorter than the message, which is likely, the key
+! is repeated cyclically throughout the message. The balance for
+! this method is using a sufficiently long password key for
+! security, but short enough to be memorable.
+
+! Your task has been made easy, as the encryption key consists
+! of three lower case characters. Using cipher1.txt (right click
+! and 'Save Link/Target As...'), a file containing the encrypted
+! ASCII codes, and the knowledge that the plain text must
+! contain common English words, decrypt the message and find the
+! sum of the ASCII values in the original text.
 
 
 ! SOLUTION
 ! --------
 
-! Assume that the space character will be the most common, so XOR the input
-! text with a space character then group the text into three "columns" since
-! that's how long our key is.  Then do frequency analysis on each column to
-! find out what the most likely candidate is for the key.
+! Assume that the space character will be the most common, so
+! XOR the input text with a space character then group the text
+! into three "columns" since that's how long our key is.  Then
+! do frequency analysis on each column to find out what the most
+! likely candidate is for the key.
 
-! NOTE: This technique would probably not work well in all cases, but luckily
-! it did for this particular problem.
+! NOTE: This technique would probably not work well in all
+! cases, but luckily it did for this particular problem.
 
 <PRIVATE
 
index 37719c973ddedad50902dae8f6c47bd9dbc5d1ed..3d355368eff5606b5c3768648f84f8ff29955764 100644 (file)
@@ -1,10 +1,8 @@
-! Copyright (C) 2018 John Benediktsson
+! Copyright (C) 2018 John Benediktsson.
 ! See https://factorcode.org/license.txt for BSD license
-
 USING: backtrack backtrack.private combinators.short-circuit
 kernel math math.functions math.primes
 project-euler.common sequences ;
-
 IN: project-euler.060
 
 ! https://projecteuler.net/problem=60
index 7be02b6a88ec665cf09be8050bfe471f6583e536..1033dbad78975debaf1eaae5afce50b888508ae4 100644 (file)
@@ -1,9 +1,7 @@
-! Copyright (C) 2023 Giftpflanze
+! Copyright (C) 2023 Giftpflanze.
 ! See https://factorcode.org/license.txt for BSD license
-
 USING: arrays assocs assocs.extras grouping kernel math
 project-euler.common ranges sequences sequences.extras ;
-
 IN: project-euler.061
 
 ! https://projecteuler.net/problem=61
diff --git a/extra/project-euler/061/authors.txt b/extra/project-euler/061/authors.txt
new file mode 100644 (file)
index 0000000..3050775
--- /dev/null
@@ -0,0 +1 @@
+Giftpflanze
index 41ac21903d38d5a30d0dab2f35467af6f8e72258..d5e9232a1f15f24a68fa35a55a39052fa884638b 100644 (file)
@@ -4,7 +4,7 @@ USING: arrays assocs hashtables kernel math math.functions
 project-euler.common sequences sorting ;
 IN: project-euler.062
 
-! https://projecteuler.net/index.php?section=problems&id=062
+! https://projecteuler.net/problem=62
 
 ! DESCRIPTION
 ! -----------
index 2bca4467b2e02b8daca3050657d749f5c502779e..a64c4d428bcb7206ace244a1708f3d8af1d90861 100644 (file)
@@ -1,32 +1,37 @@
 ! Copyright (c) 2009 Aaron Schaefer.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: kernel math math.functions ranges project-euler.common sequences ;
+USING: kernel math math.functions ranges project-euler.common
+sequences ;
 IN: project-euler.063
 
-! https://projecteuler.net/index.php?section=problems&id=63
+! https://projecteuler.net/problem=63
 
 ! DESCRIPTION
 ! -----------
 
-! The 5-digit number, 16807 = 7^5, is also a fifth power. Similarly, the
-! 9-digit number, 134217728 = 8^9, is a ninth power.
+! The 5-digit number, 16807 = 7^5, is also a fifth power.
+! Similarly, the 9-digit number, 134217728 = 8^9, is a ninth
+! power.
 
-! How many n-digit positive integers exist which are also an nth power?
+! How many n-digit positive integers exist which are also an nth
+! power?
 
 
 ! SOLUTION
 ! --------
 
-! Only have to check from 1 to 9 because 10^n already has too many digits.
-! In general, x^n has n digits when:
+! Only have to check from 1 to 9 because 10^n already has too
+! many digits. In general, x^n has n digits when:
 
 !     10^(n-1) <= x^n < 10^n
 
-! ...take the left side of that equation, solve for n to see where they meet:
+! ...take the left side of that equation, solve for n to see
+! where they meet:
 
 !     n = log(10) / [ log(10) - log(x) ]
 
-! Round down since we already know that particular value of n is no good.
+! Round down since we already know that particular value of n is
+! no good.
 
 : euler063 ( -- answer )
     9 [1..b] [ log [ 10 log dup ] dip - /i ] map-sum ;
diff --git a/extra/project-euler/064/064-tests.factor b/extra/project-euler/064/064-tests.factor
new file mode 100644 (file)
index 0000000..21548a1
--- /dev/null
@@ -0,0 +1,6 @@
+! Copyright (C) 2023 Giftpflanze.
+! See https://factorcode.org/license.txt for BSD license.
+USING: tools.test project-euler.064 ;
+IN: project-euler.064.tests
+
+{ 1322 } [ euler064b ] unit-test
index 0f3b9702af381351b59fb481905b15362d1168e7..80cde7453f1aee90f93b76727dcaf469f2fb7ea2 100644 (file)
@@ -1,8 +1,10 @@
+! Copyright (C) 2009 Kye W. Shi.
+! See https://factorcode.org/license.txt for BSD license.
 USING: accessors classes.tuple kernel math math.functions
 project-euler.common ranges sequences ;
 IN: project-euler.064
 
-! http://projecteuler.net/index.php?section=problems&id=64
+! http://projecteuler.net/problem=64
 
 ! DESCRIPTION
 ! -----------
diff --git a/extra/project-euler/064/authors.txt b/extra/project-euler/064/authors.txt
new file mode 100644 (file)
index 0000000..6b331a0
--- /dev/null
@@ -0,0 +1 @@
+Kye W. Shi
index ff583e310df19acf202a86deb271afdb5079763d..afb966613bca72c88dccbbc6fc491b37f5b744fa 100644 (file)
@@ -1,14 +1,16 @@
 ! Copyright (c) 2009 Guillaume Nargeot.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: kernel math lists lists.lazy project-euler.common sequences ;
+USING: kernel math lists lists.lazy project-euler.common
+sequences ;
 IN: project-euler.065
 
-! https://projecteuler.net/index.php?section=problems&id=065
+! https://projecteuler.net/problem=65
 
 ! DESCRIPTION
 ! -----------
 
-! The square root of 2 can be written as an infinite continued fraction.
+! The square root of 2 can be written as an infinite continued
+! fraction.
 
 !                      1
 ! √2 = 1 + -------------------------
@@ -20,12 +22,13 @@ IN: project-euler.065
 !                  2 + -------------
 !                      2 + ...
 
-! The infinite continued fraction can be written, √2 = [1;(2)], (2) indicates
-! that 2 repeats ad infinitum. In a similar way, √23 = [4;(1,3,1,8)].
+! The infinite continued fraction can be written, √2 = [1;(2)],
+! (2) indicates that 2 repeats ad infinitum. In a similar way,
+! √23 = [4;(1,3,1,8)].
 
-! It turns out that the sequence of partial values of continued fractions for
-! square roots provide the best rational approximations. Let us consider the
-! convergents for √2.
+! It turns out that the sequence of partial values of continued
+! fractions for square roots provide the best rational
+! approximations. Let us consider the convergents for √2.
 
 !     1   3         1     7           1       17             1         41
 ! 1 + - = - ; 1 + ----- = - ; 1 + --------- = -- ; 1 + ------------- = --
@@ -37,19 +40,22 @@ IN: project-euler.065
 !                                                              2 + -
 !                                                                  2
 
-! Hence the sequence of the first ten convergents for √2 are:
-! 1, 3/2, 7/5, 17/12, 41/29, 99/70, 239/169, 577/408, 1393/985, 3363/2378, ...
+! Hence the sequence of the first ten convergents for √2 are: 1,
+! 3/2, 7/5, 17/12, 41/29, 99/70, 239/169, 577/408, 1393/985,
+! 3363/2378, ...
 
-! What is most surprising is that the important mathematical constant,
-! e = [2; 1,2,1, 1,4,1, 1,6,1 , ... , 1,2k,1, ...].
+! What is most surprising is that the important mathematical
+! constant, e = [2; 1,2,1, 1,4,1, 1,6,1 , ... , 1,2k,1, ...].
 
 ! The first ten terms in the sequence of convergents for e are:
-! 2, 3, 8/3, 11/4, 19/7, 87/32, 106/39, 193/71, 1264/465, 1457/536, ...
+! 2, 3, 8/3, 11/4, 19/7, 87/32, 106/39, 193/71, 1264/465,
+! 1457/536, ...
 
-! The sum of digits in the numerator of the 10th convergent is 1+4+5+7=17.
+! The sum of digits in the numerator of the 10th convergent is
+! 1+4+5+7=17.
 
-! Find the sum of digits in the numerator of the 100th convergent of the
-! continued fraction for e.
+! Find the sum of digits in the numerator of the 100th
+! convergent of the continued fraction for e.
 
 
 ! SOLUTION
index c38f1ecc8f35a0e21f60134066c5d20db7d7d077..756b3a55650ab5bd69dc5f13555a0060a851c9b3 100644 (file)
@@ -4,13 +4,14 @@ USING: io.files math.parser project-euler.common
 io.encodings.ascii sequences splitting ;
 IN: project-euler.067
 
-! https://projecteuler.net/index.php?section=problems&id=67
+! https://projecteuler.net/problem=67
 
 ! DESCRIPTION
 ! -----------
 
-! By starting at the top of the triangle below and moving to adjacent numbers
-! on the row below, the maximum total from top to bottom is 23.
+! By starting at the top of the triangle below and moving to
+! adjacent numbers on the row below, the maximum total from top
+! to bottom is 23.
 
 !        3
 !       7 5
@@ -19,21 +20,23 @@ IN: project-euler.067
 
 ! That is, 3 + 7 + 4 + 9 = 23.
 
-! Find the maximum total from top to bottom in triangle.txt (right click and
-! 'Save Link/Target As...'), a 15K text file containing a triangle with
-! one-hundred rows.
+! Find the maximum total from top to bottom in triangle.txt
+! (right click and 'Save Link/Target As...'), a 15K text file
+! containing a triangle with one-hundred rows.
 
-! NOTE: This is a much more difficult version of Problem 18. It is not possible
-! to try every route to solve this problem, as there are 2^99 altogether! If you
-! could check one trillion (10^12) routes every second it would take over twenty
-! billion years to check them all. There is an efficient algorithm to solve it. ;o)
+! NOTE: This is a much more difficult version of Problem 18. It
+! is not possible to try every route to solve this problem, as
+! there are 2^99 altogether! If you could check one trillion
+! (10^12) routes every second it would take over twenty billion
+! years to check them all. There is an efficient algorithm to
+! solve it. ;o)
 
 
 ! SOLUTION
 ! --------
 
-! Propagate from bottom to top the longest cumulative path as is done in
-! problem 18.
+! Propagate from bottom to top the longest cumulative path as is
+! done in problem 18.
 
 <PRIVATE
 
index 8c14b9998f2804f4cc551cb681990c67a03fc2d1..9a7af58be3465e57b3de93df2b2605ec5040d2b2 100644 (file)
@@ -4,15 +4,16 @@ USING: combinators kernel math math.primes math.primes.factors
 ranges project-euler.common sequences sequences.extras ;
 IN: project-euler.069
 
-! https://projecteuler.net/index.php?section=problems&id=69
+! https://projecteuler.net/problem=69
 
 ! DESCRIPTION
 ! -----------
 
-! Euler's Totient function, φ(n) [sometimes called the phi function], is used
-! to determine the number of numbers less than n which are relatively prime to
-! n. For example, as 1, 2, 4, 5, 7, and 8, are all less than nine and
-! relatively prime to nine, φ(9)=6.
+! Euler's Totient function, φ(n) [sometimes called the phi
+! function], is used to determine the number of numbers less
+! than n which are relatively prime to n. For example, as 1, 2,
+! 4, 5, 7, and 8, are all less than nine and relatively prime to
+! nine, φ(9)=6.
 
 !     +----+------------------+------+-----------+
 !     | n  | Relatively Prime | φ(n) | n / φ(n)  |
@@ -28,9 +29,11 @@ IN: project-euler.069
 !     | 10 | 1,3,7,9          | 4    | 2.5       |
 !     +----+------------------+------+-----------+
 
-! It can be seen that n = 6 produces a maximum n / φ(n) for n ≤ 10.
+! It can be seen that n = 6 produces a maximum n / φ(n) for n ≤
+! 10.
 
-! Find the value of n ≤ 1,000,000 for which n / φ(n) is a maximum.
+! Find the value of n ≤ 1,000,000 for which n / φ(n) is a
+! maximum.
 
 
 ! SOLUTION
index fa8ec577e949692c700189b910377aff7c193b19..2a05b7f543fa9c08062f7384e4e849881a7cbf88 100644 (file)
@@ -1,41 +1,42 @@
-! Copyright (c) 2010 Aaron Schaefer. All rights reserved.
-! The contents of this file are licensed under the Simplified BSD License
-! A copy of the license is available at https://factorcode.org/license.txt
-USING: arrays combinators.short-circuit kernel math math.combinatorics
-math.functions math.primes project-euler.common sequences
-sequences.extras ;
+! Copyright (c) 2010 Aaron Schaefer.
+! See https://factorcode.org/license.txt for BSD license.
+USING: arrays combinators.short-circuit kernel math
+math.combinatorics math.functions math.primes
+project-euler.common sequences sequences.extras ;
 FROM: project-euler.common => permutations? ;
 IN: project-euler.070
 
-! https://projecteuler.net/index.php?section=problems&id=70
+! https://projecteuler.net/problem=70
 
 ! DESCRIPTION
 ! -----------
 
-! Euler's Totient function, φ(n) [sometimes called the phi function], is used
-! to determine the number of positive numbers less than or equal to n which are
-! relatively prime to n. For example, as 1, 2, 4, 5, 7, and 8, are all less
-! than nine and relatively prime to nine, φ(9)=6. The number 1 is considered to
-! be relatively prime to every positive number, so φ(1)=1.
+! Euler's Totient function, φ(n) [sometimes called the phi
+! function], is used to determine the number of positive numbers
+! less than or equal to n which are relatively prime to n. For
+! example, as 1, 2, 4, 5, 7, and 8, are all less than nine and
+! relatively prime to nine, φ(9)=6. The number 1 is considered
+! to be relatively prime to every positive number, so φ(1)=1.
 
-! Interestingly, φ(87109)=79180, and it can be seen that 87109 is a permutation
-! of 79180.
+! Interestingly, φ(87109)=79180, and it can be seen that 87109
+! is a permutation of 79180.
 
-! Find the value of n, 1 < n < 10^(7), for which φ(n) is a permutation of n and
-! the ratio n/φ(n) produces a minimum.
+! Find the value of n, 1 < n < 10^(7), for which φ(n) is a
+! permutation of n and the ratio n/φ(n) produces a minimum.
 
 
 ! SOLUTION
 ! --------
 
-! For n/φ(n) to be minimised, φ(n) must be as close to n as possible; that is,
-! we want to maximize φ(n). The minimal solution for n/φ(n) would be if n was
-! prime giving n/(n-1) but since n-1 never is a permutation of n it cannot be
-! prime.
+! For n/φ(n) to be minimised, φ(n) must be as close to n as
+! possible; that is, we want to maximize φ(n). The minimal
+! solution for n/φ(n) would be if n was prime giving n/(n-1) but
+! since n-1 never is a permutation of n it cannot be prime.
 
-! The next best thing would be if n only consisted of 2 prime factors close to
-! (in this case) sqrt(10000000). Hence n = p1*p2 and we only need to search
-! through a list of known prime pairs. In addition:
+! The next best thing would be if n only consisted of 2 prime
+! factors close to (in this case) sqrt(10000000). Hence n =
+! p1*p2 and we only need to search through a list of known prime
+! pairs. In addition:
 
 !     φ(p1*p2) = p1*p2*(1-1/p1)(1-1/p2) = (p1-1)(p2-1)
 
index 923730e373521230bf4a5c4236c42d9bb915460a..ec2042103670bb1ebd655e620a8fe486f9cba3c5 100644 (file)
@@ -3,34 +3,36 @@
 USING: kernel math project-euler.common sequences ;
 IN: project-euler.071
 
-! https://projecteuler.net/index.php?section=problems&id=71
+! https://projecteuler.net/problem=71
 
 ! DESCRIPTION
 ! -----------
 
-! Consider the fraction, n/d, where n and d are positive integers. If n<d and
-! HCF(n,d) = 1, it is called a reduced proper fraction.
+! Consider the fraction, n/d, where n and d are positive
+! integers. If n<d and HCF(n,d) = 1, it is called a reduced
+! proper fraction.
 
-! If we list the set of reduced proper fractions for d <= 8 in ascending order of
-! size, we get:
+! If we list the set of reduced proper fractions for d <= 8 in
+! ascending order of size, we get:
 
 !     1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7, 3/5, 5/8,
 !     2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 7/8
 
-! It can be seen that 2/5 is the fraction immediately to the left of 3/7.
-
-! By listing the set of reduced proper fractions for d <= 1,000,000 in
-! ascending order of size, find the numerator of the fraction immediately to the
+! It can be seen that 2/5 is the fraction immediately to the
 ! left of 3/7.
 
+! By listing the set of reduced proper fractions for d <=
+! 1,000,000 in ascending order of size, find the numerator of
+! the fraction immediately to the left of 3/7.
+
 
 ! SOLUTION
 ! --------
 
-! Use the properties of a Farey sequence by setting an upper bound of 3/7 and
-! then taking the mediant of that fraction and the one to its immediate left
-! repeatedly until the denominator is as close to 1000000 as possible without
-! going over.
+! Use the properties of a Farey sequence by setting an upper
+! bound of 3/7 and then taking the mediant of that fraction and
+! the one to its immediate left repeatedly until the denominator
+! is as close to 1000000 as possible without going over.
 
 : euler071 ( -- answer )
     2/5 [ dup denominator 1000000 <= ] [ 3/7 mediant dup ] produce
index b705e52f4e682ee92a941fa8237267533f9e5622..68b41648b9a9bee03db64084498de9a03b7e62fb 100644 (file)
@@ -1,26 +1,28 @@
 ! Copyright (c) 2009 Guillaume Nargeot.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: math.primes.factors project-euler.common ranges sequences ;
+USING: math.primes.factors project-euler.common ranges sequences
+;
 IN: project-euler.072
 
-! https://projecteuler.net/index.php?section=problems&id=072
+! https://projecteuler.net/problem=72
 
 ! DESCRIPTION
 ! -----------
 
-! Consider the fraction, n/d, where n and d are positive integers.
-! If n<d and HCF(n,d)=1, it is called a reduced proper fraction.
+! Consider the fraction, n/d, where n and d are positive
+! integers. If n<d and HCF(n,d)=1, it is called a reduced proper
+! fraction.
 
-! If we list the set of reduced proper fractions for d ≤ 8 in ascending order
-! of size, we get:
+! If we list the set of reduced proper fractions for d ≤ 8 in
+! ascending order of size, we get:
 
-! 1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7, 3/5, 5/8, 2/3,
-! 5/7, 3/4, 4/5, 5/6, 6/7, 7/8
+! 1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7,
+! 3/5, 5/8, 2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 7/8
 
 ! It can be seen that there are 21 elements in this set.
 
-! How many elements would be contained in the set of reduced proper fractions
-! for d ≤ 1,000,000?
+! How many elements would be contained in the set of reduced
+! proper fractions for d ≤ 1,000,000?
 
 
 ! SOLUTION
index f4360f32774bb366b018e7e2ef8fee8f7e1d8225..1d1a4ebbb285b4125ac44dee82819dd451b9981a 100644 (file)
@@ -3,32 +3,33 @@
 USING: kernel math project-euler.common ;
 IN: project-euler.073
 
-! https://projecteuler.net/index.php?section=problems&id=73
+! https://projecteuler.net/problem=73
 
 ! DESCRIPTION
 ! -----------
 
-! Consider the fraction, n/d, where n and d are positive integers. If n<d and
-! HCF(n,d) = 1, it is called a reduced proper fraction.
+! Consider the fraction, n/d, where n and d are positive
+! integers. If n<d and HCF(n,d) = 1, it is called a reduced
+! proper fraction.
 
-! If we list the set of reduced proper fractions for d <= 8 in ascending order of
-! size, we get:
+! If we list the set of reduced proper fractions for d <= 8 in
+! ascending order of size, we get:
 
-!     1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7, 3/5, 5/8,
-!     2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 7/8
+!     1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2,
+!     4/7, 3/5, 5/8, 2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 7/8
 
 ! It can be seen that there are 3 fractions between 1/3 and 1/2.
 
-! How many fractions lie between 1/3 and 1/2 in the sorted set of reduced
-! proper fractions for d <= 10,000?
+! How many fractions lie between 1/3 and 1/2 in the sorted set
+! of reduced proper fractions for d <= 10,000?
 
 
 ! SOLUTION
 ! --------
 
-! Use the properties of a Farey sequence and mediants to recursively generate
-! the next fraction until the denominator is as close to 1000000 as possible
-! without going over.
+! Use the properties of a Farey sequence and mediants to
+! recursively generate the next fraction until the denominator
+! is as close to 1000000 as possible without going over.
 
 <PRIVATE
 
index 6ac1c0adf7df3fd504ffeeb50d2d82cf7b22993d..8d1024aa6c2fca690d2c2c907cd6061a45027a8e 100644 (file)
@@ -4,37 +4,37 @@ USING: hash-sets kernel ranges project-euler.common
 sequences sets ;
 IN: project-euler.074
 
-! https://projecteuler.net/index.php?section=problems&id=074
+! https://projecteuler.net/problem=74
 
 ! DESCRIPTION
 ! -----------
 
-! The number 145 is well known for the property that the sum of the factorial
-! of its digits is equal to 145:
+! The number 145 is well known for the property that the sum of
+! the factorial of its digits is equal to 145:
 
 ! 1! + 4! + 5! = 1 + 24 + 120 = 145
 
-! Perhaps less well known is 169, in that it produces the longest chain of
-! numbers that link back to 169; it turns out that there are only three such
-! loops that exist:
+! Perhaps less well known is 169, in that it produces the
+! longest chain of numbers that link back to 169; it turns out
+! that there are only three such loops that exist:
 
 ! 169 → 363601 → 1454 → 169
 ! 871 → 45361 → 871
 ! 872 → 45362 → 872
 
-! It is not difficult to prove that EVERY starting number will eventually get
-! stuck in a loop. For example,
+! It is not difficult to prove that EVERY starting number will
+! eventually get stuck in a loop. For example,
 
 ! 69 → 363600 → 1454 → 169 → 363601 (→ 1454)
 ! 78 → 45360 → 871 → 45361 (→ 871)
 ! 540 → 145 (→ 145)
 
-! Starting with 69 produces a chain of five non-repeating terms, but the
-! longest non-repeating chain with a starting number below one million is sixty
-! terms.
+! Starting with 69 produces a chain of five non-repeating terms,
+! but the longest non-repeating chain with a starting number
+! below one million is sixty terms.
 
-! How many chains, with a starting number below one million, contain exactly
-! sixty non-repeating terms?
+! How many chains, with a starting number below one million,
+! contain exactly sixty non-repeating terms?
 
 
 ! SOLUTION
index 3a694b8a99694f66c6c589a5e1a174349c8732be..04ea4350b8d0ab52ecf12e3cb4538e21adfc886f 100644 (file)
@@ -1,16 +1,17 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: arrays kernel math ranges
-    namespaces project-euler.common sequences ;
+USING: arrays kernel math ranges namespaces project-euler.common
+sequences ;
 IN: project-euler.075
 
-! https://projecteuler.net/index.php?section=problems&id=75
+! https://projecteuler.net/problem=75
 
 ! DESCRIPTION
 ! -----------
 
-! It turns out that 12 cm is the smallest length of wire can be bent to form a
-! right angle triangle in exactly one way, but there are many more examples.
+! It turns out that 12 cm is the smallest length of wire can be
+! bent to form a right angle triangle in exactly one way, but
+! there are many more examples.
 
 !     12 cm: (3,4,5)
 !     24 cm: (6,8,10)
@@ -19,28 +20,31 @@ IN: project-euler.075
 !     40 cm: (8,15,17)
 !     48 cm: (12,16,20)
 
-! In contrast, some lengths of wire, like 20 cm, cannot be bent to form a right
-! angle triangle, and other lengths allow more than one solution to be found;
-! for example, using 120 cm it is possible to form exactly three different
-! right angle triangles.
+! In contrast, some lengths of wire, like 20 cm, cannot be bent
+! to form a right angle triangle, and other lengths allow more
+! than one solution to be found; for example, using 120 cm it is
+! possible to form exactly three different right angle
+! triangles.
 
 !     120 cm: (30,40,50), (20,48,52), (24,45,51)
 
-! Given that L is the length of the wire, for how many values of L ≤ 2,000,000
-! can exactly one right angle triangle be formed?
+! Given that L is the length of the wire, for how many values of
+! L ≤ 2,000,000 can exactly one right angle triangle be formed?
 
 
 ! SOLUTION
 ! --------
 
-! Algorithm adapted from https://mathworld.wolfram.com/PythagoreanTriple.html
+! Algorithm adapted from
+! https://mathworld.wolfram.com/PythagoreanTriple.html
 ! Identical implementation as problem #39
 
-! Basically, this makes an array of 2000000 zeros, recursively creates
-! primitive triples using the three transforms and then increments the array at
-! index [a+b+c] by one for each triple's sum AND its multiples under 2000000
-! (to account for non-primitive triples). The answer is just the total number
-! of indexes that are equal to one.
+! Basically, this makes an array of 2000000 zeros, recursively
+! creates primitive triples using the three transforms and then
+! increments the array at index [a+b+c] by one for each triple's
+! sum AND its multiples under 2000000 (to account for
+! non-primitive triples). The answer is just the total number of
+! indexes that are equal to one.
 
 SYMBOL: p-count
 
index 62c5933d5308934266c349becda311d6b11d89b6..937b0ad9e87f1b2bcf7fb730511a2d9e46635874 100644 (file)
@@ -1,9 +1,10 @@
 ! Copyright (c) 2008 Eric Mertens.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: arrays assocs kernel math math.order ranges sequences project-euler.common ;
+USING: arrays assocs kernel math math.order ranges sequences
+project-euler.common ;
 IN: project-euler.076
 
-! https://projecteuler.net/index.php?section=problems&id=76
+! https://projecteuler.net/problem=76
 
 ! DESCRIPTION
 ! -----------
index 1e80855ddb4ae8d5704849cd79bc13f39791a492..a322525217d4bb1f2b430f20c0d52d6052d53214 100644 (file)
@@ -1,24 +1,25 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See https://factorcode.org/license.txt for BSD license.
 USING: assocs io.encodings.ascii io.files kernel make math
-    math.parser sequences sets project-euler.common ;
+math.parser sequences sets project-euler.common ;
 IN: project-euler.079
 
-! https://projecteuler.net/index.php?section=problems&id=79
+! https://projecteuler.net/problem=79
 
 ! DESCRIPTION
 ! -----------
 
-! A common security method used for online banking is to ask the user for three
-! random characters from a passcode. For example, if the passcode was 531278,
-! they may asked for the 2nd, 3rd, and 5th characters; the expected reply would
-! be: 317.
+! A common security method used for online banking is to ask the
+! user for three random characters from a passcode. For example,
+! if the passcode was 531278, they may asked for the 2nd, 3rd,
+! and 5th characters; the expected reply would be: 317.
 
-! The text file, keylog.txt, contains fifty successful login attempts.
+! The text file, keylog.txt, contains fifty successful login
+! attempts.
 
-! Given that the three characters are always asked for in order, analyse the
-! file so as to determine the shortest possible secret passcode of unknown
-! length.
+! Given that the three characters are always asked for in order,
+! analyse the file so as to determine the shortest possible
+! secret passcode of unknown length.
 
 
 ! SOLUTION
index 74cfd5885be8809a402c294c08caa3f2fc0f294f..b65e2f9017fb26234cf247a0ad5ec13531fea1b1 100644 (file)
@@ -4,7 +4,7 @@ USING: io.encodings.ascii io.files kernel math math.order
 math.parser project-euler.common sequences splitting ;
 IN: project-euler.081
 
-! https://projecteuler.net/index.php?section=problems&id=081
+! https://projecteuler.net/problem=81
 
 ! DESCRIPTION
 ! -----------
index 8f4bc7b10d511a18c6622aa767e2db48e81cc9f1..0adad178083066999827776e8862aebd7b631a79 100644 (file)
@@ -4,22 +4,24 @@ USING: accessors kernel math ranges project-euler.common
 sequences ;
 IN: project-euler.085
 
-! https://projecteuler.net/index.php?section=problems&id=85
+! https://projecteuler.net/problem=85
 
 ! DESCRIPTION
 ! -----------
 
-! By counting carefully it can be seen that a rectangular grid measuring
-! 3 by 2 contains eighteen rectangles.
+! By counting carefully it can be seen that a rectangular grid
+! measuring 3 by 2 contains eighteen rectangles.
 
-! Although there exists no rectangular grid that contains exactly two million
-! rectangles, find the area of the grid with the nearest solution.
+! Although there exists no rectangular grid that contains
+! exactly two million rectangles, find the area of the grid with
+! the nearest solution.
 
 
 ! SOLUTION
 ! --------
 
-! A grid measuring x by y contains x * (x + 1) * y * (x + 1) / 4 rectangles.
+! A grid measuring x by y contains x * (x + 1) * y * (x + 1) / 4
+! rectangles.
 
 <PRIVATE
 
diff --git a/extra/project-euler/087/087-tests.factor b/extra/project-euler/087/087-tests.factor
new file mode 100644 (file)
index 0000000..35a1f22
--- /dev/null
@@ -0,0 +1,6 @@
+! Copyright (C) 2023 Giftpflanze.
+! See https://factorcode.org/license.txt for BSD license.
+USING: tools.test project-euler.087 ;
+IN: project-euler.087.tests
+
+{ 1097343 } [ euler087 ] unit-test
index cd331d567440274ee21f402b98ebea9cb9aa4b47..fc41af3987ba3676d85efcab22cab2196ba7cb33 100644 (file)
@@ -1,9 +1,10 @@
-USING: math math.functions math.primes
-project-euler.common sequences sets ;
-
+! Copyright (C) 2009 Kye W. Shi.
+! See https://factorcode.org/license.txt for BSD license.
+USING: math math.functions math.primes project-euler.common
+sequences sets ;
 IN: project-euler.087
 
-! https://projecteuler.net/index.php?section=problems&id=87
+! https://projecteuler.net/problem=87
 
 ! DESCRIPTION
 ! -----------
diff --git a/extra/project-euler/087/authors.txt b/extra/project-euler/087/authors.txt
new file mode 100644 (file)
index 0000000..6b331a0
--- /dev/null
@@ -0,0 +1 @@
+Kye W. Shi
index 49b7a96a298b6549e71d56f2759769d9f1f6ddf5..c908bc3d0d043a5a238957a908cb56e325a877e3 100644 (file)
@@ -4,17 +4,17 @@ USING: io.encodings.ascii io.files kernel math
 project-euler.common roman sequences ;
 IN: project-euler.089
 
-! https://projecteuler.net/index.php?section=problems&id=089
+! https://projecteuler.net/problem=89
 
 ! DESCRIPTION
 ! -----------
 
-! The rules for writing Roman numerals allow for many ways of writing
-! each number (see FAQ: Roman Numerals). However, there is always a
-! "best" way of writing a particular number.
+! The rules for writing Roman numerals allow for many ways of
+! writing each number (see FAQ: Roman Numerals). However, there
+! is always a "best" way of writing a particular number.
 
-! For example, the following represent all of the legitimate ways of
-! writing the number sixteen:
+! For example, the following represent all of the legitimate
+! ways of writing the number sixteen:
 
 ! IIIIIIIIIIIIIIII
 ! VIIIIIIIIIII
@@ -23,16 +23,17 @@ IN: project-euler.089
 ! VVVI
 ! XVI
 
-! The last example being considered the most efficient, as it uses
-! the least number of numerals.
+! The last example being considered the most efficient, as it
+! uses the least number of numerals.
 
-! The 11K text file, roman.txt (right click and 'Save Link/Target As...'),
-! contains one thousand numbers written in valid, but not necessarily
-! minimal, Roman numerals; that is, they are arranged in descending units
-! and obey the subtractive pair rule (see FAQ for the definitive rules
-! for this problem).
+! The 11K text file, roman.txt (right click and 'Save
+! Link/Target As...'), contains one thousand numbers written in
+! valid, but not necessarily minimal, Roman numerals; that is,
+! they are arranged in descending units and obey the subtractive
+! pair rule (see FAQ for the definitive rules for this problem).
 
-! Find the number of characters saved by writing each of these in their minimal form.
+! Find the number of characters saved by writing each of these
+! in their minimal form.
 
 ! SOLUTION
 ! --------
index ac47874d3e1f3a140454384e90dd737c060ecb42..81d7dde527b190445d4385d6354588fb8f55c116 100644 (file)
@@ -3,22 +3,23 @@
 USING: kernel math ranges project-euler.common sequences ;
 IN: project-euler.092
 
-! https://projecteuler.net/index.php?section=problems&id=92
+! https://projecteuler.net/problem=92
 
 ! DESCRIPTION
 ! -----------
 
-! A number chain is created by continuously adding the square of the digits in
-! a number to form a new number until it has been seen before.
+! A number chain is created by continuously adding the square of
+! the digits in a number to form a new number until it has been
+! seen before.
 
 ! For example,
 
 !     44 -> 32 -> 13 -> 10 -> 1 -> 1
 !     85 -> 89 -> 145 -> 42 -> 20 -> 4 -> 16 -> 37 -> 58 -> 89
 
-! Therefore any chain that arrives at 1 or 89 will become stuck in an endless
-! loop. What is most amazing is that EVERY starting number will eventually
-! arrive at 1 or 89.
+! Therefore any chain that arrives at 1 or 89 will become stuck
+! in an endless loop. What is most amazing is that EVERY
+! starting number will eventually arrive at 1 or 89.
 
 ! How many starting numbers below ten million will arrive at 89?
 
index dfbf4fd54ef0f68b48513581d2132584ad8a17a1..6638310f047a62a7dbbcc1e8f24a0c27804edc01 100644 (file)
@@ -3,18 +3,19 @@
 USING: math math.functions project-euler.common ;
 IN: project-euler.097
 
-! https://projecteuler.net/index.php?section=problems&id=97
+! https://projecteuler.net/problem=97
 
 ! DESCRIPTION
 ! -----------
 
-! The first known prime found to exceed one million digits was discovered in
-! 1999, and is a Mersenne prime of the form 2^6972593 − 1; it contains exactly
-! 2,098,960 digits. Subsequently other Mersenne primes, of the form 2p − 1,
-! have been found which contain more digits.
+! The first known prime found to exceed one million digits was
+! discovered in 1999, and is a Mersenne prime of the form
+! 2^6972593 − 1; it contains exactly 2,098,960 digits.
+! Subsequently other Mersenne primes, of the form 2p − 1, have
+! been found which contain more digits.
 
-! However, in 2004 there was found a massive non-Mersenne prime which contains
-! 2,357,207 digits: 28433 * 2^7830457 + 1.
+! However, in 2004 there was found a massive non-Mersenne prime
+! which contains 2,357,207 digits: 28433 * 2^7830457 + 1.
 
 ! Find the last ten digits of this prime number.
 
index 46535ed124f84b18786858f3c6b5783494c78c87..1e4b62e2935e499d02fa5d1c8835a9dc51a86e67 100644 (file)
@@ -5,29 +5,33 @@ math.parser math.vectors project-euler.common sequences
 sequences.extras splitting ;
 IN: project-euler.099
 
-! https://projecteuler.net/index.php?section=problems&id=99
+! https://projecteuler.net/problem=99
 
 ! DESCRIPTION
 ! -----------
 
-! Comparing two numbers written in index form like 2^11 and 3^7 is not difficult,
-! as any calculator would confirm that 2^11 = 2048 < 3^7 = 2187.
+! Comparing two numbers written in index form like 2^11 and 3^7
+! is not difficult, as any calculator would confirm that 2^11 =
+! 2048 < 3^7 = 2187.
 
-! However, confirming that 632382^518061 519432^525806 would be much more
-! difficult, as both numbers contain over three million digits.
+! However, confirming that 632382^518061 519432^525806 would be
+! much more difficult, as both numbers contain over three
+! million digits.
 
-! Using base_exp.txt (right click and 'Save Link/Target As...'), a 22K text
-! file containing one thousand lines with a base/exponent pair on each line,
-! determine which line number has the greatest numerical value.
+! Using base_exp.txt (right click and 'Save Link/Target As...'),
+! a 22K text file containing one thousand lines with a
+! base/exponent pair on each line, determine which line number
+! has the greatest numerical value.
 
-! NOTE: The first two lines in the file represent the numbers in the example
-! given above.
+! NOTE: The first two lines in the file represent the numbers in
+! the example given above.
 
 
 ! SOLUTION
 ! --------
 
-! Use logarithms to make the calculations necessary more manageable.
+! Use logarithms to make the calculations necessary more
+! manageable.
 
 <PRIVATE
 
index d6cad8e9012f0c6f88dd47a4509ee2ef951bf44a..9fd82cbf3dc0b8b94efbcb95ee9e72fec9c9f269 100644 (file)
@@ -3,20 +3,23 @@
 USING: kernel math math.functions project-euler.common ;
 IN: project-euler.100
 
-! https://projecteuler.net/index.php?section=problems&id=100
+! https://projecteuler.net/problem=100
 
-! DESCRIPTION ! -----------
+! DESCRIPTION
+! -----------
 
-! If a box contains twenty-one colored discs, composed of fifteen blue discs
-!  and six red discs, and two discs were taken at random, it can be seen that
-!  the probability of taking two blue discs, P(BB) = (15/21)*(14/20) = 1/2.
+! If a box contains twenty-one colored discs, composed of
+! fifteen blue discs and six red discs, and two discs were taken
+! at random, it can be seen that the probability of taking two
+! blue discs, P(BB) = (15/21)*(14/20) = 1/2.
 
-! The next such arrangement, for which there is exactly 50% chance of taking
-!  two blue discs at random, is a box containing eighty-five blue discs and
-!  thirty-five red discs.
+! The next such arrangement, for which there is exactly 50%
+! chance of taking two blue discs at random, is a box containing
+! eighty-five blue discs and thirty-five red discs.
 
-! By finding the first arrangement to contain over 10^12 = 1,000,000,000,000
-!  discs in total, determine the number of blue discs that the box would contain.
+! By finding the first arrangement to contain over 10^12 =
+! 1,000,000,000,000 discs in total, determine the number of blue
+! discs that the box would contain.
 
 
 ! SOLUTION
index 07503980db74a7fb677d23d9ba95eb891252fd88..59249a4ecc452b4f02f25397508291610e71fb00 100644 (file)
@@ -4,28 +4,30 @@ USING: arrays grouping io.encodings.ascii io.files kernel math
 math.parser sequences splitting project-euler.common ;
 IN: project-euler.102
 
-! https://projecteuler.net/index.php?section=problems&id=102
+! https://projecteuler.net/problem=102
 
 ! DESCRIPTION
 ! -----------
 
-! Three distinct points are plotted at random on a Cartesian plane, for which
-! -1000 ≤ x, y ≤ 1000, such that a triangle is formed.
+! Three distinct points are plotted at random on a Cartesian
+! plane, for which -1000 ≤ x, y ≤ 1000, such that a triangle is
+! formed.
 
 ! Consider the following two triangles:
 
 ! A(-340,495), B(-153,-910), C(835,-947)
 ! X(-175,41), Y(-421,-714), Z(574,-645)
 
-! It can be verified that triangle ABC contains the origin, whereas triangle
-! XYZ does not.
+! It can be verified that triangle ABC contains the origin,
+! whereas triangle XYZ does not.
 
-! Using triangles.txt (right click and 'Save Link/Target As...'), a 27K text
-! file containing the coordinates of one thousand "random" triangles, find the
-! number of triangles for which the interior contains the origin.
+! Using triangles.txt (right click and 'Save Link/Target
+! As...'), a 27K text file containing the coordinates of one
+! thousand "random" triangles, find the number of triangles for
+! which the interior contains the origin.
 
-! NOTE: The first two examples in the file represent the triangles in the
-! example given above.
+! NOTE: The first two examples in the file represent the
+! triangles in the example given above.
 
 
 ! SOLUTION
index f02077c7d12cc0e76cd208d0ec81a0d21c5d5f22..54c9bc5bfb286f152afcc0c3b1c53e5204ca90ec 100644 (file)
@@ -3,29 +3,32 @@
 USING: kernel math project-euler.common sequences sorting ;
 IN: project-euler.112
 
-! https://projecteuler.net/index.php?section=problems&id=112
+! https://projecteuler.net/problem=112
 
 ! DESCRIPTION
 ! -----------
 
-! Working from left-to-right if no digit is exceeded by the digit to its left
-! it is called an increasing number; for example, 134468.
+! Working from left-to-right if no digit is exceeded by the
+! digit to its left it is called an increasing number; for
+! example, 134468.
 
-! Similarly if no digit is exceeded by the digit to its right it is called a
-! decreasing number; for example, 66420.
+! Similarly if no digit is exceeded by the digit to its right it
+! is called a decreasing number; for example, 66420.
 
-! We shall call a positive integer that is neither increasing nor decreasing a
-! "bouncy" number; for example, 155349.
+! We shall call a positive integer that is neither increasing
+! nor decreasing a "bouncy" number; for example, 155349.
 
-! Clearly there cannot be any bouncy numbers below one-hundred, but just over
-! half of the numbers below one-thousand (525) are bouncy. In fact, the least
-! number for which the proportion of bouncy numbers first reaches 50% is 538.
+! Clearly there cannot be any bouncy numbers below one-hundred,
+! but just over half of the numbers below one-thousand (525) are
+! bouncy. In fact, the least number for which the proportion of
+! bouncy numbers first reaches 50% is 538.
 
-! Surprisingly, bouncy numbers become more and more common and by the time we
-! reach 21780 the proportion of bouncy numbers is equal to 90%.
+! Surprisingly, bouncy numbers become more and more common and
+! by the time we reach 21780 the proportion of bouncy numbers is
+! equal to 90%.
 
-! Find the least number for which the proportion of bouncy numbers is exactly
-! 99%.
+! Find the least number for which the proportion of bouncy
+! numbers is exactly 99%.
 
 
 ! SOLUTION
index 2851c48346172036ce6910b54bf1731946b5ce0f..6bf979233f62683d2ca89856fa417baf5fff2d7d 100644 (file)
@@ -3,32 +3,33 @@
 USING: kernel math ranges sequences project-euler.common ;
 IN: project-euler.116
 
-! https://projecteuler.net/index.php?section=problems&id=116
+! https://projecteuler.net/problem=116
 
 ! DESCRIPTION
 ! -----------
 
-! A row of five black square tiles is to have a number of its tiles replaced
-! with colored oblong tiles chosen from red (length two), green (length
-! three), or blue (length four).
+! A row of five black square tiles is to have a number of its
+! tiles replaced with colored oblong tiles chosen from red
+! (length two), green (length three), or blue (length four).
 
-! If red tiles are chosen there are exactly seven ways this can be done.
-! If green tiles are chosen there are three ways.
-! And if blue tiles are chosen there are two ways.
+! If red tiles are chosen there are exactly seven ways this can
+! be done. If green tiles are chosen there are three ways. And
+! if blue tiles are chosen there are two ways.
 
-! Assuming that colors cannot be mixed there are 7 + 3 + 2 = 12 ways of
-! replacing the black tiles in a row measuring five units in length.
+! Assuming that colors cannot be mixed there are 7 + 3 + 2 = 12
+! ways of replacing the black tiles in a row measuring five
+! units in length.
 
-! How many different ways can the black tiles in a row measuring fifty units in
-! length be replaced if colors cannot be mixed and at least one colored tile
-! must be used?
+! How many different ways can the black tiles in a row measuring
+! fifty units in length be replaced if colors cannot be mixed
+! and at least one colored tile must be used?
 
 
 ! SOLUTION
 ! --------
 
-! This solution uses a simple dynamic programming approach using the
-! following recurence relation
+! This solution uses a simple dynamic programming approach using
+! the following recurence relation
 
 ! ways(n,_) = 0   | n < 0
 ! ways(0,_) = 1
index 6912364aa3b16f079d4de6e0afb85b72877138bc..5d332eb9febfc80362e2f908553fa0fc1596ebe2 100644 (file)
@@ -3,24 +3,26 @@
 USING: kernel math project-euler.common sequences ;
 IN: project-euler.117
 
-! https://projecteuler.net/index.php?section=problems&id=117
+! https://projecteuler.net/problem=117
 
 ! DESCRIPTION
 ! -----------
 
-! Using a combination of black square tiles and oblong tiles chosen
-! from: red tiles measuring two units, green tiles measuring three
-! units, and blue tiles measuring four units, it is possible to tile a
-! row measuring five units in length in exactly fifteen different ways.
+! Using a combination of black square tiles and oblong tiles
+! chosen from: red tiles measuring two units, green tiles
+! measuring three units, and blue tiles measuring four units, it
+! is possible to tile a row measuring five units in length in
+! exactly fifteen different ways.
 
-! How many ways can a row measuring fifty units in length be tiled?
+! How many ways can a row measuring fifty units in length be
+! tiled?
 
 
 ! SOLUTION
 ! --------
 
-! This solution uses a simple dynamic programming approach using the
-! following recurence relation
+! This solution uses a simple dynamic programming approach using
+! the following recurence relation
 
 ! ways(i) = 1 | i <= 0
 ! ways(i) = ways(i-4) + ways(i-3) + ways(i-2) + ways(i-1)
index 9a504f1959fbe9dd8903fdd475cde1f997d365a6..5eb8f6f761423199589d1aacadf4bc13dd89766c 100644 (file)
@@ -1,19 +1,21 @@
 ! Copyright (c) 2009 Guillaume Nargeot.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: arrays kernel math.primes.factors
-ranges project-euler.common sequences sorting ;
+USING: arrays kernel math.primes.factors ranges
+project-euler.common sequences sorting ;
 IN: project-euler.124
 
-! https://projecteuler.net/index.php?section=problems&id=124
+! https://projecteuler.net/problem=124
 
 ! DESCRIPTION
 ! -----------
 
-! The radical of n, rad(n), is the product of distinct prime factors of n.
-! For example, 504 = 2^3 × 3^2 × 7, so rad(504) = 2 × 3 × 7 = 42.
+! The radical of n, rad(n), is the product of distinct prime
+! factors of n. For example, 504 = 2^3 × 3^2 × 7, so rad(504) =
+! 2 × 3 × 7 = 42.
 
-! If we calculate rad(n) for 1 ≤ n ≤ 10, then sort them on rad(n),
-! and sorting on n if the radical values are equal, we get:
+! If we calculate rad(n) for 1 ≤ n ≤ 10, then sort them on
+! rad(n), and sorting on n if the radical values are equal, we
+! get:
 
 !   Unsorted          Sorted
 !   n  rad(n)       n  rad(n) k
@@ -28,8 +30,8 @@ IN: project-euler.124
 !   9    3          7    7    9
 !  10   10         10   10   10
 
-! Let E(k) be the kth element in the sorted n column; for example,
-! E(4) = 8 and E(6) = 9.
+! Let E(k) be the kth element in the sorted n column; for
+! example, E(4) = 8 and E(6) = 9.
 
 ! If rad(n) is sorted for 1 ≤ n ≤ 100000, find E(10000).
 
index 22e0f8c6c11b3c8c3a9740812adb159364de1b11..6e4f53043e39581f107af05c450a42377f472348 100644 (file)
@@ -4,19 +4,19 @@ USING: arrays kernel lists lists.lazy math math.algebra
 math.functions math.primes.lists project-euler.common ;
 IN: project-euler.134
 
-! https://projecteuler.net/index.php?section=problems&id=134
+! https://projecteuler.net/problem=134
 
 ! DESCRIPTION
 ! -----------
 
-! Consider the consecutive primes p1 = 19 and p2 = 23. It can be verified that
-! 1219 is the smallest number such that the last digits are formed by p1 whilst
-! also being divisible by p2.
+! Consider the consecutive primes p1 = 19 and p2 = 23. It can be
+! verified that 1219 is the smallest number such that the last
+! digits are formed by p1 whilst also being divisible by p2.
 
-! In fact, with the exception of p1 = 3 and p2 = 5, for every pair of
-! consecutive primes, p2 p1, there exist values of n for which the last digits
-! are formed by p1 and n is divisible by p2. Let S be the smallest of these
-! values of n.
+! In fact, with the exception of p1 = 3 and p2 = 5, for every
+! pair of consecutive primes, p2 p1, there exist values of n for
+! which the last digits are formed by p1 and n is divisible by
+! p2. Let S be the smallest of these values of n.
 
 ! Find S for every pair of consecutive primes with 5 p1 1000000.
 
@@ -30,9 +30,9 @@ IN: project-euler.134
 
 <PRIVATE
 
-! Compute S for a given pair (p1, p2) -- that is the smallest positive
-! number such that X = p1 [npt] and X = 0 [p2] (npt being the smallest
-! power of 10 above p1)
+! Compute S for a given pair (p1, p2) -- that is the smallest
+! positive number such that X = p1 [npt] and X = 0 [p2] (npt
+! being the smallest power of 10 above p1)
 : s ( p1 p2 -- s )
     over 0 2array rot next-power-of-10 rot 2array chinese-remainder ;
 
index 614353d548ee1f83247002e4d3bdf55f70e2e952..2e34abe038397df8c1039649951354e962d6ce57 100644 (file)
@@ -1,15 +1,16 @@
 ! Copyright (c) 2008 Eric Mertens.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: kernel math math.functions sequences project-euler.common ;
+USING: kernel math math.functions sequences project-euler.common
+;
 IN: project-euler.148
 
-! https://projecteuler.net/index.php?section=problems&id=148
+! https://projecteuler.net/problem=148
 
 ! DESCRIPTION
 ! -----------
 
-! We can easily verify that none of the entries in the first seven rows of
-! Pascal's triangle are divisible by 7:
+! We can easily verify that none of the entries in the first
+! seven rows of Pascal's triangle are divisible by 7:
 
 !                             1
 !                         1       1
@@ -19,11 +20,11 @@ IN: project-euler.148
 !         1       5      10      10       5       1
 !    1        6      15      20      15       6       1
 
-! However, if we check the first one hundred rows, we will find that only 2361
-! of the 5050 entries are not divisible by 7.
+! However, if we check the first one hundred rows, we will find
+! that only 2361 of the 5050 entries are not divisible by 7.
 
-! Find the number of entries which are not divisible by 7 in the first one
-! billion (10^9) rows of Pascal's triangle.
+! Find the number of entries which are not divisible by 7 in the
+! first one billion (10^9) rows of Pascal's triangle.
 
 
 ! SOLUTION
index fe5c86d81850c3d7e5328ab4f69b72aa60a9e92f..acd10c4f2b8b8618784562f3f19a35bca685fb64 100644 (file)
@@ -4,22 +4,22 @@ USING: kernel math math.order ranges math.statistics
 project-euler.common sequences sequences.private ;
 IN: project-euler.150
 
-! https://projecteuler.net/index.php?section=problems&id=150
+! https://projecteuler.net/problem=150
 
 ! DESCRIPTION
 ! -----------
 
-! In a triangular array of positive and negative integers, we wish to find a
-! sub-triangle such that the sum of the numbers it contains is the smallest
-! possible.
+! In a triangular array of positive and negative integers, we
+! wish to find a sub-triangle such that the sum of the numbers
+! it contains is the smallest possible.
 
-! In the example below, it can be easily verified that the marked triangle
-! satisfies this condition having a sum of -42.
+! In the example below, it can be easily verified that the
+! marked triangle satisfies this condition having a sum of -42.
 
-! We wish to make such a triangular array with one thousand rows, so we
-! generate 500500 pseudo-random numbers sk in the range +/-2^19, using a type of
-! random number generator (known as a Linear Congruential Generator) as
-! follows:
+! We wish to make such a triangular array with one thousand
+! rows, so we generate 500500 pseudo-random numbers sk in the
+! range +/-2^19, using a type of random number generator (known
+! as a Linear Congruential Generator) as follows:
 
 ! ...
 
index 6d2f80d13125996fe41cd9b0990c6a83f9c48d60..11e16883f1bf9ebf4bfa0437f73bd5753e4748bd 100644 (file)
@@ -1,35 +1,40 @@
 ! Copyright (c) 2008 Eric Mertens.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: assocs combinators kernel math math.order namespaces sequences project-euler.common ;
+USING: assocs combinators kernel math math.order namespaces
+sequences project-euler.common ;
 IN: project-euler.151
 
-! https://projecteuler.net/index.php?section=problems&id=151
+! https://projecteuler.net/problem=151
 
 ! DESCRIPTION
 ! -----------
 
-! A printing shop runs 16 batches (jobs) every week and each batch requires a
-! sheet of special color-proofing paper of size A5.
+! A printing shop runs 16 batches (jobs) every week and each
+! batch requires a sheet of special color-proofing paper of size
+! A5.
 
-! Every Monday morning, the foreman opens a new envelope, containing a large
-! sheet of the special paper with size A1.
+! Every Monday morning, the foreman opens a new envelope,
+! containing a large sheet of the special paper with size A1.
 
-! He proceeds to cut it in half, thus getting two sheets of size A2. Then he
-! cuts one of them in half to get two sheets of size A3 and so on until he
-! obtains the A5-size sheet needed for the first batch of the week.
+! He proceeds to cut it in half, thus getting two sheets of size
+! A2. Then he cuts one of them in half to get two sheets of size
+! A3 and so on until he obtains the A5-size sheet needed for the
+! first batch of the week.
 
 ! All the unused sheets are placed back in the envelope.
 
-! At the beginning of each subsequent batch, he takes from the envelope one
-! sheet of paper at random. If it is of size A5, he uses it. If it is larger,
-! he repeats the 'cut-in-half' procedure until he has what he needs and any
-! remaining sheets are always placed back in the envelope.
+! At the beginning of each subsequent batch, he takes from the
+! envelope one sheet of paper at random. If it is of size A5, he
+! uses it. If it is larger, he repeats the 'cut-in-half'
+! procedure until he has what he needs and any remaining sheets
+! are always placed back in the envelope.
 
-! Excluding the first and last batch of the week, find the expected number of
-! times (during each week) that the foreman finds a single sheet of paper in
-! the envelope.
+! Excluding the first and last batch of the week, find the
+! expected number of times (during each week) that the foreman
+! finds a single sheet of paper in the envelope.
 
-! Give your answer rounded to six decimal places using the format x.xxxxxx .
+! Give your answer rounded to six decimal places using the
+! format x.xxxxxx .
 
 
 ! SOLUTION
index 61f9ed8c3df7e700aae7028ed380948b85e558e4..0a038cf67ae319638d06693faeeefbfd0339ddda 100644 (file)
@@ -1,15 +1,17 @@
 ! Copyright (c) 2008 Eric Mertens.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: arrays assocs kernel math ranges sequences project-euler.common ;
+USING: arrays assocs kernel math ranges sequences
+project-euler.common ;
 IN: project-euler.164
 
-! https://projecteuler.net/index.php?section=problems&id=164
+! https://projecteuler.net/problem=164
 
 ! DESCRIPTION
 ! -----------
 
-! How many 20 digit numbers n (without any leading zero) exist such
-! that no three consecutive digits of n have a sum greater than 9?
+! How many 20 digit numbers n (without any leading zero) exist
+! such that no three consecutive digits of n have a sum greater
+! than 9?
 
 
 ! SOLUTION
index d80fff5d6989ff8ce0c106475cfeb68a276d726b..e5726c0547153baf9d8fd831411964b97f04e59d 100644 (file)
@@ -1,18 +1,20 @@
 ! Copyright (c) 2007 Samuel Tardieu.
 ! See https://factorcode.org/license.txt for BSD license.
+USING: combinators kernel math math.functions
+project-euler.common ;
 IN: project-euler.169
-USING: combinators kernel math math.functions project-euler.common ;
 
-! https://projecteuler.net/index.php?section=problems&id=169
+! https://projecteuler.net/problem=169
 
 ! DESCRIPTION
 ! -----------
 
-! Define f(0) = 1 and f(n) to be the number of different ways n can be
-! expressed as a sum of integer powers of 2 using each power no more than
-! twice.
+! Define f(0) = 1 and f(n) to be the number of different ways n
+! can be expressed as a sum of integer powers of 2 using each
+! power no more than twice.
 
-! For example, f(10) = 5 since there are five different ways to express 10:
+! For example, f(10) = 5 since there are five different ways to
+! express 10:
 
 ! 1 + 1 + 8
 ! 1 + 1 + 4 + 4
index 397dd40a89b6313b7b140ba3215e8bae080623a4..814e2b035b524d6a63c8bd189e3c92d82ece511e 100644 (file)
@@ -1,22 +1,26 @@
 ! Copyright (c) 2007 Samuel Tardieu.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: kernel math math.functions ranges sequences project-euler.common ;
+USING: kernel math math.functions ranges sequences
+project-euler.common ;
 IN: project-euler.173
 
-! https://projecteuler.net/index.php?section=problems&id=173
+! https://projecteuler.net/problem=173
 
 ! DESCRIPTION
 ! -----------
 
-! We shall define a square lamina to be a square outline with a square "hole"
-! so that the shape possesses vertical and horizontal symmetry. For example,
-! using exactly thirty-two square tiles we can form two different square
-! laminae: [see URL for figure]
+! We shall define a square lamina to be a square outline with a
+! square "hole" so that the shape possesses vertical and
+! horizontal symmetry. For example, using exactly thirty-two
+! square tiles we can form two different square laminae: [see
+! URL for figure]
 
-! With one-hundred tiles, and not necessarily using all of the tiles at one
-! time, it is possible to form forty-one different square laminae.
+! With one-hundred tiles, and not necessarily using all of the
+! tiles at one time, it is possible to form forty-one different
+! square laminae.
 
-! Using up to one million tiles how many different square laminae can be formed?
+! Using up to one million tiles how many different square
+! laminae can be formed?
 
 
 ! SOLUTION
index 2f058c2989e58bb30953d92d3bb607b8028733e0..8e974609d9ee8ade40eaa6a8e9d5bb027be7d057 100644 (file)
@@ -4,29 +4,32 @@ USING: combinators kernel math math.parser project-euler.common
 sequences ;
 IN: project-euler.175
 
-! https://projecteuler.net/index.php?section=problems&id=175
+! https://projecteuler.net/problem=175
 
 ! DESCRIPTION
 ! -----------
 
-! Define f(0) = 1 and f(n) to be the number of ways to write n as a sum of
-! powers of 2 where no power occurs more than twice.
+! Define f(0) = 1 and f(n) to be the number of ways to write n
+! as a sum of powers of 2 where no power occurs more than twice.
 
-! For example, f(10) = 5 since there are five different ways to express
-! 10: 10 = 8+2 = 8+1+1 = 4+4+2 = 4+2+2+1+1 = 4+4+1+1
+! For example, f(10) = 5 since there are five different ways to
+! express 10: 10 = 8+2 = 8+1+1 = 4+4+2 = 4+2+2+1+1 = 4+4+1+1
 
-! It can be shown that for every fraction p/q (p0, q0) there exists at least
-! one integer n such that f(n) / f(n-1) = p/q.
+! It can be shown that for every fraction p/q (p0, q0) there
+! exists at least one integer n such that f(n) / f(n-1) = p/q.
 
-! For instance, the smallest n for which f(n) / f(n-1) = 13/17 is 241. The
-! binary expansion of 241 is 11110001. Reading this binary number from the most
-! significant bit to the least significant bit there are 4 one's, 3 zeroes and
-! 1 one. We shall call the string 4,3,1 the Shortened Binary Expansion of 241.
+! For instance, the smallest n for which f(n) / f(n-1) = 13/17
+! is 241. The binary expansion of 241 is 11110001. Reading this
+! binary number from the most significant bit to the least
+! significant bit there are 4 one's, 3 zeroes and 1 one. We
+! shall call the string 4,3,1 the Shortened Binary Expansion of
+! 241.
 
-! Find the Shortened Binary Expansion of the smallest n for which
-! f(n) / f(n-1) = 123456789/987654321.
+! Find the Shortened Binary Expansion of the smallest n for
+! which f(n) / f(n-1) = 123456789/987654321.
 
-! Give your answer as comma separated integers, without any whitespaces.
+! Give your answer as comma separated integers, without any
+! whitespaces.
 
 
 ! SOLUTION
index 78e6bc50856e2cecddef4d855d2e66afc87db870..b18fedb3615f0ccf594a663d58ca12ab8d48366d 100644 (file)
@@ -1,14 +1,16 @@
 ! Copyright (c) 2008 Eric Mertens.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: circular disjoint-sets kernel math ranges sequences project-euler.common ;
+USING: circular disjoint-sets kernel math ranges sequences
+project-euler.common ;
 IN: project-euler.186
 
-! https://projecteuler.net/index.php?section=problems&id=186
+! https://projecteuler.net/problem=186
 
 ! DESCRIPTION
 ! -----------
 
-! Here are the records from a busy telephone system with one million users:
+! Here are the records from a busy telephone system with one
+! million users:
 
 !     RecNr  Caller  Called
 !     1      200007  100053
@@ -16,23 +18,27 @@ IN: project-euler.186
 !     3      600863  701497
 !     ...    ...     ...
 
-! The telephone number of the caller and the called number in record n are
-! Caller(n) = S2n-1 and Called(n) = S2n where S1,2,3,... come from the "Lagged
-! Fibonacci Generator":
+! The telephone number of the caller and the called number in
+! record n are Caller(n) = S2n-1 and Called(n) = S2n where
+! S1,2,3,... come from the "Lagged Fibonacci Generator":
 
-! For 1 <= k <= 55, Sk = [100003 - 200003k + 300007k^3] (modulo 1000000)
+! For 1 <= k <= 55, Sk = [100003 - 200003k + 300007k^3] (modulo
+! 1000000)
 ! For 56 <= k, Sk = [Sk-24 + Sk-55] (modulo 1000000)
 
-! If Caller(n) = Called(n) then the user is assumed to have misdialled and the
-! call fails; otherwise the call is successful.
+! If Caller(n) = Called(n) then the user is assumed to have
+! misdialled and the call fails; otherwise the call is
+! successful.
 
-! From the start of the records, we say that any pair of users X and Y are
-! friends if X calls Y or vice-versa. Similarly, X is a friend of a friend of Z
-! if X is a friend of Y and Y is a friend of Z; and so on for longer chains.
+! From the start of the records, we say that any pair of users X
+! and Y are friends if X calls Y or vice-versa. Similarly, X is
+! a friend of a friend of Z if X is a friend of Y and Y is a
+! friend of Z; and so on for longer chains.
 
-! The Prime Minister's phone number is 524287. After how many successful calls,
-! not counting misdials, will 99% of the users (including the PM) be a friend,
-! or a friend of a friend etc., of the Prime Minister?
+! The Prime Minister's phone number is 524287. After how many
+! successful calls, not counting misdials, will 99% of the users
+! (including the PM) be a friend, or a friend of a friend etc.,
+! of the Prime Minister?
 
 
 ! SOLUTION
index 98eadeee13e3bbf860c60ede4fab344ed547f7c1..947a0a7249a2a507a7c2273e1dc0e3acce1b1051 100644 (file)
@@ -3,13 +3,14 @@
 USING: kernel math math.functions project-euler.common ;
 IN: project-euler.188
 
-! https://projecteuler.net/index.php?section=problems&id=188
+! https://projecteuler.net/problem=188
 
 ! DESCRIPTION
 ! -----------
 
-! The hyperexponentiation or tetration of a number a by a positive integer b,
-! denoted by a↑↑b or ^(b)a, is recursively defined by:
+! The hyperexponentiation or tetration of a number a by a
+! positive integer b, denoted by a↑↑b or ^(b)a, is recursively
+! defined by:
 
 ! a↑↑1 = a,
 ! a↑↑(k+1) = a^(a↑↑k).
index bf06ce470102d32c15c153d7ba494d7eb51c7a70..d0fc89d1be21892fe527fb9f216619238231476a 100644 (file)
@@ -1,19 +1,20 @@
 ! Copyright (c) 2008 Eric Mertens.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: kernel sequences math math.functions ranges project-euler.common ;
+USING: kernel sequences math math.functions ranges
+project-euler.common ;
 IN: project-euler.190
 
-! https://projecteuler.net/index.php?section=problems&id=190
+! https://projecteuler.net/problem=190
 
 ! DESCRIPTION
 ! -----------
 
-! Let Sm = (x1, x2, ... , xm) be the m-tuple of positive real numbers
-! with x1 + x2 + ... + xm = m for which Pm = x1 * x22 * ... * xmm is
-! maximized.
+! Let Sm = (x1, x2, ... , xm) be the m-tuple of positive real
+! numbers with x1 + x2 + ... + xm = m for which Pm = x1 * x22 *
+! ... * xmm is maximized.
 
-! For example, it can be verified that [P10] = 4112 ([ ] is the integer
-! part function).
+! For example, it can be verified that [P10] = 4112 ([ ] is the
+! integer part function).
 
 ! Find Σ[Pm] for 2 ≤ m ≤ 15.
 
index fde3d959b9b5c3abf485ff844f5ab83f5d9b6c1e..be2796d50b692bee49732b3c91902a5cef89fe48 100644 (file)
@@ -1,16 +1,16 @@
 ! Copyright (c) 2008 Eric Mertens.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: kernel math math.primes.factors math.vectors sequences sets
-project-euler.common ;
+USING: kernel math math.primes.factors math.vectors sequences
+sets project-euler.common ;
 IN: project-euler.203
 
-! https://projecteuler.net/index.php?section=problems&id=203
+! https://projecteuler.net/problem=203
 
 ! DESCRIPTION
 ! -----------
 
-! The binomial coefficients nCk can be arranged in triangular form, Pascal's
-! triangle, like this:
+! The binomial coefficients nCk can be arranged in triangular
+! form, Pascal's triangle, like this:
 
 !                   1
 !                 1   1
@@ -22,16 +22,18 @@ IN: project-euler.203
 !     1   7  21  35  35  21   7   1
 !               .........
 
-! It can be seen that the first eight rows of Pascal's triangle contain twelve
-! distinct numbers: 1, 2, 3, 4, 5, 6, 7, 10, 15, 20, 21 and 35.
+! It can be seen that the first eight rows of Pascal's triangle
+! contain twelve distinct numbers: 1, 2, 3, 4, 5, 6, 7, 10, 15,
+! 20, 21 and 35.
 
-! A positive integer n is called squarefree if no square of a prime divides n.
-! Of the twelve distinct numbers in the first eight rows of Pascal's triangle,
-! all except 4 and 20 are squarefree. The sum of the distinct squarefree numbers
-! in the first eight rows is 105.
+! A positive integer n is called squarefree if no square of a
+! prime divides n. Of the twelve distinct numbers in the first
+! eight rows of Pascal's triangle, all except 4 and 20 are
+! squarefree. The sum of the distinct squarefree numbers in the
+! first eight rows is 105.
 
-! Find the sum of the distinct squarefree numbers in the first 51 rows of
-! Pascal's triangle.
+! Find the sum of the distinct squarefree numbers in the first
+! 51 rows of Pascal's triangle.
 
 
 ! SOLUTION
index eb2cdc40250812359d9e956d100df4e1ee0e5f17..ecad70ac0a718ddc5bde10b1bf3dfb1542cc92cb 100644 (file)
@@ -1,11 +1,10 @@
-! Copyright (c) 2010 Aaron Schaefer. All rights reserved.
-! The contents of this file are licensed under the Simplified BSD License
-! A copy of the license is available at https://factorcode.org/license.txt
+! Copyright (c) 2010 Aaron Schaefer.
+! See https://factorcode.org/license.txt for BSD license.
 USING: grouping kernel math project-euler.common ranges
 sequences sequences.cords ;
 IN: project-euler.206
 
-! https://projecteuler.net/index.php?section=problems&id=206
+! https://projecteuler.net/problem=206
 
 ! DESCRIPTION
 ! -----------
@@ -17,9 +16,9 @@ IN: project-euler.206
 ! SOLUTION
 ! --------
 
-! Through mathematical analysis, we know that the number must end in 00, and
-! the only way to get the last digits to be 900, is for our answer to end in
-! 30 or 70.
+! Through mathematical analysis, we know that the number must
+! end in 00, and the only way to get the last digits to be 900,
+! is for our answer to end in 30 or 70.
 
 <PRIVATE
 
index 098d53ebaee98b9c3bf80816abddd221805def75..e6c21fadb173f3643b233bf0f1addd572965a647 100644 (file)
@@ -3,22 +3,24 @@
 USING: accessors kernel math project-euler.common ;
 IN: project-euler.215
 
-! https://projecteuler.net/index.php?section=problems&id=215
+! https://projecteuler.net/problem=215
 
 ! DESCRIPTION
 ! -----------
 
-! Consider the problem of building a wall out of 2x1 and 3x1 bricks
-! (horizontal x vertical dimensions) such that, for extra strength, the gaps
-! between horizontally-adjacent bricks never line up in consecutive layers,
-! i.e. never form a "running crack".
+! Consider the problem of building a wall out of 2x1 and 3x1
+! bricks (horizontal x vertical dimensions) such that, for extra
+! strength, the gaps between horizontally-adjacent bricks never
+! line up in consecutive layers, i.e. never form a "running
+! crack".
 
-! For example, the following 93 wall is not acceptable due to the running crack
-! shown in red:
+! For example, the following 93 wall is not acceptable due to
+! the running crack shown in red:
 
 !     See problem site for image...
 
-! There are eight ways of forming a crack-free 9x3 wall, written W(9,3) = 8.
+! There are eight ways of forming a crack-free 9x3 wall, written
+! W(9,3) = 8.
 
 ! Calculate W(32,10).
 
index 7d42607771aa1fb729a8ed95a8e745152474f3ae..121dc14cf0b3c15829102c158fe6fed529e9895a 100644 (file)
@@ -3,16 +3,16 @@
 USING: kernel math math.functions project-euler.common ;
 IN: project-euler.255
 
-! https://projecteuler.net/index.php?section=problems&id=255
+! https://projecteuler.net/problem=255
 
 ! DESCRIPTION
 ! -----------
 
-! We define the rounded-square-root of a positive integer n as the square root
-! of n rounded to the nearest integer.
+! We define the rounded-square-root of a positive integer n as
+! the square root of n rounded to the nearest integer.
 
-! The following procedure (essentially Heron's method adapted to integer
-! arithmetic) finds the rounded-square-root of n:
+! The following procedure (essentially Heron's method adapted to
+! integer arithmetic) finds the rounded-square-root of n:
 
 !     Let d be the number of digits of the number n.
 !     If d is odd, set x_(0) = 2×10^((d-1)⁄2).
@@ -22,27 +22,30 @@ IN: project-euler.255
 
 !     until x_(k+1) = x_(k).
 
-! As an example, let us find the rounded-square-root of n = 4321.
-! n has 4 digits, so x_(0) = 7×10^((4-2)⁄2) = 70.
+! As an example, let us find the rounded-square-root of n =
+! 4321. n has 4 digits, so x_(0) = 7×10^((4-2)⁄2) = 70.
 
 !     [ see URL for figure ]
 
 ! Since x_(2) = x_(1), we stop here.
 
-! So, after just two iterations, we have found that the rounded-square-root of
-! 4321 is 66 (the actual square root is 65.7343137…).
+! So, after just two iterations, we have found that the
+! rounded-square-root of 4321 is 66 (the actual square root is
+! 65.7343137…).
 
-! The number of iterations required when using this method is surprisingly low.
-! For example, we can find the rounded-square-root of a 5-digit integer
-! (10,000 ≤ n ≤ 99,999) with an average of 3.2102888889 iterations (the average
-! value was rounded to 10 decimal places).
+! The number of iterations required when using this method is
+! surprisingly low. For example, we can find the
+! rounded-square-root of a 5-digit integer (10,000 ≤ n ≤ 99,999)
+! with an average of 3.2102888889 iterations (the average value
+! was rounded to 10 decimal places).
 
-! Using the procedure described above, what is the average number of iterations
-! required to find the rounded-square-root of a 14-digit number
-! (10^(13) ≤ n < 10^(14))? Give your answer rounded to 10 decimal places.
+! Using the procedure described above, what is the average
+! number of iterations required to find the rounded-square-root
+! of a 14-digit number (10^(13) ≤ n < 10^(14))? Give your answer
+! rounded to 10 decimal places.
 
-! Note: The symbols ⌊x⌋ and ⌈x⌉ represent the floor function and ceiling
-! function respectively.
+! Note: The symbols ⌊x⌋ and ⌈x⌉ represent the floor function and
+! ceiling function respectively.
 
 ! SOLUTION
 ! --------
index 2930a8586ea426b93bca0cb72d57e266c7a05045..1bda3e4e6bd36daefe6265d8bb155403213aad02 100644 (file)
@@ -4,24 +4,28 @@ USING: generalizations kernel math math.functions project-euler.common
 sequences sets ;
 IN: project-euler.265
 
-! https://projecteuler.net/index.php?section=problems&id=265
+! https://projecteuler.net/problem=265
 
-! 2^(N) binary digits can be placed in a circle so that all the N-digit
-! clockwise subsequences are distinct.
+! 2^(N) binary digits can be placed in a circle so that all the
+! N-digit clockwise subsequences are distinct.
 
-! For N=3, two such circular arrangements are possible, ignoring rotations.
+! For N=3, two such circular arrangements are possible, ignoring
+! rotations.
 
-! For the first arrangement, the 3-digit subsequences, in clockwise order, are:
-! 000, 001, 010, 101, 011, 111, 110 and 100.
+! For the first arrangement, the 3-digit subsequences, in
+! clockwise order, are: 000, 001, 010, 101, 011, 111, 110 and
+! 100.
 
-! Each circular arrangement can be encoded as a number by concatenating
-! the binary digits starting with the subsequence of all zeros as the most
-! significant bits and proceeding clockwise. The two arrangements for N=3 are
-! thus represented as 23 and 29:
+! Each circular arrangement can be encoded as a number by
+! concatenating the binary digits starting with the subsequence
+! of all zeros as the most significant bits and proceeding
+! clockwise. The two arrangements for N=3 are thus represented
+! as 23 and 29:
 ! 00010111 _(2) = 23
 ! 00011101 _(2) = 29
 
-! Calling S(N) the sum of the unique numeric representations, we can see that S(3) = 23 + 29 = 52.
+! Calling S(N) the sum of the unique numeric representations, we
+! can see that S(3) = 23 + 29 = 52.
 
 ! Find S(5).
 
index bdd9b240b5e2538f79282491bc6f8a065e08946c..61694055ed93c0fde330ee14a1e9160047c68972 100644 (file)
@@ -1,14 +1,16 @@
 ! Copyright (c) 2023 Cecilia Knaebchen.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: combinators kernel locals math math.functions project-euler.common ;
+USING: combinators kernel locals math math.functions
+project-euler.common ;
 IN: project-euler.463
 
-! https://projecteuler.net/index.php?section=problems&id=463
+! https://projecteuler.net/problem=463
 
 ! DESCRIPTION
 ! -----------
 
-! The function f is defined for all positive integers as follows:
+! The function f is defined for all positive integers as
+! follows:
 
 ! f(1) = 1
 ! f(3) = 3
@@ -27,7 +29,8 @@ IN: project-euler.463
 ! --------
 
 ! Recursion for S(n):
-! S(n) = S([n/2]) + 2S([(n+1)/2]) + 3S([(n-1)/2]) - 2S([(n+1)/4]) - 4S([(n-1)/4]) - 2S([(n-3)/4]) - 1
+! S(n) = S([n/2]) + 2S([(n+1)/2]) + 3S([(n-1)/2]) -
+!        2S([(n+1)/4]) - 4S([(n-1)/4]) - 2S([(n-3)/4]) - 1
 
 MEMO:: S ( n -- Sn )
     n {
index 869650005668e83c587dce012394d9bba48ced7a..ea7e040012f3607c458068765d48ec85874bd091 100644 (file)
@@ -4,16 +4,18 @@ USING: kernel locals math math.functions ranges sequences
 project-euler.common ;
 IN: project-euler.508
 
-! https://projecteuler.net/index.php?section=problems&id=508
+! https://projecteuler.net/problem=508
 
 ! DESCRIPTION
 ! -----------
 
-! Consider the Gaussian integer i-1. A base i-1 representation of a Gaussian integer a+bi is a finite sequence of digits
+! Consider the Gaussian integer i-1. A base i-1 representation
+! of a Gaussian integer a+bi is a finite sequence of digits
 ! d(n-1) d(n-2) ... d(1) d(0) such that:
 ! a+bi = d(n-1) (i-1)^(n-1) + ... + d(1) (i-1) + d(0)
 ! Each d(k) is in {0,1}
-! There are no leading zeros, i.e. d(n-1) != 0, unless a+bi is itself 0
+! There are no leading zeros, i.e. d(n-1) != 0, unless a+bi is
+! itself 0.
 
 ! Here are base i-1 representations of a few Gaussian integers:
 ! 11+24i -> 111010110001101
@@ -22,13 +24,15 @@ IN: project-euler.508
 ! -5+ 0i -> 11001101
 !  0+ 0i -> 0
 
-! Remarkably, every Gaussian integer has a unique base i-1 representation!
+! Remarkably, every Gaussian integer has a unique base i-1
+! representation!
 
-! Define f(a+bi) as the number of 1s in the unique base i-1 representation of a+bi.
-! For example, f(11+24i) = 9 and f(24-11i) = 7.
+! Define f(a+bi) as the number of 1s in the unique base i-1
+! representation of a+bi. For example, f(11+24i) = 9 and
+! f(24-11i) = 7.
 
-! Define B(L) as the sum of f(a+bi) for all integers a, b such that |a| <= L and |b| <= L.
-! For example, B(500) = 10,795,060.
+! Define B(L) as the sum of f(a+bi) for all integers a, b such
+! that |a| <= L and |b| <= L. For example, B(500) = 10,795,060.
 
 ! Find B(10^15) mod 1,000,000,007.
 
@@ -44,8 +48,9 @@ MEMO:: fab ( a b -- n )
     a b [ zero? ] both? [ 0 ] [ a b + 2 rem dup a - dup [ b + 2 / ] [ b - 2 / ] bi* fab + ] if ;
 
 ! B(P,Q,R,S) := Sum(a=P..Q, b=R..S, f(a+bi))
-! Recursion for B(P,Q,R,S) exists, basically four slightly different versions of B(-S/2,-R/2,P/2,Q/2)
-! If summation is over fewer than 5000 terms, we just calculate values of f
+! Recursion for B(P,Q,R,S) exists, basically four slightly
+! different versions of B(-S/2,-R/2,P/2,Q/2). If summation is
+! over fewer than 5000 terms, we just calculate values of f.
 
 MEMO:: B ( P Q R S -- n )
     Q P - S R - * 5000 <