Search
C (gcc), 43 38 bytes f(i){return i>1?f(i%2?3*i+1:i/2)+1:0;} Attempt This Online! Credits to @Moshi for shortening the code.
Lundin just suggested in a comment under another question that I tag the challenge Looping Counter as kolmogorov-complexity. Now I'm not sure if it actually qualifies for that tag, for the followi...
Wolfram Language (Mathematica), 38 bytes Tr[1^ResourceFunction["Collatz"]@#]-1& Don't Try it online! Doesn't work on TIO due to using the Collatz builtin which needs to be downloaded from ...
C (gcc), 48 43 bytes s;r(n,m){s+=rand()%m+1;return--n?r(n,m):s;} Try it online! Previous 48 bytes version using loop: i,s;r(n,m){for(;i<n;i++)s+=rand()%m+1;return s;}
Python 3, 59 bytes lambda n,m:sum(choices(range(m),k=n))+n from random import* Try it online!
Zsh, 61 bytes n=2;s=s=%q\;printf\ n=\$n\$n\\\;\$s\ \$s;printf n=$n$n\;$s $s Attempt This Online! A trivial modification of this quine: s=s=%q\;printf\ \$s\ \$s;printf $s $s. n goes from 2 to 22 ...
J, 35 char <:#-:`(>:@:*&3)@.(2&|)^:(1&<)^:(<_) How it works: NB. <: subtract one from number result on right NB. # count number of items from list result on righ...
J, 13 char '*',^:(<_)'*' How it works: What's in parenthesis indicates to the verb ^: that the verb to the left of ^: has to be performed to the object on the right of the ^: an infinite nu...
J, 7 char *./~:q: How it works: 'q:' produces prime factors of number on right '~:' replaces the first instance of unique numbers with a 1, the rest 0 '*./' tests for all ones Sample runs: ...
Python 3, 38 36 33 bytes lambda x:{n:x.count(n)for n in x} -2 bytes thanks to @Razetime Another -3 bytes thanks to @orthoplex Attempt it online!
J, 8 bytes ~.,:#/.~ Tacit function, this is the de facto method for this problem in J. Attempt it online!
Myby, 12 5 bytes primf=primfd primf : prime factors = : equals primfd : unique prime factors Evaluated as a monadic fork in J (f y) g (h y). The test cases (retest...
Factor, 95 bytes USING: kernel ranges sequences ; IN: r : r ( n q -- n ) [ [1..b] [ ] ] dip map-reduce ; inline
Factor, 147 bytes USING: kernel math math.text.utils sequences ; IN: n : n ( n -- s ) 0 swap [ [ 1 + dup dup 1 digit-groups sum mod 0 > ] loop dup ] replicate nip ;
Factor, 46 bytes USE: math.statistics IN: h ALIAS: h histogram
Ruby, 56 bytes p *(1..).lazy.filter{_1%_1.digits.sum<1}.take(gets.to_i) Attempt This Online!
Sidef, 25 bytes {eval .split.join(" * ")} {eval .split.join(" * ")} { } # Create anonymous code block .split.join(" * ") # splits on whitespace and joins with "...
x86-64 machine code, 36 bytes 31 C0 8D 48 0A FF C0 50 99 89 17 48 F7 F1 01 17 99 85 C0 75 F6 58 50 F7 37 58 85 D2 75 E7 AB FF CE 75 E2 C3 Try it online! Following the standard calling conventi...
Python 3, 63 bytes print(str(eval(f"({input().replace(' ',')*(')})")).strip("()")) Try it online! Similar to hyper-neutrino's answer. Doesn't replace i by j and back, and uses f-string instea...
JavaScript, 25 bytes Could be 21 but calling the function like that feels like cheating. (f=s=>f(s+=8,print(s)))`` Try it online! 22 bytes Didn't want to post this as my main solution a...
Japt, 6 bytes ßOpP±Q Test it ßOpP±Q ß :Recursive call Op :Output with trailing newline P :Empty string, initially ± :Append Q :Quotation mark