cole-k
https://www.cole-k.com/
Recent content on cole-kHugo -- gohugo.ioen-usCole KurashigeWed, 02 Aug 2017 18:19:34 -0700About
https://www.cole-k.com/project-euler-j/about/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/about/Project Euler Solutions in J Overview My solutions to Project Euler problems in J. These are being done primarily as programming exercises for myself (though I offer them here in the hope that they may serve as a guide to you), so sometimes I will take an indirect route because I think it is more beneficial as a learning experience. Some programs may be golfed (shortened as much as possible).Common J Code
https://www.cole-k.com/project-euler-j/common-j/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/common-j/Things You’ll Often See in J Overview This guide is meant to be a brief tour of what you might expect to see in an answer in J. This is by no means a comprehensive overview of the language, but it’s meant to cover some simple things that I might not explain too in-depth in my comments (mostly because repeating explanations isn’t fun). Important to note is that I will only be covering parts of the language that I commonly use.Eye of the Eye
https://www.cole-k.com/iris-bday/eyeoftheeye/
Wed, 28 Feb 2018 23:24:54 -0800https://www.cole-k.com/iris-bday/eyeoftheeye/Voltaire, Orwell, and Swift are examples of these (9)
Celebs wear baseball caps and sunglasses in order to mitigate these chances (9 5)
Problems faced by an infertile or balding king? (4 6)
Affliction giving an aversion to garlic and stake (9)
How one might greet a skyscraper? (2 5)
A beverage that can give you two kinds of buzzes (5 6)
The location of touristy items in a supermarket archipelago?Sound Bits
https://www.cole-k.com/henry-bday/sound-bits/
Tue, 30 Jan 2018 18:13:33 -0800https://www.cole-k.com/henry-bday/sound-bits/What do the artists spell?Multiples of 3 and 5
https://www.cole-k.com/project-euler-j/problem/1/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/1/Problem Statement 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.
Solution in J +/ I. 0 < (0 = 5 | i. 1000) + (0 = 3 | i. 1000) i. 1000 i. 1000 NB.Got Your [sic] Number
https://www.cole-k.com/iris-bday/gotyournumber/
Wed, 28 Feb 2018 23:21:04 -0800https://www.cole-k.com/iris-bday/gotyournumber/Where can you find the difference between the answerer and the answer?
Property X Property Y 0 F ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ↑↓↑↓↑↓ 🙂🙁🙂🙁🙂🙁
https://www.cole-k.com/henry-bday/updown/
Tue, 30 Jan 2018 18:51:15 -0800https://www.cole-k.com/henry-bday/updown/Once you have left the order, you will know the right letter location.
Even Fibonacci numbers
https://www.cole-k.com/project-euler-j/problem/2/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/2/Problem Statement 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, …
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
Nth Fibonacci Number in J (from the wiki) (-&2 + & $: -&1) ^: (1&<) M.Point of Origin
https://www.cole-k.com/iris-bday/pointoforigin/
Wed, 28 Feb 2018 23:23:26 -0800https://www.cole-k.com/iris-bday/pointoforigin/7 8 3 12 10 5 4 9 A Meatgem
https://www.cole-k.com/henry-bday/a-meatgem/
Tue, 30 Jan 2018 18:57:57 -0800https://www.cole-k.com/henry-bday/a-meatgem/tinyurl.com/mmddyyyyLargest prime factor
https://www.cole-k.com/project-euler-j/problem/3/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/3/Problem Statement What is the largest prime factor of the number 600851475143 ?
Solution in J >./q:600851475143 q: NB. Prime factors >./ NB. Insert max (max of array) I ought to do this without builtins one day.A Word, Please
https://www.cole-k.com/iris-bday/awordplease/
Wed, 28 Feb 2018 23:29:44 -0800https://www.cole-k.com/iris-bday/awordplease/Submit your answer to the creator of the puzzle.
Words with fewer letters than 4 don’t matter.Largest palindrome product
https://www.cole-k.com/project-euler-j/problem/4/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/4/Problem Statement 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.
Solution in J >./ (#~ (*/@(=|.)@":)"0) ~. ; */~ 100+i.900 100+i.900 NB. [100,999] */~ NB. Cartesian product of range with itself and * applied ~. ; NB. Flatten and remove duplicates "0 NB.Etc
https://www.cole-k.com/iris-bday/etc/
Fri, 02 Mar 2018 10:57:34 -0800https://www.cole-k.com/iris-bday/etc/Hints Read the general hints before reading specific hints.
Read each puzzle’s hints in the order they are given to prevent the most spoilers.
General Hints Get as much information about a puzzle as possible.
Once you think you have enough information, make some assumptions about how it can be used and then follow these assumptions. Did you get what seemed to be a wrong answer? Evaluate whether it was your assumption or execution that was wrong, and try again!Smallest multiple
https://www.cole-k.com/project-euler-j/problem/5/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/5/ Problem Statement What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
Solution in J *./1+i.20 1+i.20 NB. Range [1,20] *./ NB. LCM Sum square difference
https://www.cole-k.com/project-euler-j/problem/6/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/6/Problem Statement Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
Solution in J (*:@:(+/) - +/@:*:) i.101 i.101 NB. [0,101) +/@:*: NB. Sum composed with square *:@:(+/) NB. Square composed with sum ( - ) NB. Fork: apply left and right functions to argument and NB. use the result as the argument for the middle function Solution in J by jdrandall123 (([: *: +/)-([: +/ *:)) i.Largest product in a series
https://www.cole-k.com/project-euler-j/problem/8/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/8/Problem Statement 73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 85861560789112949495459501737958331952853208805511 12540698747158523863050715693290963295227443043557 66896648950445244523161731856403098711121722383113 62229893423380308135336276614282806444486645238749 30358907296290491560440772390713810515859307960866 70172427121883998797908792274921901699720888093776 65727333001053367881220235421809751254540594752243 52584907711670556013604839586446706324415722155397 53697817977846174064955149290862569321978468622482 83972241375657056057490261407972968652414535100474 82166370484403199890008895243450658541227588666881 16427171479924442928230863465674813919123162824586 17866458359124566529476545682848912883142607690042 24219022671055626321111109370544217506941658960408 07198403850962455444362981230987879927244284909188 84580156166097919133875499200524063689912560717606 05886116467109405077541002256983155200055935729725 71636269561882670428252483600823257530420752963450 Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?
Solution in J Converting the string (assuming that all newlines, including the trailing one, are removed). Assume the filename for the number is stored in F.Special Pythagorean triplet
https://www.cole-k.com/project-euler-j/problem/9/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/9/Problem Statement A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a^2 + b^2 = c^2 For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.
Solution in J ~. */"1 (#~"2(1e3= [: +/ ])"1) (#~"2 ([: (=<.) [: {: ])"1) %: ([,],+)"0 /~ *: i.Summation of Primes
https://www.cole-k.com/project-euler-j/problem/10/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/10/ Problem Statement Find the sum of all the primes below two million.
Solution in J +/ p: i. _1 p: 2e6 _1 p: 2e6 NB. Built-in: value of greatest prime less than 2 mil i. NB. Range from 0 to value - 1 p: NB. Primes at these indeces +/ NB. Sum Largest product in a grid
https://www.cole-k.com/project-euler-j/problem/11/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/11/Problem Statement What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the (provided) 20×20 grid?
Solution in J Expects filename in the variable F. I’ve chosen to modularize each way of checking to avoid a really long line and parenthetical mess. There likely is a better way, though.
diag_prod =. [: , 4 */\"1 [: ]/. ] ]/. NB.Highly divisible triangle number
https://www.cole-k.com/project-euler-j/problem/12/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/12/Problem Statement What is the value of the first triangle number to have over five hundred divisors?
Solution in J nth triangle number calculated using the binomial coefficient (n choose 2).
2! >: ^: (500 > [: */@: >: @ {: __ q: 2!]) ^:_ (2x) 2x NB. 2 with extended precision ((1 choose 2) = 0) ^: ^:_ NB. Do while 2!] NB. nth triangle number [: */@: >: @ {: __ q: NB.Large sum
https://www.cole-k.com/project-euler-j/problem/13/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/13/Problem Statement Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.
37107287533902102798797998220837590246510135740250 . . . 53503534226472524250874054075591789781264330331690 Solution in J First load the numbers, saved to a file, to a variable named lines.
10 {. ": +/ x: ". > (10 { a.) cut lines (10 { a.) cut lines NB. Split on newlines ". > NB. Unbox and evaluate as number (precision is lost here, but NB.Longest Collatz sequence
https://www.cole-k.com/project-euler-j/problem/14/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/14/Problem Statement 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:
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.Power digit sum
https://www.cole-k.com/project-euler-j/problem/16/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/16/ Problem Statement What is the sum of the digits of the number 2^1000?
Solution in J +/ "."0 ": 2^1000x 2^1000x NB. 2^1000 (arbitrary precision) ": NB. Format to string "."0 NB. Convert to list of digits +/ NB. Sum Factorial digit sum
https://www.cole-k.com/project-euler-j/problem/20/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/20/ Problem 20 Find the sum of the digits in the number 100!
Solution in J +/ ". ;"0 ": ! 100x ! 100x NB. Calculate 100! exactly (yield all its digits) ": NB. Format to string ;"0 NB. Raze each digit ". NB. Convert to number from string +/ NB. Sum Amicable numbers
https://www.cole-k.com/project-euler-j/problem/21/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/21/Problem Statement 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.
For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284.Name scores
https://www.cole-k.com/project-euler-j/problem/22/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/22/Problem Statement 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.Non-abundant sums
https://www.cole-k.com/project-euler-j/problem/23/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/23/Problem Statement 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 n is called deficient if the sum of its proper divisors is less than n and it is called abundant if this sum exceeds n.Lexicographic permutations
https://www.cole-k.com/project-euler-j/problem/24/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/24/Problem Statement 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?Quadratic Primes
https://www.cole-k.com/project-euler-j/problem/27/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/27/Problem Statement 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 in J num_cons_primes =. [: {: [: (>:@{. , }.) ^: (1&p: @ (}. p. {.)) ^: a: 0,1,~, */ }. ({~ [: (i. >./) {."1) ,/ (i:1001) num_cons_primes"0/ i:1e3 I’m shortening the name of the helper function to np for more commenting space.Number spiral diagonals
https://www.cole-k.com/project-euler-j/problem/28/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/28/Problem Statement 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 6 1 2 11 18 5 4 3 12 17 16 15 14 13 It can be verified that the sum of the numbers on the diagonals is 101.
What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed in the same way?Distinct powers
https://www.cole-k.com/project-euler-j/problem/29/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/29/Problem Statement How many distinct terms are in the sequence generated by a^b for 2 ≤ a ≤ 100 and 2 ≤ b ≤ 100?
Solution in J # ~. ; ^/~ 2+i.99 2+i.99 NB. Range [2,100] ^/~ NB. Cartesian product of the range and itself ; NB. Raze (flatten to an array) ~. NB. Remove duplicates # NB. Tally (return length of array) Timed result: ~0.5 msDigit fifth powers
https://www.cole-k.com/project-euler-j/problem/30/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/30/Problem Statement Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.
Solution in J +/ (#~(= ([: +/ [: (5 ^~ ]) [: "."0 ":)"0)) 2+i.1e6 2+i.1e6 NB. Arbitrary upper limit excluding 1 ([: +/ [: (5 ^~ ]) [: "."0 ":)"0) NB. Hook: Sum of digits raised to the fifth equal to itself "."0 ": NB. Convert to digits 5 ^~ ] NB.Digit cancelling fractions
https://www.cole-k.com/project-euler-j/problem/33/
Tue, 08 Aug 2017 12:56:56 -0700https://www.cole-k.com/project-euler-j/problem/33/Problem Statement 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.
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.Digit factorials
https://www.cole-k.com/project-euler-j/problem/34/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/34/Problem Statement 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.
Note: as 1! = 1 and 2! = 2 are not sums they are not included.
Solution in J The upper limit I established was 10^7, but that took an incredibly long time to run so I dropped the exponent down and increased it by one until it stopped changing (although I did end up verifiying with my upper limit).Circular primes
https://www.cole-k.com/project-euler-j/problem/35/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/35/Problem Statement 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.
How many circular primes are there below one million?
Solution in J circular =. [: */ 1 p: [: ". [: 1&|. ^: (<@#) ": +/ circular"0 i.Double-base palindromes
https://www.cole-k.com/project-euler-j/problem/36/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/36/Problem Statement The decimal number, 585 = 10010010012 (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.
(Please note that the palindromic number, in either base, may not include leading zeros.)
Solution pal_10 =. (= |.) @ ": pal_2 =. (= |.) @ #: +/ (#~ ([: *./ pal_10 , pal_2)"0 ) i.1e6 Explanation pal_10 =.Truncatable primes
https://www.cole-k.com/project-euler-j/problem/37/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/37/Problem Statement 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.
NOTE: 2, 3, 5, and 7 are not considered to be truncatable primes.Integer right triangles
https://www.cole-k.com/project-euler-j/problem/39/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/39/Problem Statement 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 maximised?
Solution in J (([: (i. >./) #/.~) { ~.) (#~ (=<.) *. 1e3&>:) +/"1 %: ,/ (,,+)"0/~ *: >:i.1e3 TBD: Provide explanation
perimeters =. +/"1 %: ,/ (,,+)"0/~ *: >:i.Pandigital prime
https://www.cole-k.com/project-euler-j/problem/41/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/41/Problem Statement 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?
Solution in J This is somewhat of a naive solution which takes a while to run too. Perhaps I’ll address that in the future or add a better solution from someone else.Coded triangle numbers
https://www.cole-k.com/project-euler-j/problem/42/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/42/Problem Statement The nth term of the sequence of triangle numbers is given by, tn= ½ n (n+1); so the first ten triangle numbers are:
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.Sub-string divisibility
https://www.cole-k.com/project-euler-j/problem/43/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/43/Problem Statement 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:
d2d3d4 = 406 is divisible by 2 d3d4d5 = 063 is divisible by 3 d4d5d6 = 635 is divisible by 5 d5d6d7 = 357 is divisible by 7 d6d7d8 = 572 is divisible by 11 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.Triangular, pentagonal, and hexagonal
https://www.cole-k.com/project-euler-j/problem/45/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/45/Problem Statement Triangle, pentagonal, and hexagonal numbers are generated by the following formulae:
Triangle T_n=n(n+1)/2 1, 3, 6, 10, 15, ... Pentagonal P_n=n(3n−1)/2 1, 5, 12, 22, 35, ... Hexagonal H_n=n(2n−1) 1, 6, 15, 28, 45, ... It can be verified that T_285 = P)165 = H_143 = 40755.
Find the next triangle number that is also pentagonal and hexagonal.
Work The runtime for this is too long – it’s too naive to work.Goldbach's other conjecture
https://www.cole-k.com/project-euler-j/problem/46/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/46/Problem Statement 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^2×12 15 = 7 + 2^2×22 21 = 3 + 2^2×32 25 = 7 + 2^2×32 27 = 19 + 2^2×22 33 = 31 + 2^2×12 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?Distinct prime factors
https://www.cole-k.com/project-euler-j/problem/47/
Fri, 04 Aug 2017 20:32:28 -0700https://www.cole-k.com/project-euler-j/problem/47/Problem Statement 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:
644 = 2² × 7 × 23 645 = 3 × 5 × 43 646 = 2 × 17 × 19. Find the first four consecutive integers to have four distinct prime factors each.Self Powers
https://www.cole-k.com/project-euler-j/problem/48/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/48/Problem Statement 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.
Solution nums =. (#~ [: * 10&|) >: i. x: 1e3 _10 {. ": +/ ^~ nums Explanation Extended precision is quite nice. This is pretty brute force, though it does filter out guaranteed zeroes (any multiple of 10 will zero out).Prime permutations
https://www.cole-k.com/project-euler-j/problem/49/
Sat, 05 Aug 2017 11:57:51 -0700https://www.cole-k.com/project-euler-j/problem/49/Problem Statement 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.
What 12-digit number do you form by concatenating the three terms in this sequence?Consecutive prime sum
https://www.cole-k.com/project-euler-j/problem/50/
Fri, 04 Aug 2017 19:15:48 -0700https://www.cole-k.com/project-euler-j/problem/50/Problem Statement 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.
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?Permuted multiples
https://www.cole-k.com/project-euler-j/problem/52/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/52/Problem Statement 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.
Solution in J f =. 1 < [: # [: ~. [: /:~"2 [: ,"0 [: ":"0 (2+i.5) * ] NB. Helper function to test if multiples are permutations (2+i.Powerful digit sum
https://www.cole-k.com/project-euler-j/problem/56/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/56/Problem Statement Considering natural numbers of the form, a^b, where a, b < 100, what is the maximum digital sum?
Solution in J >. / +/ "2 ". ;"0 ": "0 ~. ; ^/~ 2+i.99x 2+i.99x NB. Exact range [2,99] ^/~ NB. Cartesian product with exponent ; NB. Raze ~. NB. Remove duplicates ": "0 NB. Convert each number to a string ;"0 NB. Raze each string (yielding digits) ".Square root convergents
https://www.cole-k.com/project-euler-j/problem/57/
Sun, 06 Aug 2017 16:27:45 -0700https://www.cole-k.com/project-euler-j/problem/57/Problem Statement 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…
By expanding this for the first four iterations, we get:
1 + 1⁄2 = 3⁄2 = 1.5
1 + 1/(2 + 1⁄2) = 7⁄5 = 1.4
1 + 1/(2 + 1/(2 + 1⁄2)) = 17⁄12 = 1.Convergents of e
https://www.cole-k.com/project-euler-j/problem/65/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/65/Problem Statement Find the sum of digits in the numerator of the 100th convergent of the continued fraction for e.
Solution in J It’s so lovely that you can turn the continued fraction into (+%)/ applied to an array.
+/ "."0 ": {. 2 x: >: (+%) / 1,~ ; 1(1,1,])\ 2*>:i.33x 2*>:i.33x NB. Generate the range (extended precision), yields NB. 2, 4, ... , 34 1(1,1,])\ NB. Infix insertion of (1,1,]) at every digit, yields NB.Totient maximum
https://www.cole-k.com/project-euler-j/problem/69/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/69/ Problem statement 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.
Solution in J >: (i. >./) (%5&p:) >:i.1e6 >:i.1e6 NB. [1,1e6] %5&p: NB. Hook: n/φ(n) 5&p: NB. φ(n) % NB. n / right argument i. >./ NB. Hook: index of maximum >./ NB. Maximum i. NB. Index of >: NB. Add 1 (range is 1-indexed) Totient permutation
https://www.cole-k.com/project-euler-j/problem/70/
Sun, 06 Aug 2017 14:26:50 -0700https://www.cole-k.com/project-euler-j/problem/70/Problem Statement 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.Counting fractions
https://www.cole-k.com/project-euler-j/problem/72/
Sat, 05 Aug 2017 22:55:44 -0700https://www.cole-k.com/project-euler-j/problem/72/Problem Statement 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:
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.Square digit chains
https://www.cole-k.com/project-euler-j/problem/92/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project-euler-j/problem/92/Problem Statement 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.A Birthday Puzzle for Reid
https://www.cole-k.com/puzzles/reid-bday-puzzle/
Wed, 20 Dec 2017 01:46:14 -0800https://www.cole-k.com/puzzles/reid-bday-puzzle/Affine Ciphers with a Twist A prize awaits you, intrepid programmer, if you are able to crack the cipher given to you. Your pirze has been encoded as an Affine cipher with a twist.
Affine Ciphers, by example To encode a piece of text using an Affine cipher, you first need to pick a multiplier m and an adder a. Note that for this application of the cipher, m must be relatively prime to 255 (i.Cross Words
https://www.cole-k.com/puzzles/crosswords/
Sat, 16 Dec 2017 18:25:45 -0800https://www.cole-k.com/puzzles/crosswords/Cross Words Mind the gap This line spoken by actor Gable is what is most remembered from a 1939 movie.
Owen replies to a silly suggestion with,
A soldier might respond to provocation with (the beginning of) this tirade.
Text lingo “ftw” in some contexts.
Fresh salmon, after salting and curing.
Find cool people drinking and serving at this bar, which is the second oldest in South.
Little red dot first telephone digit.HackMIT 2017
https://www.cole-k.com/2017/09/17/hackmit2017/
Sun, 17 Sep 2017 15:48:36 -0400https://www.cole-k.com/2017/09/17/hackmit2017/HackMIT Hackathons are always a blast, and HackMIT was no exception, but it was a different experience than most. All of the other hackathon projects I’ve worked on have been about taking a few things that our team is somewhat familiar with and combining them, but with HackMIT we were learning new technologies from scratch. That was still fun, don’t get me wrong, but it was a different kind of challenge than we were used to.Kura-shagi?
https://www.cole-k.com/2017/08/06/kurashige/
Sun, 06 Aug 2017 11:09:03 -0700https://www.cole-k.com/2017/08/06/kurashige/How do you say that? I’m used to hearing my last name mispronounced. One of my earliest memories from first grade is on the first week of school when the principal announced me as Student of the Week.[1] After she said my last name, I requested the microphone from her and pronounced it correctly for the assembled student body.
I get a lot of “Could you say your last name for me?Pro(j)ect Euler
https://www.cole-k.com/2017/08/03/project-euler/
Thu, 03 Aug 2017 22:05:21 -0700https://www.cole-k.com/2017/08/03/project-euler/Project Euler solutions in J I’d known of the existence of both Project Euler and J for a long while now, but for various reasons I never got around to investigating either until recently. I decided it was time to stop indefinitely delaying learning J, and delved right into the various guides and materials on its website and wiki. Once I had had enough of reading about J’s very-difficult-to-learn syntax, I decided it was time to just try programming in J.><> (Fish)
https://www.cole-k.com/2017/08/03/fish/
Thu, 03 Aug 2017 12:45:25 -0700https://www.cole-k.com/2017/08/03/fish/Fish? This essay serves as an explanation to what the language ><> is and what makes it so cool. I give an overview of in what ways it is esoteric and then walk through a sample program just to cement how interesting it is. I hope you like it as much as I do.
An esoteric language The programming language ><>[1] (spoken as “fish”) is what is known as an esoteric language.ProJect Euler
https://www.cole-k.com/project/project-euler-j/
Wed, 02 Aug 2017 18:19:34 -0700https://www.cole-k.com/project/project-euler-j/First Post
https://www.cole-k.com/2017/08/01/first-post/
Tue, 01 Aug 2017 16:59:58 -0700https://www.cole-k.com/2017/08/01/first-post/It was about time for a new website My old website[1] had long been broken (albeit only in a minor way) by some sort of update to HTML. In its defense, it wasn’t a particularly bad website, especially for one that I hastily threw together for a hackathon application. But I had quite a few qualms with it, the biggest being that it was completely hand-written HTML and CSS: no frameworks, nothing.About
https://www.cole-k.com/page/about/
Mon, 31 Jul 2017 22:12:50 -0700https://www.cole-k.com/page/about/I’m Cole Kurashige. kəʊl kuːraˈːʃiːgɛ[1] Short Bio I’m a sophomore planning on majoring in Computer Science at Harvey Mudd College. When I’m not busy with schoolwork, you can likely find me working on a side project of some sort, freelining, or playing a video game.
Education Harvey Mudd College Class of 2020, Intended B.S. in Computer Science Résumé If you’re a personal acquaintance of mine, I ask that you refrain from looking at my résumé unless you’re looking to hire me, as it has my GPA on it.