memowe
  • Member for 9 years, 6 months
  • Last seen more than a month ago
66 answers
50 votes
11k views
Divide a number by 3 without using *, /, +, -, % operators
7 votes

Perl (26 22) $_=3x pop;say s|333||g This version (ab)uses Perl's regex engine. It reads a number as the last command line argument (pop) and builds a string of 3s of this length ("3" x $number). The ...

View answer
98 answers
90 votes
20k views
When does (x == x+2)?
7 votes

Perl using a subroutine with side-effects on a package variable: sub x () { $v -= 2 } print "true!\n" if x == x + 2; Output: true!

View answer
26 answers
44 votes
7k views
Crash your favorite compiler
6 votes

Perl (15) BEGIN{1while 1} This creates an infinite loop at compile time: A BEGIN code block is executed as soon as possible, that is, the moment it is completely defined, even before the rest of ...

View answer
16 answers
14 votes
930 views
Rectangle of text
5 votes

Perl (124 118 109+3=112) This formerly was pretty straightforward. Counted all command line options as 1 character each. -nlE $w=(@s=split//)/2-($h=int@s/4);say@s[0..$w--];say$s[1-$_].$"x$w.$s[$w+$_]...

View answer
12 answers
11 votes
8k views
Find random images from http://i.imgur.com/
4 votes

Perl (93 + 4 = 97) Using imgur's own random mechanism to get their image URLs, which aren't png URLs most of the time: $ perl -Mojo -E 'say+g("http://imgur.com/gallery/random")->dom->at("[rel=...

View answer
7 answers
-2 votes
1k views
Swap 2 objects, without using a temporary variable
1 votes

Perl ($object1, $object2) = ($object2, $object1); Using Perl's list assertions feels like cheating, but it's a pretty common feature.

View answer
15 answers
5 votes
574 views
Create a hash from an array of arrays of key|value pairs
1 votes

There's more than one way to do it (Perl) Preparation: $input = [["A", 5], ["B", 2], ["A", 12], ["B", -2], ["C", 7]]; I have three Perl snippets to solve the problem because the obvious code is ...

View answer
38 answers
20 votes
4k views
'Add' up the letters in a word
0 votes

Perl (42 31) perl -F -pale '$c+=ord(uc$_)-64for@F;$_=$c' I hope counting F, p, a and l as 1 character was correct.

View answer
21 answers
8 votes
6k views
print 1 to 100 without using recursion and conditions
0 votes

Perl (65) Here's a non-trivial Perl approach (not like say for 1 .. 100). The program uses perl's regular expression engine to count its own characters (two times), and that's the reason why I couldn'...

View answer
33 answers
31 votes
5k views
Render "Digital Clock Style" Numbers
0 votes

Perl (182 180) #!perl -l $_=<<7; _ _ _ _ _ _ _ _ | | | _| _||_||_ |_ ||_||_| |_| ||_ _| | _||_| ||_| _| 7 @b=map{[/(...)/g]}split/\n/;@d=split//,<>;for$p(@b){print ...

View answer
65 answers
31 votes
6k views
Determine if a number is divisible by 13 (without using 13 itself)
0 votes

Perl, score: 25.6 24.8 OK, my program abuses perl's regex engine. It's a little bit obfuscated to look funnier. say+(q x x x <>)=~m ?^(\?: )+$??"yes":"no" A shorter and "more ...

View answer
30 answers
16 votes
7k views
Calculate pi to 5 decimals
0 votes

Perl (76 chars) $y=1e4;for$x(0..1e4-1){$y--while sqrt($x**2+$y**2)>1e4;$a+=$y}print 4*$a/1e8 (Result: 3.14159052) Not the shortest possible solution, but maybe interesting. It's a geometrical ...

View answer