Activity for Zakk
Type | On... | Excerpt | Status | Date |
---|---|---|---|---|
Edit | Post #286362 |
Post edited: |
— | 11 months ago |
Edit | Post #286362 |
Post edited: |
— | 11 months ago |
Edit | Post #286668 | Initial revision | — | over 2 years ago |
Answer | — |
A: Make a frequency table (histogram) Lua, 98 bytes ``` lua function(t)r={}for k,v in pairs(t)do r[v]=0 end for k,v in pairs(t)do r[v]=r[v]+1 end return r end ``` Attempt This Online! (more) |
— | over 2 years ago |
Edit | Post #286369 |
Post edited: Shortened the code. |
— | over 2 years ago |
Comment | Post #284049 |
From [this](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf):
> — removed the `gets` function (`<stdio.h>`) (more) |
— | over 2 years ago |
Comment | Post #286394 |
> Write a **full** program
Does that mean using only the code section of some try-it-online tool?
> writes another program
Does that mean generting an executable/script file? Or only printing the program is enough?
> The length of each program must tend toward infinity as the sequence con... (more) |
— | over 2 years ago |
Comment | Post #284611 |
You can shorten your code by comparing `x*y` against `4`:
``` java
x->y->x*y==4?5:x+y
```
There are 3 possibilities:
$$x=2,y=2 \Longrightarrow x \times y = 5 \text{ as of the rules}$$
$$x=1,y=4 \Longrightarrow x + y = 5 \text{ still a valid result}$$
$$x=4,y=1 \Longrightarrow x + y = 5 ... (more) |
— | over 2 years ago |
Edit | Post #286385 | Initial revision | — | over 2 years ago |
Answer | — |
A: Word Count Tool JavaScript (Node.js), 60 bytes ``` javascript s=>[/\w+/g,/./g,/[\S\t]/g].map(p=>(v=s.match(p))?v.length:0) ``` Attempt This Online! (more) |
— | over 2 years ago |
Edit | Post #286384 |
Post edited: |
— | over 2 years ago |
Edit | Post #286384 |
Post edited: |
— | over 2 years ago |
Edit | Post #286384 | Initial revision | — | over 2 years ago |
Answer | — |
A: Word Count Tool Lua 5.4, 62 bytes ``` lua ,w=s:gsub('%w+',0),c=s:gsub('[^\n]',0),n=s:gsub('[%g\t]',0) ``` Attempt This Online! Another version, 65 bytes: ``` lua p={'%w+','[^\n]','[%g\t]'}for i=1,#p do ,r[i]=s:gsub(p[i],'')end ``` Attempt This Online! (more) |
— | over 2 years ago |
Comment | Post #286370 |
Thank you for your suggestions! The use of an array was a nice trick. (more) |
— | over 2 years ago |
Edit | Post #286370 |
Post edited: |
— | over 2 years ago |
Edit | Post #286370 |
Post edited: Shortened the code. |
— | over 2 years ago |
Edit | Post #286370 | Initial revision | — | over 2 years ago |
Answer | — |
A: Collatz conjecture; Count the tries to reach $1$ Lua 5.4, 67 60 bytes ``` lua function(x)return x==1 and 0 or 1+f(({x/2,3x+1})[x%2+1])end ``` Attempt This Online! Credits to @Moshi for more shortening. (more) |
— | over 2 years ago |
Edit | Post #286369 | Initial revision | — | over 2 years ago |
Answer | — |
A: Collatz conjecture; Count the tries to reach $1$ C (gcc), 43 38 bytes ``` C f(i){return i>1?f(i%2?3i+1:i/2)+1:0;} ``` Attempt This Online! Credits to @Moshi for shortening the code. (more) |
— | over 2 years ago |
Edit | Post #286359 |
Post edited: |
— | over 2 years ago |
Comment | Post #286359 |
> If Lua has such a thing, you can use it without reservation.
I guess yes. If you call this a first-class function:
```
f = function(m,n)for i=0,m*n-1 do _=(i%n==0)and print()or io.write(i,' ')end end
```
So I will use it from now onwards.
> I'll add this in a Meta post later, but the... (more) |
— | over 2 years ago |
Edit | Post #286360 |
Post edited: |
— | over 2 years ago |
Comment | Post #286360 |
Okay, I will change that. (more) |
— | over 2 years ago |
Comment | Post #286359 |
I've put the function definition in the header section. I don't know if this is allowed or not. I see a lot of people doing that, putting only the relevent part/expression in the code section.
Here is the full function, 78 bytes:
``` lua
function f(m,n)for i=0,m*n-1 do _=(i%n==0)and print()or ... (more) |
— | over 2 years ago |
Edit | Post #286362 |
Post edited: |
— | over 2 years ago |
Edit | Post #286362 | Post undeleted | — | over 2 years ago |
Edit | Post #286362 |
Post edited: |
— | over 2 years ago |
Edit | Post #286362 |
Post edited: |
— | over 2 years ago |
Edit | Post #286362 | Post deleted | — | over 2 years ago |
Edit | Post #286362 | Initial revision | — | over 2 years ago |
Answer | — |
A: Make $2 + 2 = 5$ C (gcc), 41 bytes ```c f(x,y){int r=xy;return r&&r==x+y?5:x+y;} ``` Attempt This Online! (more) |
— | over 2 years ago |
Edit | Post #286359 |
Post edited: Shortened the code. |
— | over 2 years ago |
Edit | Post #286360 | Initial revision | — | over 2 years ago |
Answer | — |
A: Create a range grid C (gcc), 59 bytes ``` C i;f(m,n){while(i<mn){putchar(i%n?32:13);putchar(48+i++);}} ``` Attempt This Online! `m` is the number of rows. `n` is the number of columns. (more) |
— | over 2 years ago |
Edit | Post #286359 | Initial revision | — | over 2 years ago |
Answer | — |
A: Create a range grid Lua 5.4, 76 bytes ``` lua function(m,n)for i=0,mn-1 do =(i%n==0)and print()or io.write(i,' ')end end ``` Try it online! (more) |
— | over 2 years ago |
Edit | Post #286329 |
Post edited: |
— | over 2 years ago |
Edit | Post #286321 |
Post edited: |
— | over 2 years ago |
Edit | Post #286344 |
Post edited: |
— | over 2 years ago |
Edit | Post #286344 |
Post edited: |
— | over 2 years ago |
Edit | Post #286344 | Initial revision | — | over 2 years ago |
Answer | — |
A: It's Hip to be Square C (gcc), 37 bytes ``` C f(n,p){while(++pp<n);return pp==n;} ``` Try it online! The solution is based on the simple fact that: $$\forall n \in \mathbb{N}, n \text{ is a perfect square} \Longleftrightarrow \exists p \in \mathbb{N}, p \le n \text{ / } p^2=n$$ (more) |
— | over 2 years ago |
Edit | Post #286343 | Initial revision | — | over 2 years ago |
Answer | — |
A: It's Hip to be Square Lua 5.4, 9 bytes ``` lua n^.5%1==0 ``` Try it online! The entire compressed code is 33 bytes: ``` lua function f(n)return n^.5%1==0 end ``` Try it here. It's not clear whether the rules allow the first form (i.e. only the relevant expression) or the second form (i.e. the ent... (more) |
— | over 2 years ago |
Edit | Post #286342 | Initial revision | — | over 2 years ago |
Answer | — |
A: It's Hip to be Square JavaScript (V8), 13 bytes ``` javascript x=>x.5%1==0 ``` Try it online! (more) |
— | over 2 years ago |
Edit | Post #286324 |
Post edited: Removed one semicolon. |
— | over 2 years ago |
Edit | Post #286331 | Initial revision | — | over 2 years ago |