Post History
Ruby, 31 bytes ->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 vers...
Answer
#6: Post edited
- # [Ruby](https://www.ruby-lang.org/), 31 bytes
- ```ruby
- ->a{a.map{$*[_1]=1.+$*[_1]||0}}
- ```
- **[Try this online!](https://ato.pxeger.com/run?1=m72kqDSpcsHiNNuYpaUlaboW-3XtEqsT9XITC6pVtKLjDWNtDfW0IayaGoPaWoiqm6YFCmnR0YY6hjpGYGgIhsY6xrGxCsoKunYK0YZgUSOQmI6JjimIHQvRvGABhAYA)**
`$*` is a global variable, so calling this lambda multiple times (in a single process) would give wrong result. A 33 bytes version that does not rely on a global state:- ```ruby
- ->a,*c{a.map{c[_1]=1.+c[_1]||0}}
- ```
- If array consists of positive integers from a known range (lets say `0...1e3`, then 30 bytes version is:
- ```ruby
- ->a{b=[0]*1e3;a.map{b[_1]+=1}}
- ```
- # [Ruby](https://www.ruby-lang.org/), 31 bytes
- ```ruby
- ->a{a.map{$*[_1]=1.+$*[_1]||0}}
- ```
- **[Try this online!](https://ato.pxeger.com/run?1=m72kqDSpcsHiNNuYpaUlaboW-3XtEqsT9XITC6pVtKLjDWNtDfW0IayaGoPaWoiqm6YFCmnR0YY6hjpGYGgIhsY6xrGxCsoKunYK0YZgUSOQmI6JjimIHQvRvGABhAYA)**
- `$*` 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}}
- ```
- If array consists of positive integers from a known range (lets say `0...1e3`, then 30 bytes version is:
- ```ruby
- ->a{b=[0]*1e3;a.map{b[_1]+=1}}
- ```
#5: Post edited
- # [Ruby](https://www.ruby-lang.org/), 31 bytes
- ```ruby
- ->a{a.map{$*[_1]=1.+$*[_1]||0}}
- ```
- **[Try this online!](https://ato.pxeger.com/run?1=m72kqDSpcsHiNNuYpaUlaboW-3XtEqsT9XITC6pVtKLjDWNtDfW0IayaGoPaWoiqm6YFCmnR0YY6hjpGYGgIhsY6xrGxCsoKunYK0YZgUSOQmI6JjimIHQvRvGABhAYA)**
- `$*` is a global variable, so calling this lambda multiple times (in a single process) would give wrong result. A 33 bytes version that does not rely on a global state:
- ```ruby
->a{c=Hash.new 0;a.map{c[_1]+=1}}- ```
- If array consists of positive integers from a known range (lets say `0...1e3`, then 30 bytes version is:
- ```ruby
- ->a{b=[0]*1e3;a.map{b[_1]+=1}}
- ```
- # [Ruby](https://www.ruby-lang.org/), 31 bytes
- ```ruby
- ->a{a.map{$*[_1]=1.+$*[_1]||0}}
- ```
- **[Try this online!](https://ato.pxeger.com/run?1=m72kqDSpcsHiNNuYpaUlaboW-3XtEqsT9XITC6pVtKLjDWNtDfW0IayaGoPaWoiqm6YFCmnR0YY6hjpGYGgIhsY6xrGxCsoKunYK0YZgUSOQmI6JjimIHQvRvGABhAYA)**
- `$*` is a global variable, so calling this lambda multiple times (in a single process) would give wrong result. A 33 bytes version that does not rely on a global state:
- ```ruby
- ->a,*c{a.map{c[_1]=1.+c[_1]||0}}
- ```
- If array consists of positive integers from a known range (lets say `0...1e3`, then 30 bytes version is:
- ```ruby
- ->a{b=[0]*1e3;a.map{b[_1]+=1}}
- ```
#4: Post edited
- # [Ruby](https://www.ruby-lang.org/), 31 bytes
- ```ruby
- ->a{a.map{$*[_1]=1.+$*[_1]||0}}
- ```
- **[Try this online!](https://ato.pxeger.com/run?1=m72kqDSpcsHiNNuYpaUlaboW-3XtEqsT9XITC6pVtKLjDWNtDfW0IayaGoPaWoiqm6YFCmnR0YY6hjpGYGgIhsY6xrGxCsoKunYK0YZgUSOQmI6JjimIHQvRvGABhAYA)**
`$*` is a global variable, so you can calling this lambda multiple times (in a single process) would give wrong result. A 33 bytes version that does not rely on a global state:- ```ruby
- ->a{c=Hash.new 0;a.map{c[_1]+=1}}
- ```
- If array consists of positive integers from a known range (lets say `0...1e3`, then 30 bytes version is:
- ```ruby
- ->a{b=[0]*1e3;a.map{b[_1]+=1}}
- ```
- # [Ruby](https://www.ruby-lang.org/), 31 bytes
- ```ruby
- ->a{a.map{$*[_1]=1.+$*[_1]||0}}
- ```
- **[Try this online!](https://ato.pxeger.com/run?1=m72kqDSpcsHiNNuYpaUlaboW-3XtEqsT9XITC6pVtKLjDWNtDfW0IayaGoPaWoiqm6YFCmnR0YY6hjpGYGgIhsY6xrGxCsoKunYK0YZgUSOQmI6JjimIHQvRvGABhAYA)**
- `$*` is a global variable, so calling this lambda multiple times (in a single process) would give wrong result. A 33 bytes version that does not rely on a global state:
- ```ruby
- ->a{c=Hash.new 0;a.map{c[_1]+=1}}
- ```
- If array consists of positive integers from a known range (lets say `0...1e3`, then 30 bytes version is:
- ```ruby
- ->a{b=[0]*1e3;a.map{b[_1]+=1}}
- ```
#3: Post edited
- # [Ruby](https://www.ruby-lang.org/), 31 bytes
- ```ruby
- ->a{a.map{$*[_1]=1.+$*[_1]||0}}
- ```
- **[Try this online!](https://ato.pxeger.com/run?1=m72kqDSpcsHiNNuYpaUlaboW-3XtEqsT9XITC6pVtKLjDWNtDfW0IayaGoPaWoiqm6YFCmnR0YY6hjpGYGgIhsY6xrGxCsoKunYK0YZgUSOQmI6JjimIHQvRvGABhAYA)**
- `$*` is a global variable, so you can calling this lambda multiple times (in a single process) would give wrong result. A 33 bytes version that does not rely on a global state:
- ```ruby
- ->a{c=Hash.new 0;a.map{c[_1]+=1}}
- ```
If array consists of positive integers from a known range (lets say `0..1e3`, then 30 bytes version is:- ```ruby
- ->a{b=[0]*1e3;a.map{b[_1]+=1}}
- ```
- # [Ruby](https://www.ruby-lang.org/), 31 bytes
- ```ruby
- ->a{a.map{$*[_1]=1.+$*[_1]||0}}
- ```
- **[Try this online!](https://ato.pxeger.com/run?1=m72kqDSpcsHiNNuYpaUlaboW-3XtEqsT9XITC6pVtKLjDWNtDfW0IayaGoPaWoiqm6YFCmnR0YY6hjpGYGgIhsY6xrGxCsoKunYK0YZgUSOQmI6JjimIHQvRvGABhAYA)**
- `$*` is a global variable, so you can calling this lambda multiple times (in a single process) would give wrong result. A 33 bytes version that does not rely on a global state:
- ```ruby
- ->a{c=Hash.new 0;a.map{c[_1]+=1}}
- ```
- If array consists of positive integers from a known range (lets say `0...1e3`, then 30 bytes version is:
- ```ruby
- ->a{b=[0]*1e3;a.map{b[_1]+=1}}
- ```
#2: Post edited
- # [Ruby](https://www.ruby-lang.org/), 31 bytes
- ```ruby
- ->a{a.map{$*[_1]=1.+$*[_1]||0}}
- ```
- **[Try this online!](https://ato.pxeger.com/run?1=m72kqDSpcsHiNNuYpaUlaboW-3XtEqsT9XITC6pVtKLjDWNtDfW0IayaGoPaWoiqm6YFCmnR0YY6hjpGYGgIhsY6xrGxCsoKunYK0YZgUSOQmI6JjimIHQvRvGABhAYA)**
`$*` is a global variable, so you can call function only once. A 33 bytes version that does not rely on a global state:- ```ruby
- ->a{c=Hash.new 0;a.map{c[_1]+=1}}
- ```
- If array consists of positive integers from a known range (lets say `0..1e3`, then 30 bytes version is:
- ```ruby
- ->a{b=[0]*1e3;a.map{b[_1]+=1}}
- ```
- # [Ruby](https://www.ruby-lang.org/), 31 bytes
- ```ruby
- ->a{a.map{$*[_1]=1.+$*[_1]||0}}
- ```
- **[Try this online!](https://ato.pxeger.com/run?1=m72kqDSpcsHiNNuYpaUlaboW-3XtEqsT9XITC6pVtKLjDWNtDfW0IayaGoPaWoiqm6YFCmnR0YY6hjpGYGgIhsY6xrGxCsoKunYK0YZgUSOQmI6JjimIHQvRvGABhAYA)**
- `$*` is a global variable, so you can calling this lambda multiple times (in a single process) would give wrong result. A 33 bytes version that does not rely on a global state:
- ```ruby
- ->a{c=Hash.new 0;a.map{c[_1]+=1}}
- ```
- If array consists of positive integers from a known range (lets say `0..1e3`, then 30 bytes version is:
- ```ruby
- ->a{b=[0]*1e3;a.map{b[_1]+=1}}
- ```
#1: Initial revision
# [Ruby](https://www.ruby-lang.org/), 31 bytes ```ruby ->a{a.map{$*[_1]=1.+$*[_1]||0}} ``` **[Try this online!](https://ato.pxeger.com/run?1=m72kqDSpcsHiNNuYpaUlaboW-3XtEqsT9XITC6pVtKLjDWNtDfW0IayaGoPaWoiqm6YFCmnR0YY6hjpGYGgIhsY6xrGxCsoKunYK0YZgUSOQmI6JjimIHQvRvGABhAYA)** `$*` is a global variable, so you can call function only once. A 33 bytes version that does not rely on a global state: ```ruby ->a{c=Hash.new 0;a.map{c[_1]+=1}} ``` If array consists of positive integers from a known range (lets say `0..1e3`, then 30 bytes version is: ```ruby ->a{b=[0]*1e3;a.map{b[_1]+=1}} ```