Skip to content

Commit

Permalink
Create xenotation.dyalog
Browse files Browse the repository at this point in the history
  • Loading branch information
davis68 authored Jan 21, 2019
1 parent d44e0f9 commit 2299d06
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions xenotation.dyalog
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
∇/∆ APL XENOTATION ∇/∆\∇/∆\∇/∆\∇/∆\∇/∆\∇/∆\∇/∆\∇/∆\∇/∆\∇/∆\∇/∆\∇/∆\∇/∆\∇/∆\∇/∆

Generate a list of prime factors. ⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝
Prime{1(~v1 1v.×v)/v(+1)}

We need the full decomposition, not just the prime factors. (Rosetta Code) ⍝
PrimeFactorDecomposition←{⎕ML ⎕IO←1 ⍝ Prime factors of ⍵.
⍵{ note: ⎕wa>(⍵*÷2)×2*4.
,(÷×/)~1 append factor > sqrt(⍵).
}⍵{ concatenated,
(0=(*)|)/ powers of each prime factor.
}¨{ remove multiples:
nxt next prime, and
msk0nxt| ... mask of non-multiples.
/1msk:, all non multiples - finished.
(,nxt) msk/ sieve remainder.
}⍵{ from,
(0=|)/ divisors of ⍵ in:
}2,(1+2×0.5×*÷2), 2,3 5 .. sqrt(⍵),⍵
}

Find the xenotative form of a number. ⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝
XenoXenotate n
Find prime factors of an Arabic-style number.
Factors PrimeFactorDecomposition n
Use the prime indices in the generation of the xenotative number.
Primes Prime 1000

Construct xenotative form of each prime factor.
This can probably be made more APL-like.
Xeno ''
:For Factor :In Factors
:If Factor = 2 Add ':'
XenoXeno,':'
:Else Implex
PrimeIndex (Factor Primes) / Primes
InnerValue Xenotate( PrimeIndex )
XenoXeno,'(',InnerValue,')'
:EndIf
:EndFor

0 comments on commit 2299d06

Please sign in to comment.