Activity for radarekā
Type | On... | Excerpt | Status | Date |
---|---|---|---|---|
Edit | Post #285592 |
Post edited: |
— | 8 months ago |
Edit | Post #286079 | Initial revision | — | about 1 year ago |
Answer | — |
A: Solve Goldbach's Conjecture Ruby, 62 bytes require'prime';f=->n,k=0{n.prime?&&k.prime?? [n,k]:f[n-1,k+1]} Attempt This Online! (more) |
— | about 1 year ago |
Edit | Post #285629 |
Post edited: |
— | about 1 year ago |
Edit | Post #285629 |
Post edited: |
— | about 1 year ago |
Comment | Post #285743 |
@#53310 Thanks for spotting it. Fixed. (more) |
— | about 1 year ago |
Edit | Post #285743 |
Post edited: |
— | about 1 year ago |
Edit | Post #285743 | Initial revision | — | about 1 year ago |
Answer | — |
A: Golf a FRACTRAN interpreter Ruby, 44 bytes ->p,n{n=I while I=p.find{1n%1==0};n.toi} Attempt This Online! (more) |
— | about 1 year ago |
Edit | Post #285708 | Initial revision | — | about 1 year ago |
Answer | — |
A: Stairs? Stairs! Stairs. Ruby, 50 bytes ->n{n.times{puts (' '(n-1)+'/'+'##'1)[3..]}} Attempt This Online! (more) |
— | about 1 year ago |
Edit | Post #285496 |
Post edited: |
— | about 1 year ago |
Edit | Post #285707 | Initial revision | — | about 1 year ago |
Answer | — |
A: Operation "Find The Operator" Ruby, 57 bytes ->a,b,c{%w[+ - / % ].select{c==a.send(1,b)rescue p}} Attempt This Online! (more) |
— | about 1 year ago |
Comment | Post #285331 |
However, your code and mine suggestion don't work with input `*,0,*` (division by 0). The error must by properly handled. (more) |
— | about 1 year ago |
Comment | Post #285692 |
Unfortunately this does not work for input 0, 2 and 0, 2.
```
f=->a,b{a|b==2?5:a+b}
f[0, 2] # => 5
``` (more) |
— | about 1 year ago |
Edit | Post #285706 | Initial revision | — | about 1 year ago |
Answer | — |
A: Make $2 + 2 = 5$ Ruby, 20 bytes ->a,b{4[a]4[b]+a+b} Attempt This Online! (more) |
— | about 1 year ago |
Edit | Post #285592 |
Post edited: |
— | about 1 year ago |
Edit | Post #285605 |
Post edited: |
— | about 1 year ago |
Edit | Post #285496 |
Post edited: |
— | about 1 year ago |
Edit | Post #285668 |
Post edited: |
— | about 1 year ago |
Edit | Post #285668 | Initial revision | — | about 1 year ago |
Answer | — |
A: Given the preorder and the inorder of a tree, output the postorder Ruby, 75 72 bytes f=->((e,r),n){(i=n.index e)?f[r[0,i],n[...i]]+f[r[i..],n[i+1..]]+[e]:n} Attempt This Online! (more) |
— | about 1 year ago |
Edit | Post #285667 | Initial revision | — | about 1 year ago |
Answer | — |
A: Compute the determinant Ruby, 35 bytes ->m{require'matrix';Matrix[m].det} Attempt This Online! (more) |
— | about 1 year ago |
Edit | Post #285618 |
Post edited: |
— | about 1 year ago |
Edit | Post #285659 | Initial revision | — | about 1 year ago |
Answer | — |
A: Prime Difference Ruby, 56 bytes ```ruby ->n{require'prime';Prime.eachcons(2).find{2-1>=n}[0]} ``` Attempt This Online! (more) |
— | about 1 year ago |
Edit | Post #285630 |
Post edited: |
— | about 1 year ago |
Edit | Post #285630 |
Post edited: |
— | about 1 year ago |
Edit | Post #285629 |
Post edited: |
— | about 1 year ago |
Comment | Post #283012 |
@#53607 Ok, make sense. (more) |
— | about 1 year ago |
Comment | Post #285618 |
@#55346 nice catch! Thanks. (more) |
— | about 1 year ago |
Edit | Post #285655 |
Post edited: |
— | about 1 year ago |
Edit | Post #285655 |
Post edited: |
— | about 1 year ago |
Edit | Post #285655 |
Post edited: |
— | about 1 year ago |
Edit | Post #285655 | Initial revision | — | about 1 year ago |
Answer | — |
A: Merge two strings Ruby, 40 bytes ```ruby f=->a,b{b.index(a)==0?b:a[/./m]+f[$',b]} ``` Attempt This Online! If we could assume that string contains only letters and numbers (or to be more specific, no characters like `\t\n\v\f\r \#$()+-.?[\\]^{|}`) then it could be improved to 36 bytes: ```ruby f=->a,b{b... (more) |
— | about 1 year ago |
Comment | Post #281542 |
What characters can strings include? Only letters (like in examples)? New lines can be included? What about other characters? (more) |
— | about 1 year ago |
Edit | Post #285622 |
Post edited: |
— | about 1 year ago |
Edit | Post #285622 |
Post edited: |
— | about 1 year ago |
Edit | Post #285622 |
Post edited: |
— | about 1 year ago |
Edit | Post #285622 |
Post edited: |
— | about 1 year ago |
Edit | Post #285622 |
Post edited: |
— | about 1 year ago |
Edit | Post #285622 |
Post edited: |
— | about 1 year ago |
Edit | Post #285622 |
Post edited: |
— | about 1 year ago |
Edit | Post #285622 |
Post edited: |
— | about 1 year ago |
Edit | Post #285632 | Initial revision | — | about 1 year ago |
Answer | — |
A: A number adder, not a death adder Ruby, 25 bytes ```ruby puts"p #{gets}+gets.toi" ``` P1 - Try this online! P2 - Try this online! (more) |
— | about 1 year ago |
Edit | Post #285631 | Initial revision | — | about 1 year ago |
Answer | — |
A: Evens or Odds - you know this one Ruby, 13 bytes According to the rules, programs should read from STDIN and output to the STDOUT. This is my solution: ```ruby p gets.toi&1 ``` Try this online! (more) |
— | about 1 year ago |
Edit | Post #285630 | Initial revision | — | about 1 year ago |
Answer | — |
A: Weave Strings Together Ruby, 48 45 bytes ```ruby ->w{([p].w''=/$/).zip(w.map(&:chars))''} ``` Try this online! It could be improved to 32 bytes, if every string is represented as an array of characters: ```ruby ->w{([p].w''=/$/).zip(w)''} ``` Attempt This Online! (more) |
— | about 1 year ago |
Edit | Post #285629 | Initial revision | — | about 1 year ago |
Answer | — |
A: Are All Elements Equal? Ruby, 14 bytes ```ruby ->{1|[]in[]} ``` Alternative solution: ```ruby ->a{!(a|a)[1]} ``` Try this online! Couple of other solutions I developed: ```ruby ->a{!a.uniq[1]} # 15 bytes ->{!(1|[])[1]} # 15 bytes ->a{(a|a).one?} # 15 bytes ``` (more) |
— | about 1 year ago |
Edit | Post #285618 |
Post edited: |
— | about 1 year ago |
Edit | Post #285623 |
Post edited: |
— | about 1 year ago |
Edit | Post #285623 |
Post edited: |
— | about 1 year ago |
Edit | Post #285623 | Initial revision | — | about 1 year ago |
Answer | — |
A: Make my number a set Ruby, 23 bytes ```ruby ->n,x{eval'xn{eval'$<<$1;'n} ``` Try this online! (more) |
— | about 1 year ago |
Edit | Post #285622 | Initial revision | — | about 1 year ago |
Answer | — |
A: Coat of Many Colours Ruby, 101 79 76 72 bytes This challenge was one of the funniest I have ever solved! 72 bytes solution (I show the solution as a Ruby string - because binary data is filtered out) ```ruby "->l{l.sortby{'d\v\x162\x82\r\x1D\nJ\"\x01T\x0E?\x8B.\x11\x05\x06G(\fM\x00 HyI'.index''<<1[2,4].sum%145}... (more) |
— | about 1 year ago |
Edit | Post #285621 | Initial revision | — | about 1 year ago |
Answer | — |
A: Repeat the characters Ruby, 23 bytes ```ruby ->{1.gsub /./,'\0'2} ``` Try this online! (more) |
— | about 1 year ago |
Edit | Post #285618 | Initial revision | — | about 1 year ago |
Answer | — |
A: Write a Deadfish Interpreter Ruby, 70 67 66 bytes ```ruby ->c{a=0;c.bytes{|b|a,=[b<106?a+b/3-34:b<112?p(a):aa,0]-[-1,256]}} ``` Test this online! (more) |
— | about 1 year ago |
Edit | Post #285611 |
Post edited: |
— | about 1 year ago |
Edit | Post #285611 |
Post edited: |
— | about 1 year ago |
Edit | Post #285611 |
Post edited: |
— | about 1 year ago |
Edit | Post #285611 | Initial revision | — | about 1 year ago |
Answer | — |
A: Small integer swapping Ruby, 24 bytes ```ruby gets=/ /;puts$`,$'2+$` ``` Try this online! (more) |
— | about 1 year ago |
Edit | Post #285610 | Initial revision | — | about 1 year ago |
Answer | — |
A: Word Count Tool Ruby, 48 bytes ```ruby ->a{[a.split,b=a.chars-[$/],b-[' ']].map &:size} ``` Try this online! (more) |
— | about 1 year ago |
Edit | Post #285606 |
Post edited: |
— | about 1 year ago |
Edit | Post #285606 |
Post edited: |
— | about 1 year ago |
Edit | Post #285606 | Initial revision | — | about 1 year ago |
Answer | — |
A: Digit Sum Integer Sequence (working title) Ruby, 36 bytes Infinite version: ```ruby n=1;0while n+=p(n).digits.minmax.sum ``` Try this online! (program is interrupted after it reaches the 128KiB limit of output) (more) |
— | about 1 year ago |
Edit | Post #285605 | Initial revision | — | about 1 year ago |
Answer | — |
A: Diagonalized alphabet Ruby, 52 51 bytes 13.times{puts:YWUSQOMKIGECABDFHJLNPRTVXZ[12-1,14]} Attempt This Online! (more) |
— | about 1 year ago |
Edit | Post #285597 | Initial revision | — | about 1 year ago |
Answer | — |
A: Word Set Square Ruby, 70 bytes ```ruby ->s{s+=s.reverse;s[..-2].gsub(/./){t=$&+' '$.+$/;t[-2]=$&;$.+=1;t}+s} ``` Try this online! (more) |
— | about 1 year ago |
Edit | Post #285592 |
Post edited: |
— | about 1 year ago |
Comment | Post #283012 |
According to the description, input is a given as a string, not a array of strings (lines) as your solution is implemented. (more) |
— | about 1 year ago |
Edit | Post #285592 |
Post edited: |
— | about 1 year ago |
Edit | Post #285593 | Initial revision | — | about 1 year ago |
Answer | — |
A: Multiply complex numbers. Ruby, 25 bytes ```ruby ->e{e.toce[/ ./].toc} ``` Try this online! (more) |
— | about 1 year ago |
Edit | Post #285592 |
Post edited: |
— | about 1 year ago |
Edit | Post #285592 | Initial revision | — | about 1 year ago |
Answer | — |
A: Cumulative Counts Ruby, 31 bytes ```ruby ->a{a.map{$[1]=1.+$[1]||0}} ``` Try this online! `$` is a global variable, so calling this lambda multiple times (in a single process) would give wrong result. A 32 bytes version that does not rely on a global state: ```ruby ->a,c{a.map{c[1]=1.+c[1]||0}} ``` ... (more) |
— | about 1 year ago |
Edit | Post #285588 | Initial revision | — | about 1 year ago |
Answer | — |
A: Bytes to Segfault Ruby, 14 bytes ```ruby `kill -11 #$$` ``` Try this online! (more) |
— | about 1 year ago |
Edit | Post #285519 | Initial revision | — | about 1 year ago |
Answer | — |
A: Generalized Sort Ruby, 25 bytes Credits goes to @Shaggy and his JavaScript solution. ```ruby ->a,l{l.map{a.sort! &1}} ``` Try this online! The other solution which not mutate original array (more) |
— | about 1 year ago |
Edit | Post #285512 | Initial revision | — | about 1 year ago |
Answer | — |
A: Reduce over the range [1..n] Ruby, 22 bytes ```ruby ->{(1..2).reduce &1} ``` Try this online! Without using `reduce` (28 bytes): ```ruby f=->g,n{n<2?n:g[n,f[g,n-1]]} ``` Try this online! (more) |
— | about 1 year ago |
Comment | Post #283278 |
Also, the solution you provided does not follow problem description. The code does not reduce 1..n (n is a parameter). (more) |
— | about 1 year ago |
Comment | Post #283278 |
I don't think that first code is correct. If you want to pass proc/lambda as a block to `reduce` method, then `&` is needed.
```ruby
->{_2.reduce(&_1)}
```
To make it shorter, `()` can be omitted:
```ruby
->{_2.reduce &_1}
```
[Try this online](https://ato.pxeger.com/run?1=m72kqDSpcsH... (more) |
— | about 1 year ago |
Edit | Post #285507 |
Post edited: |
— | about 1 year ago |
Edit | Post #285507 | Initial revision | — | about 1 year ago |
Answer | — |
A: Golf golf challenge Ruby, 100 96 bytes According to the rules, trailing white spaces and line feed are allowed and my program uses that: ```ruby ->p,s{"Par Bogey Double bogey Triple bogey Hole in one Albatross Eagle Birdie".lines[s<2?4:s-p]} ``` Try this online! (more) |
— | about 1 year ago |
Edit | Post #285496 | Initial revision | — | about 1 year ago |
Answer | — |
A: Roll n fair dice Ruby, 27 24 bytes ->n,m{eval'-rand(m)'n} Attempt This Online! If we change the order of `n, m` parameters to `m, n` then following 23 bytes version work, but only in ruby 2.7 (it does not work in 3.x - bug or feature?): ```ruby ->{eval'-rand(1)'2} ``` (more) |
— | about 1 year ago |
Edit | Post #285480 |
Post edited: |
— | about 1 year ago |
Edit | Post #285482 |
Post edited: |
— | about 1 year ago |
Edit | Post #285482 |
Post edited: |
— | about 1 year ago |
Edit | Post #285482 | Initial revision | — | about 1 year ago |
Answer | — |
A: Evaluate a single variable polynomial equation Ruby, 29 bytes ```ruby ->l,x{a,b=l;a ?a+xf[b,x]:0} ``` Try it online (more) |
— | about 1 year ago |
Edit | Post #285480 |
Post edited: |
— | about 1 year ago |
Edit | Post #285480 |
Post edited: |
— | about 1 year ago |
Edit | Post #285480 |
Post edited: |
— | about 1 year ago |
Edit | Post #285480 | Initial revision | — | about 1 year ago |
Answer | — |
A: Determine whether an integer is square-free Ruby, 27 bytes ```ruby ->n{(2..n).all?{n%12>0}} ``` Try it online (more) |
— | about 1 year ago |
Comment | Post #285404 |
@#53310 Good catch, thanks! (more) |
— | about 1 year ago |
Comment | Post #285331 |
```ruby
->a,b,c{%w[+ - * / % **].select{eval"a#{_1}b==c"}}
```
(more) |
— | about 1 year ago |
Comment | Post #285404 |
You can make it 1b shorter by using `$><<` to output value in P2:
```
puts"$><<#{gets}+gets.to_i"
```
(more) |
— | about 1 year ago |