This is a challenge about the the tricks and optimizations that can be used when golfing in Pyth. Pyth golfers may recognize many of the tricks involved. However, unfamiliar approaches and constructs may be involved, so take a look at the Pyth Tips as well as the Pyth Character Reference if you get stuck. Solutions may be tested here.
Goal: There are 8 problems, each with a Pyth snippet for you to optimize. Your goal is to create something equivalent but shorter. The reference solutions total 80 bytes. Your goal is to beat that by as much as possible.
The winner will go to the submission that solves all 8 problems with the smallest total number of bytes. Tiebreaker is earlier post.
Answering: Please spoiler your entire answer, except for your total score. It is intended that you do not look at other people's answers before submitting your own.
Each submission should answer every problem and give the corresponding byte count, but feel free to use the reference implementation if you cannot improve it.
Details: If the question calls for a certain value or output, q
equality is desired, so 1
and !0
are equivalent. If the question calls for testing whether a condition is true, the output must be truthy if the condition is true and falsy if the condition is false, but is unconstrained beyond that. You may not swap true for false and false for true. If the question calls for something to be printed, nothing else may be printed except a trailing newline.
All answers must be valid for the most recent Pyth commit as of this question's posting.
Problem 1: Given a set in Q, output a list containing the elements of Q in any order.
; 3 bytes
f1Q
Problem 2: Output the list [1, 1, 0, 0, 1, 1, 0]
.
; 9 bytes
[J1JZZJJZ
Problem 3: Given a positive integer in Q, test whether all of Q's digits are positive (not zero).
; 7 bytes
!f!TjQT
Problem 4: Given a string in z, test whether z contains any quotation marks - "
or '
.
; 9 bytes
|}\'z}\"z
Problem 5: Map Q=1 to 'Win', Q=0 to 'Tie' and Q=-1 to 'Lose'.
; 20 bytes
@["Tie""Win""Lose")Q
Problem 6: Print 0123456789
.
; 6 bytes
sm`dUT
Problem 7: Given a string in z, count the number of inversions.
(Indexes i
and j
form an inversion if i < j
but z[i] > z[j]
).
; 17 bytes
ssmm>@zd@zkrdlzUz
Problem 8: Given a list in z, count the number of repeated adjacent elements.
; 9 bytes
lfqFT.:z2
f1Q
filtersQ
on a function that is always true, so it always outputs every element of the set.f
outputs a list, which meets the objective in that question. \$\endgroup\$