YAPC::EU 2018 Glasgow Update!
This commit is contained in:
parent
22f33d4004
commit
4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions
|
|
@ -36,14 +36,14 @@ extension op
|
|||
]
|
||||
}
|
||||
|
||||
public program =
|
||||
public program
|
||||
[
|
||||
("abracadabra", "seesaw", "grrrrrr", "pop", "up", "a") forEach(:aWord)
|
||||
("abracadabra", "seesaw", "grrrrrr", "pop", "up", "a") forEach(:s)
|
||||
[
|
||||
var aShuffled := aWord shuffled.
|
||||
var shuffled_s := s shuffled.
|
||||
|
||||
console printLine("The best shuffle of ",aWord," is ",aShuffled,"(",aShuffled score:aWord,")").
|
||||
console printLine("The best shuffle of ",s," is ",shuffled_s,"(",shuffled_s score:s,")").
|
||||
].
|
||||
|
||||
console readChar.
|
||||
].
|
||||
console readChar
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,30 +1,30 @@
|
|||
/*REXX program determines and displays the best shuffle for any list of words/characters*/
|
||||
/*REXX program determines and displays the best shuffle for any list of words or tokens.*/
|
||||
parse arg $ /*get some words from the command line.*/
|
||||
if $='' then $= 'tree abracadabra seesaw elk grrrrrr up a' /*use the defaults?*/
|
||||
w=0; #=words($) /* [↑] finds the widest word in $ list*/
|
||||
do i=1 for #; @.i=word($,i); w=max(w, length(@.i) ); end /*i*/
|
||||
w=w+9 /*add 9 blanks for output indentation. */
|
||||
do n=1 for #; new=bestShuffle(@.n) /*process the examples in the @ array. */
|
||||
do i=1 for #; @.i=word($,i); w=max(w, length(@.i) ); end /*i*/
|
||||
w= w+9 /*add 9 blanks for output indentation. */
|
||||
do n=1 for #; new= bestShuffle(@.n) /*process the examples in the @ array. */
|
||||
same=0; do m=1 for length(@.n)
|
||||
same=same + (substr(@.n, m, 1) == substr(new, m, 1) )
|
||||
end /*m*/
|
||||
say 'original:' left(@.n, w) 'new:' left(new,w) 'count:' same
|
||||
say ' original:' left(@.n, w) 'new:' left(new,w) 'score:' same
|
||||
end /*n*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
bestShuffle: procedure; parse arg x 1 ox; L=length(x); if L<3 then return reverse(x)
|
||||
/*[↑] fast track short strs*/
|
||||
do j=1 for L-1; parse var x =(j) a +1 b +1 /*get A,B at Jth & J+1 pos.*/
|
||||
if a\==b then iterate /*ignore any replicates. */
|
||||
c=verify(x,a); if c==0 then iterate /* " " " */
|
||||
x=overlay( substr(x,c,1), overlay(a,x,c), j) /*swap the x,c characters*/
|
||||
rx=reverse(x) /*obtain the reverse of X. */
|
||||
y=substr(rx, verify(rx,a), 1) /*get 2nd replicated char. */
|
||||
x=overlay(y, overlay(a,x, lastpos(y,x)),j+1) /*fast swap of 2 characters*/
|
||||
end /*j*/
|
||||
do k=1 for L; a=substr(x,k,1) /*handle a possible rep. */
|
||||
if a\==substr(ox,k,1) then iterate /*skip non-replications*/
|
||||
if k==L then x=left(x,k-2)a || substr(x,k-1,1) /*last case*/
|
||||
else x=left(x,k-1)substr(x,k+1,1)a || substr(x, k+2)
|
||||
end /*k*/
|
||||
do j=1 for L-1; parse var x =(j) a +1 b +1 /*get A,B at Jth & J+1 pos.*/
|
||||
if a\==b then iterate /*ignore any replicates. */
|
||||
c= verify(x,a); if c==0 then iterate /* " " " */
|
||||
x= overlay( substr(x,c,1), overlay(a,x,c), j) /*swap the x,c characters*/
|
||||
rx= reverse(x) /*obtain the reverse of X. */
|
||||
y= substr(rx, verify(rx, a), 1) /*get 2nd replicated char. */
|
||||
x= overlay(y, overlay(a,x, lastpos(y,x)),j+1) /*fast swap of 2 characters*/
|
||||
end /*j*/
|
||||
do k=1 for L; a=substr(x, k, 1) /*handle a possible rep*/
|
||||
if a\==substr(ox, k, 1) then iterate /*skip non-replications*/
|
||||
if k==L then x= left(x, k-2)a || substr(x, k-1,1) /*last case*/
|
||||
else x= left(x, k-1)substr(x, k+1, 1)a || substr(x,k+2)
|
||||
end /*k*/
|
||||
return x
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
# Project : Best shuffle
|
||||
# Date : 2018/02/15
|
||||
# Author : Gal Zsolt (~ CalmoSoft ~)
|
||||
# Email : <calmosoft@gmail.com>
|
||||
|
||||
test = ["abracadabra", "seesaw", "elk", "grrrrrr", "up", "a"]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue