Mister Zimbu said:Bah, that's an easy one. Try regex'ing out c-style comments.
"/*"([^*]|"*"+[^/*])*"*"+"/"
($@,$?)=(@ARGV,9,9);
$: = 1 - $? * $@;
print "# ", '##' x ($@-2), "# #\n";
$_[0][$_] = $_[$? + 1][$_] = 8 for (0 .. $@);
$_[$_][0] = $_[$_][$@ + 1] = 8 for (0 .. $?);
$/ = 1 + rand $?;
$. = 1 + rand $@;
@@ = [$., $/];
$_[$/][$.] = $^ = 4;
while ($:) {
$" = ($^-- > 3) ? rand 4
: ++$" % 4;
(1 > $") ? $.--
: ((2 > $") ? $/--
: (2 ^ $") ? ++$/
: $.++);
if ($_[$/][$.] && 1) {
pop @@, $^ = 4 if (!$^);
($., $/) = @{ $@[-1] };
next;
}
$_[$/][$.] = $^ = 4;
($" < 2) ? $_[$/][$.] |= 1 << $"
: ($_[$@[-1][1]][$@[-1][0]] |= 1 << $" - 2);
push @@, [$., $/];
++$:
}
print "#", map( { ($_ % 2) ? ' '
: ' #'
} @$_[1..$@]),
"\n#",
map( { (2 & $_) ? ' #'
: '##'
} @$_[1..$@]),
"\n" for (@_[1 .. $?]);
Exactly what I was thinking.nubbe said:haha
It's a programming language based on Asian smiles
hahahahaahahahhahhahahanubbe said:haha
It's a programming language based on Asian smiles
* factor an arbitrarily large positive integer
*
* Copyright (C) 1999 by Brian Raiter
* under the GNU General Public License
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>-
<<<<<<<<<+
[-[>>>>>>>>>>][-]<<<<<<<<<<[[->>>>>>>>>>+<<<<<<<<<<]<<<<<<<<<<]
>>>>>>>>>>,----------]
>>>>>>>>>>[------------------------------------->>>>>>>>>->]
<[+>[>>>>>>>>>+>]<-<<<<<<<<<<]-
[>++++++++++++++++++++++++++++++++++++++++++++++++.
------------------------------------------------<<<<<<<<<<<]
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.
--------------------------.[-]
>>>>>>>>>>>>++<<<<+
[ [-]>>
[>>>>[-]>[-]>[-]>[-]
>[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+<<<<<
[->>>>>+<<<<<[->>>>>--------->>>>>+<<<<<<<<<<
[->>>>>+<<<<<]]]]]]]]]]]>>>>>>>>]
<<<<<<<<<<[>>>>>>>[-<<<<<+>>>>>]<<<<<<<<<<<<<<<<<]
>>>>>>>>>
]<
]>>
[>>>>>>>>>>]<<<<<<<<<<[+>[>>>>>>>>>+>]<-<<<<<<<<<<]-
[>++++++++++++++++++++++++++++++++++++++++++++++++.<<<<<<<<<<<]
++++++++++.
What is Whitespace?
Most modern programming languages do not consider white space characters (spaces, tabs and newlines) syntax, ignoring them, as if they weren't there. We consider this to be a gross injustice to these perfectly friendly members of the character set. Should they be ignored, just because they are invisible? Whitespace is a language that seeks to redress the balance. Any non whitespace characters are ignored; only spaces, tabs and newlines are considered syntax.
What are the advantages of Whitespace?
Some things which are difficult in other languages are made much easier in Whitespace. For example, literate programming is simply a matter of writing your helpful comments in between program instructions. It's also easy to encrypt your programs. Simply write a misleading comment!
Whitespace is a particularly useful language for spies. Imagine you have a top secret program that you don't want anyone to see. What do you do? Simply print it out and delete the file, ready to type in at a later date. Nobody will know that your blank piece of paper is actually vital computer code!
What does a typical Whitespace program look like?
Below is an extract from a program which asks for a name then outputs it (see here for the full script.
Towers of Hanoi solver.
A polynomial in x of at most degree 2 is given by ax^2 + bx + c
Write a Java program that reads in values of a, b, and c and finds the roots of the polynomial
ax^2 + bx + c
The roots are real or complex numbers that solve the equation
ax^2 + bx + c = 0
When both a = 0 and b = 0, we consider the case "extremely degenerate" and leave it at that. When a = 0 and b != 0, we consider the case "degenerate." In this case the equation reduces to bx + c = 0 and has one root given by
x = - c/b. When a != 0 (the general case), the roots are given by
root1 = (1/2a) (-b + (b^2 - 4 a c)^1/2)
root1 = (1/2a) (-b - (b^2 - 4 a c)^1/2)
the expression under the square root sign is the discriminant. If the disc. is postive, then two real roots exist. If the disc. is zero, then the two roots are real and equal. In the case we say that the polynomial has multiple roots. If the disc. is negative, then the roots are complex. For each set of values, a, b, and c, your program should print the computed root (s) along with one of the following messages:
degenerate
extremely degenerate
multiple real roots
two real roots
two complex roots
For example, if the values 1, 2, and 3 are read in for a, b, and c, respectively, then
Two complex roots: root1 = -1.00 + i * 1.41
root2 = -1.00 - i * 1.41
Should be printed.
Ferrio said:Switch statements aren't used very much. Good use for them is menuing systems.
import javax.swing.*;
public class PolynomialRoots {
public static void main(String[] args) {
// declare variables
String a_input;
String b_input;
String c_input;
double a;
double b;
double c;
double root1;
double root2;
// use JOptionPane object for input and then converting the strings to doubles
String a_input = JOptionPane.showInputDialog(null, "Enter the value of a", "Project 7" , JOptionPane.QUESTION_MESSAGE);
a = Double.parseDouble(a_input);
String b_input = JOptionPane.showInputDialog(null, "Enter the value of b", "Project 7" , JOptionPane.QUESTION_MESSAGE);
b = Double.parseDouble(b_input);
String c_input = JOptionPane.showInputDialog(null, "Enter the value of c", "Project 7" , JOptionPane.QUESTION_MESSAGE);
c = Double.parseDouble(c_input);
// using the control statement if.. else to determine if there are any roots, and if so what type
if ( a == 0 && b == 0 )
System.out.println("Case is Extremely Degenerate");
else
{
if ( a == 0 && b != 0 ) {
root1 = - c/b;
System.out.printlin("There is only one root in this degenerate case, and it is:" + root1); }
else
{
[b] if ( ( b^2 - 4 a c ) > 0 ) { [/b]
root1 = (1/2a) (-b + (b^2 - 4 a c)^1/2);
root2 = (1/2a) (-b - (b^2 - 4 a c)^1/2);
System.out.println("Two real roots:" + "root1:" root1 + "root2:" + root2); }
else
{
if ( ( b^2 - 4 a c) == 0) {
root1 = (1/2a) (-b + (b^2 - 4 a c)^1/2);
root2 = (1/2a) (-b - (b^2 - 4 a c)^1/2);
System.out.prinln("multiple real roots:" + "root1:" + root1 + "root2:" + root2);
}
else
{
if ( ( b^2 - 4 a c) < 0) {
root1 = (1/2a) (-b + (b^2 - 4 a c)^1/2);
root2 = (1/2a) (-b - (b^2 - 4 a c)^1/2);
System.out.println("Two complex roots:" + "root 1:" + root1 + "root2:" + root2);
}
}
}
// exiting and ending the program
[b]System.exit(0);[/b]
}
}
}
}
Chrono said:if ( ( b^2 - 4 a c ) > 0 )
if ((b^2 - 4 * a * c) > 0)
Chrono said:(1/2a) (-b + (b^2 - 4 a c)^1/2)
iapetus said:There is no good use for switch statements.
#!/usr/bin/perl
# 472-byte qrpff, Keith Winstein and Marc Horowitz <[email protected]>
# MPEG 2 PS VOB file -> descrambled output on stdout.
# usage: perl -I <k1>:<k2>:<k3>:<k4>:<k5> qrpff
# where k1..k5 are the title key bytes in least to most-significant order
s''$/=\2048;while(<>){G=29;R=142;if((@a=unqT="C*",_)[20]&48){D=89;_=unqb24,qT,@b=map{ordqB8,unqb8,qT,_^$a[--D]}@INC;s/...$/1$&/;Q=unqV,qb25,_;H=73;O=$b[4]<<9|256|$b[3];Q=Q>>8^(P=(E=255)&(Q>>12^Q>>4^Q/8^Q))<<17,O=O>>8^(E&(F=(S=O>>14&7^O)^S*8^S<<6))<<9,_=(map{U=_%16orE^=R^=110&(S=(unqT,"\xb\ntd\xbz\x14d")[_/16%8]);E^=(72,@z=(64,72,G^=12*(U-2?0:S&17)),H^=_%64?12:0,@z)[_%8]}(16..271))[_]^((D>>=8)+=P+(~F&E))for@a[128..$#a]}print+qT,@a}';s/[D-HO-U_]/\$$&/g;s/q/pack+/g;eval
CrunchyB said:A switch is evaluated only once, I'd image it could be more efficient than many sequential if statements.
Koshiro said:Perl is being phased out anyway (on the net at least)