Quantcast
Channel: How many times should I press this? - Code Golf Stack Exchange
Browsing latest articles
Browse All 22 View Live

Answer by Kenzie for How many times should I press this?

Pip, 100 90 bytesa:qb:["abc""def""ghi""jkl""mno""pqrs""tuv""wxyz"s]Fc,#a{Fd,#b{e:((bd)@?(ac))e<4?i+:e+1x}}iCheck each character of the input for a match in each element of b. The index of that match...

View Article



Answer by Adám for How many times should I press this?

APL (Dyalog), 36 bytes{+/(3×⍵∊'sz'),1+3|¯1+⍵⍳⍨819⌶⎕A~'SZ'}Try it online!Finds the mod-3 indices in the alphabet without S and Z. Since space, S, and Z are not found, they "have" index 25 (one more than...

View Article

Answer by Keyu Gan for How many times should I press this?

C (gcc), 75 77 bytesn,b;f(char*a){for(n=0;b=*a++;)n+=b<'s'?--b%3+(b>31):""[b-'s'];a=n;}The unprintable string "" is a table of 04 01 02 03 01 02 03 04.Try it online!

View Article

Answer by Ray for How many times should I press this?

C, 92 88 bytesc,n;f(char*s){n=0;while(c=*s++)n+=(c=='s')+3*(c>'y')+1+(c+1+(c<'s'))%3-(c<33);return n;}

View Article

Answer by Arnauld for How many times should I press this?

Python 3, 60 bytesProbably sub-optimal, as this is my first golf ever in Python.lambda x:sum((ord(i)-8)%3.15//1+3*(i>'y')+(i>'')for i in x)Try it online!

View Article


Answer by Adam Mendenhall for How many times should I press this?

Java, 95 73 bytesa->a.chars().map(b->1+(b<64?0:b+(Math.abs(b-115)<4?4:5))%(3+b/112)).sum()Thanks to Kevin Cruijssen for making the function a lambda expression (where a is of type String)....

View Article

Answer by Henry for How many times should I press this?

Haskell - 7471 62 bytesEdit: removed 3 bytes by using a list comprehension instead of filterEdit: Save 9 bytes thanks to Siracusa, Laikoni and Zgarb!f=sum.(>>=...

View Article

Answer by marcosm for How many times should I press this?

Bash, 69 68 bytesbc<<<`fold -1|tr "\n "adgjmptwbehknquxcfilorvysz +[1*9][2*8][3*8]44`Try it online!Folds one char per line, transliterates each newline with +, each space with 1 and each...

View Article


Answer by steenbergh for How many times should I press this?

QBIC, 94 bytes[_l;||_SA,a,1|p=p-(instr(@sz`,B)>0)-(instr(@cfilorvy`+C,B)>0)-(instr(@behknqux`+C+D,B)>0)+1}?pExplanation[ | FOR a = 1 TO _l | the length of ; the input string (A$)_SA,a,1| Take...

View Article


Answer by dbuchmann for How many times should I press this?

C, 211 196 bytesFirst submission here...looks quite lengthy and I see that this is not an efficient approach, but at least it works :)f(char*n){char*k=" abcdefghijklmnopqrstuvwxyz";int...

View Article

Answer by Neil for How many times should I press this?

JavaScript (ES6), 71 bytesf=s=>[...s].map(c=>t+=((c=parseInt(0+c,36))>23?c+3:c&&~-c%3)%7%4+1,t=0)|t<input oninput=o.textContent=f(this.value)><pre id=o>Look no letter...

View Article

Answer by ovs for How many times should I press this?

Python 2, 56 bytesUses the same algorithm as @RickHitchcock's Javascript solutionlambda x:sum('behknquxcfilorvysz'.find(c)/8+2for c in x)Try it online!

View Article

Answer by ZaMoC for How many times should I press this?

Mathematica, 83 bytesc=Characters;Tr[Tr@Mod[c@"bc1def1ghi1jkl1mno1pqrstuv1wxyz "~Position~#,4]+1&/@c@#]&

View Article


Answer by Martin Ender for How many times should I press this?

Retina, 46 36 bytesThanks to CalculatorFeline for saving 6 bytes.s|z,c[cfilorvy],b[behknqux],,.Try it online!

View Article

Answer by NikoNyrh for How many times should I press this?

Clojure, 82 76 bytes#(apply +(for[c %](+(count(filter #{c}"bcceffhiikllnooqrrsssuvvxyyzzz"))1)))Oh it is simpler to just filter and count than use frequencies. Original:#(apply +(count %)(for[c...

View Article


Answer by Leaky Nun for How many times should I press this?

Python 3, 696765 64 bytes1 byte thanks to Mr. Xcoder.1 byte thanks to Felipe Nardi Batista.lambda x:sum((ord(i)+~(i>"s"))%3+3*(i in"sz")+(i>"")for i in x)Try it online!

View Article

Answer by Emigna for How many times should I press this?

05AB1E, 2926 25 bytesð¢svA•22ā₂•S£ð«øðδKy.åƶOOTry it online!Explanationð¢ # count spaces in input sv # for each char y in input A # push the lowercase alphabet•22ā₂•S # push the base-10 digit list...

View Article


Answer by Uriel for How many times should I press this?

Dyalog APL, 37 bytes+/⌈9÷⍨'adgjmptw behknqux~cfilorvy~'⍳⍞Try it online!How?Get the ⍳ndex of every char of the input in the string 'adgjmptw behknqux~cfilorvy~' (s and z will default to 28), divide by...

View Article

Answer by 0xffcourse for How many times should I press this?

Python 3, 91 byteslambda x:sum(j.find(i)+1for j in' !abc!def!ghi!jkl!mno!pqrs!tuv!wxyz'.split('!')for i in x)Try it online!

View Article

Answer by Erik the Outgolfer for How many times should I press this?

Jelly, 25 bytesØaḟ⁾sz©;⁶s3Z®ṭċ@€€⁸×"J$ẎSTry it online!

View Article

Answer by Rick Hitchcock for How many times should I press this?

JavaScript (ES6) 776664 60 bytes(Saved some bytes thanks to @Johan Karlsson and...

View Article


Image may be NSFW.
Clik here to view.

How many times should I press this?

We are all used to the old-school telephone keypad, right? For reference, here is what it looks like:Given a String consisting only of lowercase ASCII letters and single spaces, your task is to return...

View Article

Browsing latest articles
Browse All 22 View Live




Latest Images