38
Awesome Team
Stefan Pochmann
http://www.stefan-pochmann.info/
Last seen 3 hours ago
Member for 9 years, 1 month, 4 days
Difficulty Normal
Recent solutions I'm happy with (just starting/trying this):
[Words Order](https://py.checkio.org/mission/words-order/publications/StefanPochmann/python-3/short-dict-subsequence/share/5bbb2df54ec5a810d36d7f70ae7e92da/)
Dang it no markdown here?
[Why does naive string concatenation become quadratic above a certain length?](https://stackoverflow.com/q/44487537)
More
Now *that's* a stack. Inspired this silly thing. I don't really like it, but at least it uses `match` for actual *structural* matching (unlike all the other solutions I saw which only did `match item:`). And I do like my fifth case.
```python
def postfix_evaluate(items):
stack = ()
for item
More
And another solution further away but still inspired by yours:
```python
from operator import add, sub, mul
ops = {'+': add, '-': sub, '*': mul, '/': lambda x, y: y and x // y}
def postfix_evaluate(items: list[int|str]) -> int:
if op := ops.get(item := items.pop()):
right = postfix_eva
More
Tadaa! Non-recursive top-down, and I'm actually loving this one. I don't even have to peel the result value off the stack at the end.
```python
def postfix_evaluate(items: list[int|str]) -> int:
stack = ()
for item in reversed(items):
while True:
match item, stack:
More
I want a button to hide all comments so I can read the code, without distractions :-P
More
`isvowel = set("aeiouAEIOU").__contains__` seems more natural to me. Did you first use `dict.fromkeys("aeiouAEIOU", True).get` and then switched to `__contains__`?
`"aeiouAEIOU".__contains__` also works, as does `"aeiouAEIOU".count` :-). But I think `set` is best.
More
Ugh, I just noticed that all lines are almost equally long, just one is one char too short and another is one char too long. Irritating.
More
If I'm not mistaken, everybody else worked bottom-up (i.e., `items` from left to right).
Previously posted [a few other variants](https://py.checkio.org/mission/postfix-evaluation/publications/veky/python-3/packed-with-fun/share/8c79fa5a557ecd890f2b65385934c008/#comment-126213).
More
Some variations (first one is yours, for easy comparison):
```python
def beat_previous(digits: str, last: int=-1) -> list[int]:
try:
s, i = next((s, i) for s in accumulate(digits) if (i:=int(s)) > last)
return [i] + beat_previous(digits[len(s):], i)
except StopIteration:
More
Variation of my [original](https://py.checkio.org/mission/sequence-analyzer/publications/StefanPochmann/python-3/six/?ordering=most_voted&filtering=all), just adding helpers to make the actual solution cleaner.
Yet another variation with the same helpers:
```python
def analyzer(s):
for j, c in
More
Also posted a [variation](https://py.checkio.org/mission/sequence-analyzer/publications/StefanPochmann/python-3/convenience/#comment-126282) with easier translation between characters and numbers.
More
Haven't gotten wrong results from this is version, but some cases are extremely slow again, like `balanced_centrifuge(80, 77)` (119 seconds) and `balanced_centrifuge(98, 93)` (ran for about 7 minutes until it was killed, not sure why).
More
That looks right, although a bit slow. I might use `{*sympy.factorint(n), 0}`, I really dislike explicit `.keys()` calls.
And you could make it faster by using `issubset` on an iterator instead of building the whole set of sums:
```python
def balanced_centrifuge(n: int, k: int) -> bool:
return
More
`return {k, n - k} <= allowed` would also work. Or without duplication:
```
need = {k, n - k}
limit = max(need}
...
return need <= allowed
```
More
Inspired by [@mildm's solution](
https://py.checkio.org/mission/longest-common-prefix/publications/mildm/python-3/first/share/bb6db9d7936b4e2875616378bc669731/).
More
Hmm. `collatz_convert('uddudd')` returns `1`. I think it should be `None`, since the original forward-going Collatz sequence **stops** when 1 is reached, doesn't run extra cycles 1->4->2->1.
More
This one seems quite buggy. Some test cases (input, what I'd expect, and what you return):
```
'u' None 0.0
'ud' None 0.3333333333333333
'du' None 0.0
'udu' None -0.3333333333333333
'udd' None 1.0
'dud' None 0.6666666666666666
'ddu' None 0.0
'udud' None -0.11111111111111112
'uddu' None -0.333333333
More