Archive for arithmetics

Carmichael number, more or less

Posted in Books, Kids, Statistics with tags , , , , , , , on May 6, 2022 by xi'an

A quick-and-dirty R resolution of a riddle from The Riddler, namely to find a Carmichael number of the form abcabc:

library(numbers)
for(i in 1:9)
  for(j in 0:9)
    for(k in 0:9){
      x=i*100100+j*1010+k*101
      if(!isPrime(x)){
        p=primeFactors(x)
        if((prod(apply(outer(p,p,F="=="),1,sum)%%2))&
          (!max((x-1)%%(p-1))))break()}}

resulting into the number 101 101, since its prime factors are

> primeFactors(101101)
[1]   7  11  13 101

and 6, 10, 12, and 100 are divisors of 101100:

> primeFactors(101100) 
[1] 2 2 3 5 5 337

Le Monde puzzle [#1139]

Posted in Books, Kids, R, Statistics with tags , , , , , on April 24, 2020 by xi'an

A weekly Monde current mathematical puzzle that reminded me of an earlier one (but was too lazy to check):

The integer n=36 enjoys the property that all the differences between its ordered divisors are also divisors of 36. Find the only 18≤m≤100 that enjoys this property such that all its prime dividers areof multiplicity one. Are there other such m’s?

The run of a brute force R search return 42 as the solution (codegolf welcomed!)

y=z=1:1e5
for(x in y)z[y==x]=!sum(x%%diff((1:x)[!x%%(1:x)]))
y=y[z==1]
for(k in generate_primes(2,max(y)))y=y[!!y%%k^2]

where generate_primes is a primes R function. Increasing the range of y’s to 10⁵ exhibits one further solution, 1806.

Le Monde puzzle [#1133]

Posted in Books, Kids, R with tags , , , , , , on March 28, 2020 by xi'an

A weekly Monde current mathematical puzzle that reminded me of an earlier one (but was too lazy to check):

If ADULE-ELUDA=POINT, was is the largest possible value of POINT? With the convention that all letters correspond to different digits and no digit can start with 0. Same question when ADULE+ELUDA=POINT.

The run of a brute force R search return 65934 as the solution (codegolf welcomed!)

dify<-function(adule) 
  (sum(adule*10^(4:0))-sum(rev(adule)*10^(4:0)))
num2dig<-function(dif) (dif%/%10^(0:4))%%10
sl=NULL
for (t in 1:1e6){
  adule=sample(0:9,5)
  while((dify(adule)<=0)||(!prod(adule[c(1,5)])))
     adule=sample(0:9,5)
point=rev(num2dig(dify(adule)))
if ((!sum(duplicated(point)))&(prod(point%in%(0:9)[-adule-1])))
  sl=rbind(sl,c(adule,point))}
sl=as.matrix(distinct(as.data.frame(sl),.keep_all = TRUE))

where distinct is a dplyr R function.

> 94581-18549
[1] 76032

The code can be easily turned into solving the second question

> 31782+28713
[1] 60495

Le Monde puzzle [#1134]

Posted in Books, R with tags , , , , , , on March 24, 2020 by xi'an

A Monde mathematical puzzle on gcd’s and scm’s:

If one replaces a pair (a,b) of integers with the pair (g,s) of their greatest common denominator and smallest common multiple, how long at most before the sequence ends. Same question when considering a collection of five integers where two are selected by the pair (g,s) of their greatest common denominator and smallest common multiple.

The first question is straightforward as s is a multiple of s. So the sequence ends at most after one run. For five, run of a brute force R search return 9 as “the” solution (even though the true maximum is 10, as illustrated by the quintuplet (16,24,36,54,81):

ogcd <- function(x,y){r<-x%%y
  return(ifelse(r,ogcd(y,r),y))}

oscm<-function(x,y) x*y/ogcd(x,y)

divemul<-function(a,b) return(c(oscm(a,b),ogcd(a,b)))

for (t in 1:1e5){
ini=sample(1:1e2,5)
i=0;per=ker=sample(ini,2)
nez=divemul(per[1],per[2])
while(!max(nez%in%per)){
 ini=c(ini[!ini%in%per],nez)
 per=sample(ini,2)
 ker=rbind(ker,per)
 nez=divemul(per[1],per[2])
 i=i+1}
 sol=max(sol,i)}

Le Monde puzzle [#1132]

Posted in Kids, R, Statistics with tags , , , , , on February 24, 2020 by xi'an

A vaguely arithmetic challenge as Le weekly Monde current mathematical puzzle:

Given two boxes containing x and 2N+1-x balls respectively. If one proceeds by repeatedly transferring half the balls from the even box to the odd box, what is the largest value of N for which the resulting sequence in one of the boxes covers all integers from 1 to 2N?

The run of a brute force R search return 2 as the solution

lm<-function(N)
fils=rep(0,2*N)
bol=c(1,2*N)
while(max(fils)<2){
    fils[bol[1]]=fils[bol[1]]+1
    bol=bol+ifelse(rep(!bol[1]%%2,2),-bol[1],bol[2])*c(1,-1)/2}
return(min(fils))}

with obvious arguments that once the sequence starts cycling all possible numbers have been visited:

> lm(2)
[1] 1
> lm(3)
[1] 0

While I cannot guess the pattern, there seems to be much larger cases when lm(N) is equal to one, as for instance 173, 174, 173, 473, 774 (and plenty in-between).

%d bloggers like this: