Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 121

Challenges related to elementary arithmetic.

6 votes

The Luhn algorithm for verifying credit card numbers, etc

D, 144 bytes bool f(S)(S s){int t(C)(C c){return to!int(c)-'0';}int n,v;foreach(i,c;array(retro(s))){v=i&1?t(c)*2:t(c);n+=v>=10?v%10+v/10:v;}return n%10==0;} More legibly: bool f(S)(S s) { int t( …
Jonathan M Davis's user avatar
4 votes

Find the Factorial!

D: 45 Characters T f(T)(T n){return n < 2 ? 1 : n * f(n - 1);} More legibly: T f(T)(T n) { return n < 2 ? 1 : n * f(n - 1); } A cooler (though longer version) is the templatized one which do …
Jonathan M Davis's user avatar