3 Rollback to Revision 1
source | link

VDM-SL, 315161 bytes

modulef(i)==(lambda CG
importsp:set fromof IOnat1&let all
exportsz all
definitions
functionsin f:seq1set ofp char->seq1be ofst char
fforall m in set p&abs(m-i)==let>=abs(z-i)in m=z)({2|->"ABC",3|->"DEF",4|->"GHI",5|->"JKL",6|->"MNO",7|->"PQRS",8|->"TUV",9|->"WXYZ"},q=[z|zx|x in seqset{1,...,9**7}&forall i&zy in set{2,...,1003}&y<>x=>x dommod m],a=IO`freadvaly<>0})

A full program to run might look like this - it's worth noting that the bounds of the set of primes used should probably be changed if you actually want to run this, since it will take a long time to run for 1 million:

functions
f:nat1+>nat1
f("f"i)in==(lambda letp:set rof nat1&let z in set ap be st forall xm in set inds q&rp&abs(x)in set m(-i)>=abs(xz-i)in z)({x|x in r
endset{1,...,9**7}&forall CGy in set{2,...,1003}&y<>x=>x mod y<>0})

IO hurts in VDM, since it's intended for modelling first and foremost. For comparison (but not as a submission since IO must be performed not receiving dictionary as input). A 198 byte function could be:

Explanation:

f(a,i)==let== m={2|->"ABC",3|->"DEF",4|->"GHI",5|->"JKL",6|->"MNO",7|->"PQRS",8|->"TUV",9|->"WXYZ"},q=[z|z in seq i&z in                                   /* f is a function which takes a nat1 (natural number not including 0)*/
(lambda p:set domof m]innat1 let r                       /* define a lambda which takes a set of nat1*/
&let z in set ap be st                         /* which has an element z in the set such that */
forall xm in set indsp q&r                            /* for every element in the set*/
&abs(xm-i)in set                                    /* the difference between the element m and the input*/
>=abs(z-i(x)                                    /* is greater than or equal to the difference between the element z and the input */
in z)                                         /* and return z from the lambda */
(                                             /* apply this lambda to... */
{                                             /* a set defined by comprehension as.. */
x|                                            /* all elements x such that.. */ 
x in rset{1,...,9**7}                          /* x is between 1 and 9^7 */
&forall y in set{2,...,1003}                  /* and for all values between 2 and 1003*/
&y<>x=>x mod y<>0                             /* y is not x implies x is not divisible by y*/
} 
)

Still expensive because of building the map (I'm sure there'll be a good map comprehension for it I've just not thought of it yet) and could save further bytes if the string was guaranteed to only contain values in the domain of the map

VDM-SL, 315 bytes

module CG
imports from IO all
exports all
definitions
functions f:seq1 of char->seq1 of char
f(i)==let m={2|->"ABC",3|->"DEF",4|->"GHI",5|->"JKL",6|->"MNO",7|->"PQRS",8|->"TUV",9|->"WXYZ"},q=[z|z in seq i&z in set dom m],a=IO`freadval("f")in let r in set a be st forall x in set inds q&r(x)in set m(i(x))in r
end CG

IO hurts in VDM, since it's intended for modelling first and foremost. For comparison (but not as a submission since IO must be performed not receiving dictionary as input). A 198 byte function could be:

f(a,i)==let m={2|->"ABC",3|->"DEF",4|->"GHI",5|->"JKL",6|->"MNO",7|->"PQRS",8|->"TUV",9|->"WXYZ"},q=[z|z in seq i&z in set dom m]in let r in set a be st forall x in set inds q&r(x)in set m(i(x))in r

Still expensive because of building the map (I'm sure there'll be a good map comprehension for it I've just not thought of it yet) and could save further bytes if the string was guaranteed to only contain values in the domain of the map

VDM-SL, 161 bytes

f(i)==(lambda p:set of nat1&let z in set p be st forall m in set p&abs(m-i)>=abs(z-i)in z)({x|x in set{1,...,9**7}&forall y in set{2,...,1003}&y<>x=>x mod y<>0})

A full program to run might look like this - it's worth noting that the bounds of the set of primes used should probably be changed if you actually want to run this, since it will take a long time to run for 1 million:

functions
f:nat1+>nat1
f(i)==(lambda p:set of nat1&let z in set p be st forall m in set p&abs(m-i)>=abs(z-i)in z)({x|x in set{1,...,9**7}&forall y in set{2,...,1003}&y<>x=>x mod y<>0})

Explanation:

f(i)==                                        /* f is a function which takes a nat1 (natural number not including 0)*/
(lambda p:set of nat1                         /* define a lambda which takes a set of nat1*/
&let z in set p be st                         /* which has an element z in the set such that */
forall m in set p                             /* for every element in the set*/
&abs(m-i)                                     /* the difference between the element m and the input*/
>=abs(z-i)                                    /* is greater than or equal to the difference between the element z and the input */
in z)                                         /* and return z from the lambda */
(                                             /* apply this lambda to... */
{                                             /* a set defined by comprehension as.. */
x|                                            /* all elements x such that.. */ 
x in set{1,...,9**7}                          /* x is between 1 and 9^7 */
&forall y in set{2,...,1003}                  /* and for all values between 2 and 1003*/
&y<>x=>x mod y<>0                             /* y is not x implies x is not divisible by y*/
} 
)
2 deleted 891 characters in body
source | link

VDM-SL, 161315 bytes

f(i)==(lambda p:set of nat1&let zmodule inCG
imports setfrom pIO beall
exports stall
definitions
functions forallf:seq1 mof inchar->seq1 setof p&abs(m-i)>=abschar
f(z-i)in z)({x|x in==let setm={12|->"ABC",...3|->"DEF",9**74|->"GHI",5|->"JKL",6|->"MNO",7|->"PQRS",8|->"TUV",9|->"WXYZ"}&forall,q=[z|z yin seq i&z in set{2,...,1003}&y<>x=>x moddom y<>0})

A full program to run might look like this - it's worth noting that the bounds of the set of primes used should probably be changed if you actually want to run this, since it will take a long time to run for 1 million:

functions
f:nat1+>nat1
fm],a=IO`freadval(i"f")==(lambda p:set ofin nat1&letlet zr in set pa be st forall mx in set p&abs(m-i)>=abs(z-i)ininds z)q&r({x|x x)in set{1,...,9**7}&forall y m(i(x))in set{2,...,1003}&y<>x=>x modr
end y<>0})CG

Explanation:

IO hurts in VDM, since it's intended for modelling first and foremost. For comparison (but not as a submission since IO must be performed not receiving dictionary as input). A 198 byte function could be:

f(a,i)==                                        /* f is a function which takes a nat1==let (naturalm={2|->"ABC",3|->"DEF",4|->"GHI",5|->"JKL",6|->"MNO",7|->"PQRS",8|->"TUV",9|->"WXYZ"},q=[z|z numberin notseq includingi&z 0)*/
(lambdain p:set of nat1                         /* define a lambda which takes a setdom ofm]in nat1*/
&letlet zr in set pa be st                         /* which has an element z in the set such that */
forall mx in set p                             /* for every element in theinds set*/
&absq&r(m-ix)                                     /* the difference between thein elementset m and the input*/
>=abs(z-i)                                    /* is greater than or equal to the difference between the element z and the input */
in z)                                         /* and return z from the lambda */
(                                             /* apply this lambda to... */
{                                             /* a set defined by comprehension as.. */
x|                                            /* all elements x such that.. */ 
x in set{1,...,9**7}                          /* x is between 1 and 9^7 */
&forall y ))in set{2,...,1003}                  /* and for all values between 2 and 1003*/
&y<>x=>x mod y<>0                             /* y is not x implies x is not divisible by y*/
} 
)r

Still expensive because of building the map (I'm sure there'll be a good map comprehension for it I've just not thought of it yet) and could save further bytes if the string was guaranteed to only contain values in the domain of the map

VDM-SL, 161 bytes

f(i)==(lambda p:set of nat1&let z in set p be st forall m in set p&abs(m-i)>=abs(z-i)in z)({x|x in set{1,...,9**7}&forall y in set{2,...,1003}&y<>x=>x mod y<>0})

A full program to run might look like this - it's worth noting that the bounds of the set of primes used should probably be changed if you actually want to run this, since it will take a long time to run for 1 million:

functions
f:nat1+>nat1
f(i)==(lambda p:set of nat1&let z in set p be st forall m in set p&abs(m-i)>=abs(z-i)in z)({x|x in set{1,...,9**7}&forall y in set{2,...,1003}&y<>x=>x mod y<>0})

Explanation:

f(i)==                                        /* f is a function which takes a nat1 (natural number not including 0)*/
(lambda p:set of nat1                         /* define a lambda which takes a set of nat1*/
&let z in set p be st                         /* which has an element z in the set such that */
forall m in set p                             /* for every element in the set*/
&abs(m-i)                                     /* the difference between the element m and the input*/
>=abs(z-i)                                    /* is greater than or equal to the difference between the element z and the input */
in z)                                         /* and return z from the lambda */
(                                             /* apply this lambda to... */
{                                             /* a set defined by comprehension as.. */
x|                                            /* all elements x such that.. */ 
x in set{1,...,9**7}                          /* x is between 1 and 9^7 */
&forall y in set{2,...,1003}                  /* and for all values between 2 and 1003*/
&y<>x=>x mod y<>0                             /* y is not x implies x is not divisible by y*/
} 
)

VDM-SL, 315 bytes

module CG
imports from IO all
exports all
definitions
functions f:seq1 of char->seq1 of char
f(i)==let m={2|->"ABC",3|->"DEF",4|->"GHI",5|->"JKL",6|->"MNO",7|->"PQRS",8|->"TUV",9|->"WXYZ"},q=[z|z in seq i&z in set dom m],a=IO`freadval("f")in let r in set a be st forall x in set inds q&r(x)in set m(i(x))in r
end CG

IO hurts in VDM, since it's intended for modelling first and foremost. For comparison (but not as a submission since IO must be performed not receiving dictionary as input). A 198 byte function could be:

f(a,i)==let m={2|->"ABC",3|->"DEF",4|->"GHI",5|->"JKL",6|->"MNO",7|->"PQRS",8|->"TUV",9|->"WXYZ"},q=[z|z in seq i&z in set dom m]in let r in set a be st forall x in set inds q&r(x)in set m(i(x))in r

Still expensive because of building the map (I'm sure there'll be a good map comprehension for it I've just not thought of it yet) and could save further bytes if the string was guaranteed to only contain values in the domain of the map

1
source | link

VDM-SL, 161 bytes

f(i)==(lambda p:set of nat1&let z in set p be st forall m in set p&abs(m-i)>=abs(z-i)in z)({x|x in set{1,...,9**7}&forall y in set{2,...,1003}&y<>x=>x mod y<>0})

A full program to run might look like this - it's worth noting that the bounds of the set of primes used should probably be changed if you actually want to run this, since it will take a long time to run for 1 million:

functions
f:nat1+>nat1
f(i)==(lambda p:set of nat1&let z in set p be st forall m in set p&abs(m-i)>=abs(z-i)in z)({x|x in set{1,...,9**7}&forall y in set{2,...,1003}&y<>x=>x mod y<>0})

Explanation:

f(i)==                                        /* f is a function which takes a nat1 (natural number not including 0)*/
(lambda p:set of nat1                         /* define a lambda which takes a set of nat1*/
&let z in set p be st                         /* which has an element z in the set such that */
forall m in set p                             /* for every element in the set*/
&abs(m-i)                                     /* the difference between the element m and the input*/
>=abs(z-i)                                    /* is greater than or equal to the difference between the element z and the input */
in z)                                         /* and return z from the lambda */
(                                             /* apply this lambda to... */
{                                             /* a set defined by comprehension as.. */
x|                                            /* all elements x such that.. */ 
x in set{1,...,9**7}                          /* x is between 1 and 9^7 */
&forall y in set{2,...,1003}                  /* and for all values between 2 and 1003*/
&y<>x=>x mod y<>0                             /* y is not x implies x is not divisible by y*/
} 
)