Activity for Moshi
Type | On... | Excerpt | Status | Date |
---|---|---|---|---|
Edit | Post #284317 | Initial revision | — | about 3 years ago |
Answer | — |
A: The Ludic Numbers [Sclipting], (UTF-16) 58 52 bytes ```text 가匱❸增平갠下氫終要鈮貶⓶梴감⓶上❸乘殲終終并鈮掘增 ``` Gives the nth ludic number, 0-indexed. ```text 가 Start list of Ludics with 0 匱❹增平갠下氫終 Create a list of numbers from 2 to n+1 squared 要 While the list is truthy 鈮 Retrieve the Ludic number x (the first elem... (more) |
— | about 3 years ago |
Comment | Post #284288 |
It's better just to use a for loop instead of an expensive `[...Array(n)].map((_,i)=>`
```
(n,i=n)=>{for(;i;)console.log((' '.repeat(i)+'_/'+'##'.repeat(n-i--)).slice(3))}
```
https://tio.run/##bctBCsIwEEDRfU8R6GJmqInQQDclnkSQEBOJhElJSjfi2SN2IQpu/@Pf7WarK3FZJeerb8E05EM0TOb0CLngHGdymWtOXqV8Qw... (more) |
— | about 3 years ago |
Comment | Post #284289 |
```python
lambda s,n:''.join((c,chr((ord(c)+n-(o:=65+(ord(c)>96)*32))%26+o))[c.isalpha()]for c in s)
```
https://tio.run/##XY3NTsMwEITvPMVyqOwlJlKTNoVK5QzPABwcp/4hxhttDA19@RAkDhTNYaT5PmmGr@wp1XcDz0z58DJH/d52GkaV9kKUbxSSlEYZz1ISd9JgkW4l7Q/NtvgdHu4bvKkrxFXVFIT4bMow6jh4LfHVEoOBkGDEeeCQslxupHg8xkgKT... (more) |
— | about 3 years ago |
Edit | Post #284266 | Initial revision | — | about 3 years ago |
Answer | — |
A: Evaluate a single variable polynomial equation [Python 3], 46 bytes ```python lambda a,x:sum(cxi for i,c in enumerate(a)) ``` Try it online! (more) |
— | about 3 years ago |
Edit | Post #284227 |
Post edited: |
— | about 3 years ago |
Edit | Post #284226 |
Post edited: |
— | about 3 years ago |
Edit | Post #284227 | Initial revision | — | about 3 years ago |
Answer | — |
A: Weave Strings Together [Python 2], 58 54 bytes ```python lambda l:''.join(filter(None,sum(map(None,'',l),()))) ``` Try it online! Amazingly, shorter than my Python 3 answer! Uses this method to zip unequal-length lists and this method to flatten the result. (more) |
— | about 3 years ago |
Edit | Post #284226 | Initial revision | — | about 3 years ago |
Answer | — |
A: Weave Strings Together [Python 3], 72 69 bytes ```python lambda l:''.join(sum(zip([[i]+['']max(map(len,l))for i in l]),())) ``` Try it online! Uses this method to flat zip, with modifications to pad the shorter lists. (more) |
— | about 3 years ago |
Edit | Post #284202 |
Post edited: |
— | about 3 years ago |
Edit | Post #284202 |
Post edited: |
— | about 3 years ago |
Comment | Post #284145 |
It's cheaper to set x outside the loop
```python
x=int(input())
for i in range(x+1):x-i*i or exit(1)
```
[51 bytes](https://tio.run/##K6gsycjPM7YoKPr/v8I2M69EIzOvoLREQ1OTKy2/SCFTITNPoSgxLz1Vo0LbUNOqQjdTK1MBKJFakVmiYaj5/78hAA) (more) |
— | about 3 years ago |
Edit | Post #284202 | Initial revision | — | about 3 years ago |
Answer | — |
A: Collatz conjecture; Count the tries to reach $1$ [Sclipting], (UTF-16) 44 34 32 bytes ``` 貶要❶갠剩❷隔❸增갰乘嗎終并長貶 ``` Because comparing with 1 is expensive (requires copying and decrementing), we instead use a modified version of the Collatz sequence - namely, we use the sequence where every number is one lower. This allows us to compare with 0 in... (more) |
— | about 3 years ago |
Edit | Post #284182 |
Post edited: |
— | about 3 years ago |
Edit | Post #284201 | Initial revision | — | about 3 years ago |
Answer | — |
A: Expand a polynomial [JavaScript (Node.js)], 60 bytes ``` f=([x,...r],y)=>x?[0,...y=f(r)].map((v,i)=>v-x(y[i]|0)):[1] ``` Try it online! (more) |
— | about 3 years ago |
Edit | Post #284129 |
Post edited: |
— | about 3 years ago |
Edit | Post #284182 | Initial revision | — | about 3 years ago |
Answer | — |
A: Decode periodic decimal fractions [JavaScript (Node.js)], 242 234 bytes ```javascript s=>([l,p,i,j,,r]=/(-)?\+?(\d)\.?(\d?)(((\d+)\6|\d)\.|$)/.exec(s),[i,r]=c(c([i|0,1],[j|0,10(l=j.length)]),[r=r||'0',10l(10r.length-1)]),[(p?-i:i)/(j=d(i,r)),r/j]) c=(a,b)=>[a[0]b[1]+b[0]a[1],a[1]b[1]] d=(a,b)=>b?d(b,a%b):a ``` Try it online... (more) |
— | about 3 years ago |
Edit | Post #284129 |
Post edited: |
— | about 3 years ago |
Edit | Post #284129 | Initial revision | — | about 3 years ago |
Answer | — |
A: Abbreviate everything [JavaScript (Node.js)], 91 68 65 bytes ```javascript s=>s.toUpperCase().match(/(?<=^| )[A-Z]|:|;|(?<=[.?!]) /g).join`` ``` Assumes that the original text is properly formatted (has a space after punctuation). It converts the string to uppercase, then matches the following: - A letter at... (more) |
— | about 3 years ago |
Edit | Post #283882 |
Post edited: |
— | about 3 years ago |
Edit | Post #284125 | Initial revision | — | about 3 years ago |
Question | — |
Expand a polynomial Challenge Given the roots of a polynomial (that is, the $x$ values where the polynomial evaluates to zero), as an array of real numbers, return the polynomial's coefficients. That is, given real roots $r1, r2, \cdots , rn$, find the coefficients of the expansion of $(x-r1)(x-r2)\cdots(x-rn)$, o... (more) |
— | about 3 years ago |
Comment | Post #283989 |
Can I return a number instead of a string for the zero case, even if I am using strings for the other return values? (more) |
— | about 3 years ago |
Edit | Post #283990 |
Post edited: |
— | about 3 years ago |
Edit | Post #283990 |
Post edited: |
— | about 3 years ago |
Comment | Post #283990 |
@#53588 That returns a number instead of a string for `f(0)` though, which I'm not sure whether it is allowed. I can implement the other part though for 49 (more) |
— | about 3 years ago |
Comment | Post #284100 |
Instead of doing an indexed for loop, just iterate over the characters directly with `for c in x:`. [38 bytes](https://tio.run/##RYo5CoAwEABrfUXYKitbeFVKer@hOTAQkiAK5vXxKLScI6Z9Db7LWWnDDD8p4VAWJmxMMuvZOcTN@p1rr4SsEuYoXlEaDvMigRocI8cHJ@1cAKo/ocKxOA3U/osF6j@6S435Ag "Python 3 – Try It Online") (more) |
— | about 3 years ago |
Edit | Post #284081 | Initial revision | — | about 3 years ago |
Answer | — |
A: Reverse an ASCII string [Sclipting], (UTF-16) 2 bytes ``` 反 ``` Yay for builtins (more) |
— | about 3 years ago |
Comment | Post #284040 |
See https://en.m.wikipedia.org/wiki/Collatz_conjecture (more) |
— | about 3 years ago |
Edit | Post #284025 | Initial revision | — | about 3 years ago |
Answer | — |
A: Stairs? Stairs! Stairs. [Python 3], 64 bytes ```python def f(n): for i in range(n):print((' '(n-i)+'/'+'##'i)[3:]) ``` Try it online! (more) |
— | about 3 years ago |
Comment | Post #283990 |
@#8056 Fixed it (more) |
— | about 3 years ago |
Edit | Post #283990 |
Post edited: |
— | about 3 years ago |
Comment | Post #283982 |
You can use this trick with more than one statement by using semicolons. For example, this will work as well:
```
for x in range(4):print('a');print(x)
```
[Try it online!](https://tio.run/##K6gsycjPM/7/Py2/SKFCITNPoSgxLz1Vw0TTqqAoM69EQz1RXdMawqzQ/P8fAA "Python 3 – Try It Online") (more) |
— | about 3 years ago |
Comment | Post #284000 |
```
j,k;f(i){for(j=i;j--;printf("#"));for(j=i-1;j--;printf("#"))for(k=i-2,printf("\n#");k--;printf(" "));}
```
[Try it online!](https://tio.run/##S9ZNzknMS///P0sn2zpNI1OzOi2/SCPLNtM6S1fXuqAoM68kTUNJWUlT0xoqoWuIIQWSyQbKGOnARGPygOLW2UjqFEBG1P7PTczM09Cs5uJM0zDVtC4oLSkGKQaqBYmYY4gYGgDp2v8A "C (clang... (more) |
— | about 3 years ago |
Comment | Post #283865 |
@#8056 "On one hand, the wording is obviously misleading because that's not what it was referring to" What was it referring to then? I'm not sure what else it could mean. (more) |
— | about 3 years ago |
Comment | Post #283865 |
If I am understanding these points correctly,
> The tens-/ones part, if not zero, must be separated with and, e.g. two hundred and five, not two hundred five.
>
> The above rules are applied also to the factors of thousand and million.
Then 1,000,001 should be "one million **and** one"; howev... (more) |
— | about 3 years ago |
Edit | Post #283990 |
Post edited: |
— | about 3 years ago |
Edit | Post #283990 | Initial revision | — | about 3 years ago |
Answer | — |
A: When The Ternary Is Balance [JavaScript (Node.js)], 47 40 50 49 bytes -1 (possibly -3) bytes thanks to Shaggy! ``` f=(n,s='0')=>n?f(n/3+n%3/2|0,'')+"+-0+-"[n%3+2]:s ``` Try it online! A basic recursive solution. (more) |
— | about 3 years ago |
Comment | Post #283978 |
https://tio.run/##JclLCoAgEADQvaeQVn5wIe0Mu0i0ksIBGUUMptNPQtv32jtyxZWZImB7htKCbKQjBOdPAdF5cdcukwSUUyeG1gGHSkbB7ry2i1wM2KQ3sNGLP0kz56uU@gE
```
x=input()
x+=x[::-1]
i=-1
for c in x[:-1]:print(c*(i>-1)+" "*i+c);i+=1
print(x)
```
Three improvements: 1. Use `x[::-1]` instead of `x[-2::-1]` 2. Us... (more) |
— | about 3 years ago |
Edit | Post #283789 |
Post edited: Apparently forgot to copy the footnote from the Sandbox |
— | about 3 years ago |