
See this post at Yahoo Respostas!
p=1.0
for x in range(1,42):
if x == 1:
print " N P(%)"
print " %2d %2.2f%%" % (x,100*(1-p))
p = (365-x)*p/365
N P(%)
1 0.00%
2 0.27%
3 0.82%
4 1.64%
5 2.71%
6 4.05%
7 5.62%
8 7.43%
9 9.46%
10 11.69%
11 14.11%
12 16.70%
13 19.44%
14 22.31%
15 25.29%
16 28.36%
17 31.50%
18 34.69%
19 37.91%
20 41.14%
21 44.37%
22 47.57%
23 50.73%
24 53.83%
25 56.87%
26 59.82%
27 62.69%
28 65.45%
29 68.10%
30 70.63%
31 73.05%
32 75.33%
33 77.50%
34 79.53%
35 81.44%
36 83.22%
37 84.87%
38 86.41%
39 87.82%
40 89.12%
41 90.32%
# This makefile that generate one resouce in paralellal mode.
# the out_file is the target. First, the makefile verify if it
# is running protected, by consulting a PROTECTED variable.
# If not, it will create a lock file, and call itself with
# protected flag on, once it aquired the lock. As it call the
# Makefile again, the rule will be checked if the resource
# has already been created. So, the shared resource between
# process running the makefile will only be created once!
#
MAKEFILE=./Makefile
ifeq ($(PROTECTED),YES)
else
all: out_file
@echo "Makefile $(MAKE_NUM) done!"
endif
out_file: source_file
ifeq ($(PROTECTED),YES)
@echo "Creating out_file"
@rm -f out_file
@sleep 3
@touch out_file
else
@lockfile make.lock
@echo "Enter Critical Section"
@$(MAKE) -f $(MAKEFILE) PROTECTED=YES
@echo "Leave Critical Section"
@rm -f make.lock
endif
#!/usr/bin/env perl
#
use strict;
use charnames ':full';
use utf8;
# First, let's print the source code.
open THIS, $0;
print $_ while (<THIS>);
# Get the vector elements sum. We use the Sigma greek letter.
sub Σ
{
my ($accum) = shift;
foreach(@_)
{
$accum += $_;
}
return $accum;
}
# My Day is done!
# But Gauss would do it better!
# We can see that perl allows any
# Alphabet caracter to be used, but any symbol
# is reserverd. This is the case of integral symbols
# ∫, ∬, ∭, ∮, ∯, ∰, ∳, ∲. and even the Summantion sign ∑
# Note that this is not the greek sigma letter. Perl is smart, hum?
my @Ϯ = 1 .. 100;
my $ΔU = Σ @Ϯ; # Σ is not ∑. (Sigma and summantion sign).
print "The Summation from one to a handred is $ΔU.\n";
# Energy Funcion Ψ.
# It goes from ± a radius around
# the center.
sub Ψ
{
my ($α,$β,$γ) = @_[0..2];
return $α**2 + $β**2 + $γ**2;
}
# My runic letter Gar
my $ᚸ = Ψ(2.3, 234.0, 23.4);
# Listing day in Japanese, from Sunday to Saturday
my @Ա = qw/㈰ ㈪ ㈫ ㈬ ㈭ ㈮ ㈯/;
# A dictionary.
my %Ծ =
(
"㈰" => ["Sun", "Sunday"],
"㈪" => ["Moon", "Monday"],
"㈫ " => ["Fire", "Tuesday"],
"㈬" => ["Water", "Wednesday"],
"㈭" => ["Wood", "Thursday"],
"㈮" => ["Metal", "Friday"],
"㈯" => ["Earth", "Saturday"],
);
# Now, lets print the sign for Astrological sign.
my $signs = join ", ", map { chr(ord("♈") + $_ - 1) } 1..12;
print "This is a list with the signs $signs.\n";
foreach my $Ʃ (@Ա)
{
print "$Ʃ is the Japanese symbol for $Ծ{$Ʃ}->[0] element, also $Ծ{$Ʃ}->[1] week\'s day.\n";
}
/*
* File: heap.c
* Author: cassius
*
* Created on 19 de Novembro de 2006, 22:27
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void print_recursive(char* str, int pos, int length)
{
int k;
char first, current;
if(pos >= (length-1) )
fprintf(stdout, "%s ", str);
else
{
first = str[pos];
for(k = pos; k < length; k++)
{
/* swap chars */
current = str[k];
str[pos] = current;
str[k] = first;
print_recursive(str, pos + 1, length);
/* swap it back. */
str[k] = current;
}
str[pos] = first;
}
}
void print(char* str)
{
int len = strlen(str);
print_recursive(str, 0, len);
fprintf(stdout, ".\n");
}
/*
*
*/
int
main(int argc, char** argv) {
char max_str[100];
fprintf(stdout, "Please, digite a word.\n");
fscanf(stdin, "%s ", max_str);
print(max_str);
fprintf(stdout, "Exiting ...");
return (EXIT_SUCCESS);
}
/*
* File: newmain.c
* Author: cassius
*
* Created on 15 de Novembro de 2006, 13:22
*/
#include <stdio.h>
#include <stdlib.h>
const char ptr[] ="string";
typedef struct
{
const char *c;
int i;
}test_struct;
test_struct s={ptr,10};
/* Only to take control of it */
#define DEFAULT_ARRAY_SIZE 10
#define MAX_ARRAY_PERMITED_SIZE 1024
/*
*
*/
int
main(int argc, char** argv) {
int *array = NULL;
int k = 0;
int length = DEFAULT_ARRAY_SIZE;
int arg_pos = 1;
double n;
/* If you want to force the same resoults, use -seed num to set a seed
to the pseudo random sequence.
*/
while(arg_pos < argc) {
if( (strcmp(argv[arg_pos],"--seed") == 0) && (argc - arg_pos >= 2 ) ) {
int seed;
arg_pos++;
seed = atoi(argv[arg_pos]);
srand(seed);
} else if( (strcmp(argv[arg_pos],"--length") == 0) && (argc - arg_pos >= 2 ) ) {
int user_length;
arg_pos++;
user_length = atoi(argv[arg_pos]);
if( (user_length < 1) || (user_length > MAX_ARRAY_PERMITED_SIZE ) )
fprintf(stdout, "Invalid length. Assuming default value of %d.\n",length);
else
length = user_length;
}
arg_pos++; /* bypass argment name or last args processed */
}
/* Suppouse we use only 100 positons, for now */
array = (int*)malloc(sizeof(int)*length);
if(array == NULL)
{
fprintf(stderr, "No memory could be allocated. Exiting... ");
return (EXIT_FAILURE);
}
for(k = 0; k < length; k++ )
array[k] = k;
/* Now, scramble the array. The process is simple. The k variable points to
the end of the array. We choose randomically between all positions bellow
k. This position must be swapped with k. And the process goes on until
the the start of the array.
Warning: Although */
for(k = (length-1); k > 0;k-- )
{
int temp_int = array[k];
int old_pos = rand() % k;
array[k] = array[old_pos];
array[old_pos] = temp_int;
}
/* Print the array. */
fprintf(stdout, "[");
for(k = 0; k < length; k++)
{
char term = k == (length -1) ? ']' : ',';
fprintf(stdout, "%d%c",array[k],term);
}
fprintf(stdout, "\n");
return (EXIT_SUCCESS);
}