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 386

Challenges related to elementary arithmetic.

5 votes

The Luhn algorithm for verifying credit card numbers, etc

PowerShell 123 filter L($x){$l=$x.Length-1;$l..0|%{$d=$x[$_]-48;if($_%2-eq$l%2){$s+=$d}elseif($d-le4){$s+=$d*2}else{$s+=$d*2-9}};!($s%10)}
Ty Auvil's user avatar
  • 483
4 votes

Find the Factorial!

PowerShell, 42 bytes (saved 2 chars using filter instead of function) filter f($x){if(!$x){1}else{$x*(f($x-1))}} Output: PS C:\> f 0 1 PS C:\> f 5 120 PS C:\> f 1 1 PS C:\> f 125 1.88267717688893E+20 …
Ty Auvil's user avatar
  • 483