Name: Anonymous 2013-10-20 22:56
Post a random function that you made. May be from any project you've done or make one impromptu.
Any QUALITY is allowed. No bullying!
Any QUALITY is allowed. No bullying!
#include <stdio.h>
#include <math.h>
int main()
{
unsigned long long int i, factor, number = 600851475143;
for (i = 1; i < number; i++) {
/* The largest factors are equal to the number divided
by the smallest factors. Then just test those large factors
for primality. */
if (isprime(factor = (number / i)) && number % i == 0)
break;
}
printf("%Ld", factor);
}
int >>15
isprime(long long int n)
{
long long int i, sqrt_n;
if (n == 2)
return 1;
/* If even number */
if ((n % 2 == 0) || n <= 1)
return 0;
sqrt_n = sqrt(n);
/* Skip every 2nd number to avoid even numbers
to reduce the number of loops */
for (i = 3; i <= sqrt_n; i += 2) {
if (n % i == 0)
return 0;
}
return 1;
}
alpha = "abcdefghijklmnopqrstuvwxyz";
rnonce = ceil(rand(1) * 10) + 5;
nonce = ceil(rand(1,rnonce) * 26);
nonce = nonce(nonce != key(3));
rnonce = length(nonce);
key = [1,2,3];
inpstr = "CAPSTEST";
outpstr = '';
lastinp = 0;
for(i=1:rnonce)
lastinp = mod(lastinp + nonce(i) - 1, 26) +1;
outpstr(i) = alpha( mod(lastinp + key(mod(i, 3)+1)-1, 26) +1 );
endfor;
lastinp = mod(lastinp + key(3) - 1, 26) +1;
outpstr(i) = alpha( mod(lastinp + key(mod(i, 3)+1)-1, 26) +1 );
for(j=1:length(inpstr))
val = 0;
for(iter = 1:length(alpha))
val = val + (inpstr(j) == alpha(iter)) * iter;
endfor;
lastinp = mod(lastinp + val - 1, 26) +1;
outpstr(j+i) = alpha( mod(lastinp + nonce(mod(i, rnonce)+1)-1, 26) +1 );
if(inpstr(j) == ' ')
outpstr(j+i) = ' ';
endif;
endfor;
outpstr
int con_initialize_f(FILE * ifp){
int i_width, i_height;
int c = EOF;
int i, j;
size_t m = 0;
if (fscanf(ifp, " %d x %d ", &i_width, &i_height) != 2)
return E_MALFORMED_INPUT;
if (i_width <= 0 || i_height <= 0)
return E_MALFORMED_INPUT;
g_width = i_width;
g_height = i_height;
alive_stat = calloc(g_width * g_height, sizeof(*alive_stat));
nigh_count = calloc(g_width * g_height, sizeof(*nigh_count));
freeze_alive_stat = malloc(g_width * g_height * sizeof(*alive_stat));
freeze_nigh_count = malloc(g_width * g_height * sizeof(*nigh_count));
for (j = 0; j < g_height; ++j) {
for (i = 0; i < g_width; ++i) {
do {
c = fgetc(ifp);
} while (c != ' ' && c != '.' && c != EOF);
if (c == EOF)
return E_MALFORMED_INPUT;
else if (c == '.') {
alive_stat[m] = 1;
n_add(i, j, 1);
}
m++;
}
}
return 0;
}
matrix =
[1 2 3
4 5 6
7 8 9]
>> matrix[1] == [1 2 3]
True
>> matrix[1] == [1 2 3]
(always add 50 newlines between lines of code and results)
Error: I am a piece of shit[i]![/i]
>> matrix(1) == [1 2 3]
Error: I am a piece of shit[i]![/i]
>> matrix(1)(:) == [1 2 3]
1.
[]
instead of ()
for function calls.
mat = [1,2,3; 4,5,6; 7,8,9];
mat(1,:) == [1,2,3]
[1, 1, 1] %'(logical type)
[1,2,3; 4,5,6; 7,8,9]
) is less cumbersome than typing [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
, but that syntax is not stopping Matshit developers from representing the matrix internally as a list of lists.
void EncodeMessage()
{
key.assign(StrToBin(key));
message.assign(StrToBin(message));
for(unsigned int x = 0; x < message.size()/7; x++)
{
std::vector<bool> a;
for(int y = 0; y < 7; y++)
{
a.push_back(XOR((int)(message[7*x+y]-48), (int)(key[(7*x+y)%key.size()]-48)));
}
encoded.push_back(a);
}
}
//Attempts to find the sole "root" symbol of this grammar
bool findstartsym() {
set<int> lside, rside;
vector<rule*>::const_iterator i;
for (i = rtable.begin(); i != rtable.end(); i++) {
lside.insert((**i).get_lhs());
rule::const_iterator j;
for (j = (**i).begin(); j != (**i).end(); j++)
rside.insert(*j);
}
set<int>::const_iterator j;
for (j = rside.begin(); j != rside.end(); j++)
if (lside.count(*j) > 0)
lside.erase(*j);
//lside.erase(rside.begin(), rside.end());
if (lside.size() > 1) {
//Too many startsyms
cerr << "Multiple start symbols found!\n"
<< "Check your grammar for dangling productions.\n";
return true;
}
if (lside.size() < 1) {
//No startsym
cerr << "No start symbol found!\n"
<< "Make sure your grammar has a unique start symbol.\n";
return true;
}
startsym = *(lside.begin());
return false;
}
var montageOffset = (function() {
// Magic numbers :(
var firstdelay = 6.15;
var shortdelay = 1 / 20;
var shortlimit = 12;
var longdelay = 3 / 2;
var t = 0;
var shortframe = 0;
var shortcount = 0;
var longframe = Math.floor(Math.random() * 62 + 1);
var frametime = 0;
return {
alt: false,
smalloffset: [0, 0],
tick: function() {
t += timeSinceLastTick;
if (t < firstdelay) return;
frametime += timeSinceLastTick;
var alt = this.alt;
if (frametime >= (alt ? longdelay : shortdelay)) {
if (alt) {
longframe = 1 + longframe % 62;
alt = false;
} else {
shortframe = 1 + shortframe % 62;
shortcount++;
if (shortcount >= shortlimit) {
alt = true;
shortcount = 0;
}
}
frametime = 0;
this.alt = alt;
}
var frame = alt ? longframe : shortframe;
var divs = 8;
// FIXME I think these are backwards.
this.smalloffset = [
Math.floor(frame / divs) / divs,
(frame % divs) / divs,
];
},
};
})();
outcome :: Board -> Outcome
outcome board = maximum [f $ (`M.lookup` board) <$> line | line <- allLines]
where f [Just X, Just X, Just X] = Win X
f [Just O, Just O, Just O] = Win O
f [Just _, Just _, Just _] = Draw
f _ = Continue
if [[ "$1" =~ '/' ]]; then
FILENAME="$1"
else
FILENAME="$HOME/.local/bin/$1"
fi
if [ -f "$FILENAME" ] && file -I "$FILENAME" | grep -v -q 'text/'; then
while true; do
read -p "$1 may be a binary file. Really edit it? " -n 1 yn
case $yn in
[Nn] )
exit 1
;;
[Yy] )
break
;;
* )
echo At least answer yes or no.
exit 1
;;
esac
done
fi
$EDITOR $FILENAME
[ -e $FILENAME ] && [ ! -x $FILENAME ] && chmod +x $FILENAME
* Helper subroutine for DISPLAY-SHIP. The STRING statement can be
* thought of as a cruder version of sprintf from the C language.
DISPLAY-CHARACTER.
IF SHIP-IDX > 1 THEN
STRING SPACE DELIMITED BY SIZE
QUADRANT DELIMITED BY SPACE
SPACE DELIMITED BY SIZE
INTO OUT-TEXT WITH POINTER LINE-POS
END-IF.
STRING CHARACTER-NAME (SHIP-CHAR-IDX (SHIP-IDX))
DELIMITED BY ' '
INTO OUT-TEXT WITH POINTER LINE-POS.
SHIP-CHAR-IDXUgh, you shippers now need lookup systems just to remember who you're shipping this season? Disgusting, all of you.