Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Every time you visit for the FIRST TIME today... [Part 1]

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!

Name: Anonymous 2013-10-25 15:37

>>40
You've misunderstood the intent of this software.

Name: Anonymous 2013-10-25 17:57

>>41
I know its a full width to double byte unicode translator, just messing around.

Name: Anonymous 2013-10-25 22:34

>>38
what language is that? what's that supposed to do? isn't rand(1) just 0?

Name: Anonymous 2013-10-25 22:43

>>43
Looks like Matlab/Scilab for the fucking retarded slicing syntax.

Name: Anonymous 2013-10-25 22:47

>>44
You take that back right now!

Name: Anonymous 2013-10-25 23:14

>>45
Matlab/Scilab
syntax
is

SHIT

for

FAGS.

Name: Anonymous 2013-10-26 2:38

>>46
OK YOU FUQIN ANGERED AN EXPERT PROGRAMMER

I agree that the language's syntax is third-hand puke disgusting. But the array slicing stuff is really neat.

Name: Anonymous 2013-10-26 7:05

Can /prog/ please rate my Project Euler #3 solution?
I am actually >>15.

#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;
}

Name: Anonymous 2013-10-26 7:21

>>48
Unfortunately, that's not LUCAS-quality.

Name: Anonymous 2013-10-26 8:27

>>43
conways game of life =)

Name: Anonymous 2013-10-26 8:36

todays thingo


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

Name: Anonymous 2013-10-26 8:51

In my timezone it's past midnight.


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;
}


That's some intialization code from http://repo.or.cz/w/simple-cellular-automata-suite.git , which I made for the Conway's Game of Thug Life thread. I keep meaning to go back and add new engines to it, but the life of an ENTERPRISE progrider is tiring. (I will give you commit access if you ask for it.)

Name: Anonymous 2013-10-26 9:31

>>52
conways game of thug life ^^
did you make black/white cells? xD

Name: Anonymous 2013-10-26 9:37

isn't there a way to factor recursively with modulo?

Name: Anonymous 2013-10-26 9:51

x % y = z
y % z = a
z % a = b
...
until you get zero or one? (zero = divisible // one = isn't)

Name: Anonymous 2013-10-26 10:58

>>51,53
i knew it, it had to be luke with his shit matlab code

Name: Anonymous 2013-10-26 11:06

>>47
matrix =
[1 2 3
4 5 6
7 8 9]


FIOC:
>> matrix[1] == [1 2 3]
True


Matshit:
>> 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.


Mathematica has saner syntax than Matlab and is homoeroticiconic. At least it has a valid excuse for having shitty slicing syntax and it's using [] instead of () for function calls.

Name: Anonymous 2013-10-26 11:08

>>52
Cute. Did you ever get your particular set to work, or did you just get the engine ready?

Name: Anonymous 2013-10-26 12:03

>>49
What's that mean?

Name: Anonymous 2013-10-26 13:32

>>58
and by set i meant ruleset*

Name: Anonymous 2013-10-26 13:35


mat = [1,2,3; 4,5,6; 7,8,9];

mat(1,:) == [1,2,3]

[1, 1, 1] %'(logical type)

Name: Anonymous 2013-10-26 13:39

>>55
or was that something else..?

floor(x / y) = a
x % y = z

((a % b) * a + z) % b == 0 ?

Name: Anonymous 2013-10-26 13:44

((a % b) * y + z) % b

Name: Anonymous 2013-10-26 13:50

then make y a multiple of b? =D

Name: Anonymous 2013-10-26 14:42

>>61
The list-of-lists syntax is much more flexible and clear, and it's also almost identical to the Mi,j notation used in mathematics and other abstract bullshite.

For instance, in linear programming it makes sense to talk of A5 as being the fifth constraint of the program, even though A could be a 5x9999 matrix.

Now, yes, that declaration syntax ([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.

PD: parentheses for subindices look retarded IMO

Name: Anonymous 2013-10-26 20:00

Don't hurt me please


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);
}
}

Name: Anonymous 2013-10-26 23:35

>>66
Sepples quality code

Name: Anonymous 2013-10-27 0:14

//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;
}

Name: Anonymous 2013-10-27 3:38

^^ it's euclid's greatest common divisor..
pair it up with a lazy prime template (like using 2 step.. except maybe 30 / 210 / etc) and fermat's prime test [2^(n-1) % n == 1]

Name: Anonymous 2013-10-27 3:53

...I wonder if it's worth using fermats.. it could be faster without?

Name: Anonymous 2013-10-27 4:15

Name: Anonymous 2013-10-27 6:20

>>58
My particular engine (the one based on sin and a bunch of ξ alterations) did end up working, it just wasn't very interesting to look at, unfortunately. It compensated for itself too fast and simply shot to zero.

Name: Anonymous 2013-10-27 14:03

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,
];
},
};
})();

Name: Anonymous 2013-10-27 15:17

>>72
Ah, what a shame.

Name: Anonymous 2013-10-27 15:46

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

Name: Anonymous 2013-10-28 0:56

hmm.. so is that lpt nearly an optimized number sieve?
seems like it should be faster, since it tells you which numbers to keep rather than which to throw away? =)

Name: Anonymous 2013-10-28 1:52

and i get that keeping a number vs throwing it away isn't much of a difference in itself...

but even with say, primes < 25..
sieve 2 keeps 50% / throws 50%
sieve 3 keeps 66% / throws 33%
//sieve 5 keeps 80% / throws 20%

composite sieve 2,3,5 keeps (1,7,11,13,17,19,23,29) mod 30 (keeps 26% / throws 74%) and takes one pass instead of two..?
...it's a little large for < 25..
composite sieve 2,3 keeps (1,5) mod 6 (keeps 33% / throws 66%)
1,(2,3),5, 7,11, 13,17, 19,23, [25],29, 31,[35]...

Name: Anonymous 2013-10-28 14:28

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

Name: Anonymous 2013-10-29 9:45

* 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.

Name: Anonymous 2013-10-29 11:26

>>79
SHIP-CHAR-IDX
Ugh, you shippers now need lookup systems just to remember who you're shipping this season? Disgusting, all of you.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List