Best shuffle: Difference between revisions
Content added Content deleted
MaiconSoft (talk | contribs) No edit summary |
(Added BaCon version.) |
||
Line 303: | Line 303: | ||
The output might change if the <tt>for (c in set)</tt> loop iterates the array in a different order. |
The output might change if the <tt>for (c in set)</tt> loop iterates the array in a different order. |
||
=={{header|BaCon}}== |
|||
<lang bacon>DECLARE case$[] = { "tree", "abracadabra", "seesaw", "elk", "grrrrrr", "up", "a" } |
|||
FOR z = 0 TO UBOUND(case$)-1 |
|||
result$ = EXPLODE$(case$[z], 1) |
|||
FOR y = 1 TO AMOUNT(result$) |
|||
FOR x = 1 TO LEN(case$[z]) |
|||
IF TOKEN$(result$, y) <> MID$(case$[z], x, 1) AND TOKEN$(result$, x) = MID$(case$[z], x, 1) THEN result$ = EXCHANGE$(result$, x, y) |
|||
NEXT |
|||
NEXT |
|||
total = 0 |
|||
FOR x = 1 TO AMOUNT(result$) |
|||
INCR total, IIF(MID$(case$[z], x, 1) = TOKEN$(result$, x), 1, 0) |
|||
NEXT |
|||
PRINT MERGE$(result$), ":", total |
|||
NEXT</lang> |
|||
{{output}} |
|||
eert:0 |
|||
baaracadabr:0 |
|||
wsseea:0 |
|||
kel:0 |
|||
rgrrrrr:5 |
|||
pu:0 |
|||
a:1 |
|||
=={{header|BBC BASIC}}== |
=={{header|BBC BASIC}}== |