New answers tagged

0

Japt -R, 9 bytes ü ®Î+S+Zl Try it


1

Stax, 5 bytes ═#8¼K Run and debug it


0

Stax (31 bytes) âpWhuÉñ♫∩Ω╝YT>ⁿë╘Æ↨»╧óPÜ≤♪Ñû1♫à Try it online here: https://staxlang.xyz/#p=837057687590a40eefeabc59543efc89d49217afcfa2509af30da596310e85&a=1 It has some limitations. No uppercase letters, and it shows all letters, even if they have zero occurences Unpacked version: 0]6{c+}*,""/{|3b@^&FVw""/{[cp':p|3@PF ^a ^b ^c ^...


0

Julia 1.0, 53 bytes s=readline() Set(s).|>c->println(c,": ",sum(==(c),s)) Try it online!


0

Pip, 48 bytes a:qFi32,128{b:0Fj,#a{a@jQ Ci?++bx}b?P Ci.":".bx} I assume you meant printable ascii Try it online!


0

Oracle SQL, 103 bytes select substr(x,level,1),count(*)from t connect by level<=length(x)group by substr(x,level,1)order by 1 Test in SQL*PLus SQL> set pages 100 SQL> set heading off SQL> with t(x) as (select 'The definition of insanity is quoting the same phrase again and again and not expect despair.' from dual) 2 select substr(x,level,1),...


1

Keg, 3 bytes ?!. Well, I can't golf this program well. TIO


1

JavaScript (Node.js), 64 bytes e=>(d={},e.replace(/\S/g,e=>d[e]=d[e]+1||1),[Object.entries(d)]) Try it online! JavaScript (Node.js), 59 bytes e=>(d={},[...e].map(e=>d[e]=d[e]+1||1),[Object.entries(d)]) Try it online!


0

Add++, 35 bytes D,g,@@#,€=b+": "$J D,f,@,qdA€gBcBJn Try it online! Defines a function f, which takes the input as an argument, and returns the complete formatted string. Explanation D,g, ; Define a helper function, g @@#, ; that takes 2 arguments Stack: ['l' 'Hello World'] €= ; Compare each letter to argument Stack: [[0 ...


0

Python 3, 46 bytes i=input() for c in{*i}:print(c,':',i.count(c)) Try it online!


0

SuperMarioLang, 449 bytes >++++) >^====+ (+++< >,[!^= (< +======" *-< "==#= =" + ) ======" >%+>[!%+ ) >&[! "====# + ) "==#===================== ! <>+++(-[!))+(%> [!! #================#====="==## > (((++*)+*)&+...


0

Perl 5, 254 bytes sub f{@s=map[$_>$_[0]||0,$_>$_[0]?$_[3]:$_[2],1],1..$_[0]+$_[1];while(join('',map$$_[0],@s)=~/01|10/){($c,$p)=&{$_[4]};(@w=sort{$p*($$b[1]<=>$$a[1])}grep$$_[2]&&$$_[0]eq$c,@s)[0][2]=0;@s=grep$$_[2]||++$$_[2]&&--$$_[1],@s if@w<2}sort{$b<=>$a}map$$_[1],@s} Try it online! Ungolfed but same – with ...


0

JavaScript (Node.js), 56 bytes s=>[...s].sort().reduce((a,b)=>(a[b]=(a[b]||0)+1)&&a,{}) Try it online!


1

SNOBOL4 (CSNOBOL4), 135 bytes I =INPUT B I '-o' = :F(A) B =B + 1 :(B) A I '/o' = :F(D) A =A + 1 :(A) D I 'o' = :F(O) D =D + 1 :(D) O OUTPUT =+D ' ' +A ' ' +B END Try it online! Removes -o, /o, and o from the string and increments the appropriate counters each time. Leaves behind a lot of arms and legs (/-\, \, ...


0

SNOBOL4 (CSNOBOL4), 120 bytes A =&ALPHABET I =INPUT S O =0 A LEN(1) . X REM . A :F(END) R I X = :F(O) O =O + 1 :(R) O OUTPUT =GT(O) X 0 O :(S) END Try it online! A =&ALPHABET ;* alias for &ALPHABET (256 characters in ascending order) I =INPUT ;* read input S O =0 &...


0

C (gcc), 99 98 96 bytes -1 byte thanks to ceilingcat o,S,d,c;f(char*s){for(o=S=d=0;c=*s++;o+=c>93)d+=c==45,S+=c==47;printf("%d %d %d",o-S,S-d,d/=2);} Try it online!


3

PHP, 57 bytes foreach(count_chars($argn,1)as$a=>$b)echo chr($a)," $b "; Try it online! Input via STDIN, run with php -F: $ echo Su3OH39IguWH|php -F cc.php 3 2 9 1 H 2 I 1 O 1 S 1 W 1 g 1 u 2 Fun fact: this challenge is basically the Example 1 on the PHP docs for count_chars().


1

Forth (gforth), 134 bytes : f here 128 allot dup 128 erase -rot 0 do 2dup i + c@ + 1 swap +! loop drop 128 0 do dup i + c@ ?dup if i emit ." : ". cr then loop ; Try it online! Limitation: won't work if any character occurs more than 256 times in a single string (to fix this requires an extra ~25 bytes) Explanation Allocate an area of memory 128 bytes (...


1

JavaScript, 55  48  62 57 bytes a=>[...a].sort().map(c=>o.set(c,-~o.get(c)),o=new Map)&&o output is a Map contrary to Objects, Map remember the order in which values where sets let input = document.getElementById("input") let run = document.getElementById("run") let output = document.getElementById("output") run.onclick = () ...


0

05AB1E, 13 bytes …-/oS¢ć;š0š¥R This one could be 12 bytes by removing the R if an output-order of [bodybuilder, acrobat, dwarf] would have been allowed. Try it online or verify all test cases. Minor equal-bytes alternative: …-/oS¢R`;0)üα Try it online or verify all test cases. Explanation: …-/o # Push string "-/o" S # Split to ...


1

R (in C locale), 32 bytes function(s)table(strsplit(s,'')) Try it online! strsplit the input character string by the empty string to separate its characters then table builds a contingency table of the unique character counts.


1

05AB1E, 8 6 bytes SêDŠ¢ø Try it online!


1

Kotlin, 53 bytes Returns a Map<Char, Int> associating characters to frequencies. The map keys are sorted in ASCII order (it's a java.util.SortedMap underneath.) {s->s.associateWith{c->s.count{it==c}}.toSortedMap()} Try it online!


2

APL(NARS), 26 chars, 52 bytes {m,¨+/¨{w=⍵}¨m←k[⍋k←∪w←⍵]} test: ⎕fmt{m,¨+/¨{w=⍵}¨m←k[⍋k←∪w←⍵]}'is, this good or not?' ┌12─────────────────────────────────────────────────────────────────────────────────┐ │┌2───┐ ┌2───┐ ┌2───┐ ┌2───┐ ┌2───┐ ┌2───┐ ┌2───┐ ┌2───┐ ┌2───┐ ┌2───┐ ┌2───┐ ┌2───┐│ ││ 4│ │ , 1│ │ ? 1│ │ d 1│ │ g 1│ │ h 1│ │ i 2│ │ n 1│ │ o 4│ │ ...


0

C++ (gcc), 85 bytes #include<map> auto f(std::string s){std::map<char,int>m;for(int c:s)m[c]++;return m;} Try it online! This solution makes use of several nice features of std::map: It has a sorted iterator, with default lexicographic ordering. The []-operator default initializes members, in case of int it zeroes it. Also, C++17 allows for ...


8

Python 3, 41 bytes lambda s:sorted({*zip(s,map(s.count,s))}) Try it online!


2

brainfuck, 128 114 bytes ->>,[[-[>>+<<-]>>]>+<+[-<<+]->>,]+[+>[<--.++<<+++++++[>++++++++<-]>++.[-]++++++[>>++++++++<<-]>>.[-].]<[>>+<<-]>>] Try it online! How it works: - sets cell 0 to 255, which is used to move ...


1

Ruby -n, 43 bytes p$_.chars.uniq.sort.map{|c|[c,$_.count(c)]} Try it online!


3

C (gcc), 94 91 bytes Thanks to Ourous and ceilingcat for their suggestions. To get the non-newline separator, I'm making use of the fact that negative numbers get a "-" for free! :-) f(char*s){char c[255]={},i=31;for(;*s;)c[*s++]--;for(;++i>0;)c[i]&&printf("%c%d ",i,c[i]);} Try it online!


2

K4, 9 bytes Solution: #:'=x@<x: Example: q)k)#:'=x@<x:"Over 9001!" | 1 !| 1 0| 2 1| 1 9| 1 O| 1 e| 1 r| 1 v| 1 Explanation: #:'=x@<x: / the solution x: / store input as x < / indices to sort ascending x@ / apply (@) to x = / group same values #:' / count (#:) each (')


1

Haskell, 46 bytes f x=[(c,sum[1|d<-x,d==c])|c<-[' '..],elem c x] Try it online!


1

Japt, 7 bytes ¬ü ®âZl Test it online!


0

Scala, 64 62 bytes (x:String)=>x.groupBy(identity).mapValues(_.size).toSeq.sorted


1

Java (JDK), 82 bytes s->s.stream().sorted().distinct().map(c->c+" "+s.stream().filter(x->c==x).count()) Try it online!


1

Kotlin, 75 bytes fun String.c()=toCharArray().sorted().map{Pair(it,count{s->it==s})}.toSet() Try it online!


3

PowerShell, 27 22 21 19 bytes $args[0]|sort|group Try it online! Exactly what it says on the tin. Takes input $args[0] via splatting (manifests on TIO as a [char[]]), sorts it, then group-object it into a grouping. -8 bytes thanks to mazzy


9

Ohm v2, 2 bytes SÖ Try it online! implicit input S sort string Ö run-length encoding implicitly print


0

Perl 5 (-nF -M5.01 -MList::Util=uniq), 49 41 bytes 41 bytes : for$a(uniq sort@F){say"$a ",eval"y/$a//"} doesn't work if input contains a slash. Otherwise, 36 bytes : for$a(uniq sort@F){say"$a "./\Q$a/g} doesn't work because of //g in scalar context. for$a(uniq sort@F){say"$a ".(()=/\Q$a/g)} TIO first answer


1

Japt, 10 8 bytes ü mÎíUmÊ Try it ü\nmÎíUmÊ :Implicit input of string U ü :Split, sort and partition by value \n :Reassign to U m :Map Î : First element í :Interleave with UmÊ : Map lengths of U


7

Brachylog, 2 bytes ọo Try it online! ọ Occurrences, o sorted. It's essentially the same as using an RLE builtin with the sorting requirement, but if the output could be in any order it would just be ọ.


1

Charcoal, 13 bytes EΦγ№θι⁺⁺ι №θι Try it online! Link is to verbose version of code. Explanation: γ Printable ASCII Φ Filtered where non-zero № Count of ι Current character in θ Input string E Map over filtered characters ι Current character ⁺ ...


4

T-SQL 2008 query, 130 bytes DECLARE @ varchar(2000)='kabcdda' SELECT w,sum(1)FROM(SELECT substring(@,number+1,1)FROM spt_values WHERE type='P'and number<len(@))x(w)GROUP BY w ORDER BY ascii(w) Try it online


4

Pyth, 3 bytes r8S Try it online! Simply run-length encodes (r8) the sorted (S) input. Output is a list of tuples of [frequency, character].


1

JavaScript, 57 bytes Outputs a 2D-Array. Had to implement a quick & dirty fix for the sorting so I'll need to come back to try to golf that. s=>[...s].map(o=x=>o[x]=-~o[x])&&Object.entries(o).sort() Try It Online!


3

JavaScript, 58 bytes s=>[...s].sort().flatMap(c=>c>p?[p=[c,1]]:p[1]++&&[],p=[]) Try it online! Thanks Shaggy, -1 byte. Retina, 18 bytes O`. (.)\1* $1,$.&¶ Try it online! I don't speak Retina. I just translated above JavaScript answer to Retina with some searching. Thanks to Cows quack, -3 bytes.


4

Jelly, 6 3 bytes ṢŒr Try it online! A monadic link taking the string as its argument. Returns a list of lists, each one containing the character and count. The footer formats this as a grid.


2

C# (Visual C# Interactive Compiler), 63 61 bytes s=>s.OrderBy(c=>c).GroupBy(c=>c).Select(g=>(g.Key,g.Count())) Try it online! Thanks to Expired Data for pointing me towards the C# Interactive Compiler and for showing me the power of dynamics.


4

Bash, 27 22 20 bytes fold -1|sort|uniq -c Try it online! -5 bytes thanks to Neil -2 bytes thanks to Digital Trauma


0

Red, 92 bytes func[s][parse/case sort/case s[any[copy k[copy t skip thru any t](print[t length? to""k])]]] Try it online!


5

CJam, 8 4 bytes $e`p Try it online! -3 bytes thanks to Jonah, and -1 byte from rule interpretation. A perfect challenge for CJam. I had hoped that the RLE encode operator would output [char, count], but the order was reversed. Otherwise it would have been a 5-byter. After Jonah's comment, I switched the order of the output. I'm not sure if the first ...


Top 50 recent answers are included