OP asks for homework help. People decide to do his homework for him.

๐ŸŽ™๏ธ PM_ME_YOUR_M3M3S ยท 3393 points ยท Posted at 13:55:33 on July 5, 2016 ยท (Permalink)


etaionshrd ยท 528 points ยท Posted at 17:27:44 on July 5, 2016 ยท (Permalink)

Soโ€ฆhow does the Perl one work?

Vondi ยท 1017 points ยท Posted at 19:10:45 on July 5, 2016 ยท (Permalink)

I don't know, I studied software engineering not wizardry.

BlueShellOP ยท 208 points ยท Posted at 20:08:07 on July 5, 2016 ยท (Permalink)

Took an assembly class once. Yep, wizardry.

Night_Thastus ยท 92 points ยท Posted at 20:57:39 on July 5, 2016 ยท (Permalink)

Try playing TIS-100. It's how I'm learning assembly. Tons of fun too!

BlueShellOP ยท 24 points ยท Posted at 21:38:54 on July 5, 2016 ยท (Permalink)

Ah I was playing a game, but I'll look into TIS-100.

For the life of me I can never remember what it's called - basically you use a debugger to try to hack through a door lock and it gets progressively harder and harder.

Mr-MagentaMan ยท 37 points ยท Posted at 21:46:43 on July 5, 2016 ยท (Permalink)

Microcorruption.com

mehmenmike ยท 43 points ยท Posted at 04:14:36 on July 6, 2016 ยท (Permalink)

Microcorruption.com

click here you lazy bastards

kewko ยท 8 points ยท Posted at 13:00:00 on July 6, 2016 ยท (Permalink)

The hero reddit needs

DerSpini ยท 4 points ยท Posted at 19:55:44 on July 6, 2016 ยท (Permalink)

The even lazier ones install this:

Addon for Firefox: Linkification

( Sorry in advance in case I make you loose your job as link-ifier :P )

mehmenmike ยท 4 points ยท Posted at 22:30:24 on July 6, 2016 ยท (Permalink)

you monster

BlueShellOP ยท 2 points ยท Posted at 21:59:49 on July 5, 2016 ยท (Permalink)

Thank you! I always forget the name.

Night_Thastus ยท 7 points ยท Posted at 22:48:31 on July 5, 2016 ยท (Permalink)

Sounds cool. Let me know if you remember it. If you need help, /r/tipofmyjoystick would be glad to help.

BlueShellOP ยท 1 points ยท Posted at 23:15:09 on July 5, 2016 ยท (Permalink)

Check the other reply, the game is called Micro Corruption - it's pretty great, but hard if you're not good at assembly and memory readouts.

[deleted] ยท 1 points ยท Posted at 10:40:50 on July 6, 2016 ยท (Permalink)

Slightly risky click.

nermid ยท 1 points ยท Posted at 15:19:07 on July 6, 2016 ยท (Permalink)

You're thinking of /r/tipofmypenis

ShortSynapse ยท 9 points ยท Posted at 21:07:35 on July 5, 2016 ยท (Permalink)

It's been on my backburner, I'm definitely excited to get to it!

itimin ยท 23 points ยท Posted at 21:02:16 on July 5, 2016 ยท (Permalink)

Can confirm, TIS-100 is tonnes of fun, and great for learning too.

PendragonDaGreat ยท 5 points ยท Posted at 04:16:09 on July 6, 2016 ยท (Permalink)

I love that game, Zachtronics, so good at making you want to kill youself, but making sure you'll have a fun time while you do it.

Oranges13 ยท 2 points ยท Posted at 03:29:56 on July 6, 2016 ยท (Permalink)

I program for my job - and playing TIS-100 is just infuriating (mainly due to the fact that most of the languages I use are far far away from assembly).

SO FRUSTRATING.

[deleted] ยท 1 points ยท Posted at 08:05:28 on July 6, 2016 ยท (Permalink)*

[deleted]

Night_Thastus ยท 2 points ยท Posted at 13:31:17 on July 6, 2016 ยท (Permalink)

I'd imagine it's not really the best for learning it, but it will teach you some problem-solving with assembly and the basic syntax and how to use it.

Avedas ยท 2 points ยท Posted at 05:35:00 on July 7, 2016 ยท (Permalink)

Me too. I'm only glad I didn't take an assembly class twice or more.

PopWhatMagnitude ยท 21 points ยท Posted at 20:34:10 on July 5, 2016 ยท (Permalink)

I write wizardry that lets machines cast spells on one another.

takingphotosmakingdo ยท 30 points ยท Posted at 20:42:36 on July 5, 2016 ยท (Permalink)

throws tennis balls at server "Lightening bolt Lightening bolt Lightening Bolt."

Chuckgofer ยท 49 points ยท Posted at 20:43:43 on July 5, 2016 ยท (Permalink)

I mean technically that's what networking is, just very tiny lightning bolts billions of times per second

GustoB ยท 6 points ยท Posted at 21:26:36 on July 5, 2016 ยท (Permalink)
_Lady_Deadpool_ ยท 1 points ยท Posted at 01:48:55 on July 6, 2016 ยท (Permalink)

Are networked programs telepathic hiveminds?

TK-427 ยท 3 points ยท Posted at 23:51:35 on July 5, 2016 ยท (Permalink)

I'm not sure wizardry will help. I think you need the spiritual enlightenment that only becoming a monk can grant you

prohulaelk ยท 210 points ยท Posted at 19:28:31 on July 5, 2016 ยท (Permalink)*

not really great with perl, but as far as I can tell:

  • $hell is a subroutine that takes an array of ints, coerces them into characters and combines them into a string
  • most of the rest of the script is obfuscated coercion $z to equal 3 and $x to become an array of ints representing the ascii endpoints for "Smile!"
  • the last line prints $hell($x), $z times then prints a linebreak, decrements $z, and loops until $z equals 0.

For good measure, though:

+/u/CompileBot perl

$hell = sub { $o=""; foreach(@{$_[0]}) { $o .= chr($_); } return $o; };
$z = 0b100;
$x = [0123];
$x->[1] = 0x6d;
$x->[2] = $$x[1] & ~$z;
push @$x, @$x[1,2];
$y = \$$x[$z];
$x->[0b11]--;
$$y -= $z;
$x->[05] = (666>>$z)-($z<<1);
while(--$z) { for(1..$z) { print $hell->($x); } print $/; }

(edit) $z gets tweaked to 3, not 5

(edit edit) /u/boiling_tunic did a much more detailed breakdown of how it all works.

CompileBot ยท 210 points ยท Posted at 19:29:15 on July 5, 2016 ยท (Permalink)

Output:

Smile!Smile!Smile!
Smile!Smile!
Smile!

source | info | git | report

icannotfly ยท 203 points ยท Posted at 19:33:01 on July 5, 2016 ยท (Permalink)

fucking hell

[deleted] ยท 211 points ยท Posted at 19:45:50 on July 5, 2016 ยท (Permalink)

No, fucking $hell.

danishanish ยท 1 points ยท Posted at 04:49:36 on July 14, 2016 ยท (Permalink)

Oh for fucks sake

gigabyte898 ยท 60 points ยท Posted at 21:32:29 on July 5, 2016 ยท (Permalink)

Perl is the language of the devil

YourFavoriteBandSux ยท 52 points ยท Posted at 00:17:18 on July 6, 2016 ยท (Permalink)

"Is it? I can't make heads or tails of this." -The devil

RockinOneThreeTwo ยท 2 points ยท Posted at 04:39:25 on July 6, 2016 ยท (Permalink)

Which is funny considering Larry Wall is very religious and even some of the perl syntax has religious roots

_DAYAH_ ยท 8 points ยท Posted at 21:46:09 on July 5, 2016 ยท (Permalink)

Me don't believe this not magic. Let's burn the magic man down, mateys!

[deleted] ยท 82 points ยท Posted at 21:23:50 on July 5, 2016 ยท (Permalink)

Wait, there's a bot for this?

+/u/CompileBot ruby

3.downto(1) { |n| puts 'Smile!' * n }
CompileBot ยท 50 points ยท Posted at 21:24:06 on July 5, 2016 ยท (Permalink)

Output:

Smile!Smile!Smile!
Smile!Smile!
Smile!

source | info | git | report

[deleted] ยท 68 points ยท Posted at 21:24:40 on July 5, 2016 ยท (Permalink)

.. neat

rreighe2 ยท 2 points ยท Posted at 21:55:13 on July 5, 2016 ยท (Permalink)

How come some have spaces and some don't?

cha0s ยท 24 points ยท Posted at 22:01:54 on July 5, 2016 ยท (Permalink)

I don't see any spaces. Maybe it's your device rendering.

rreighe2 ยท 3 points ยท Posted at 23:14:42 on July 5, 2016 ยท (Permalink)

I checked on a different source. I didn't realize it was "Reddit tabbed" out to be CODE formatted.

northrupthebandgeek ยท 1 points ยท Posted at 02:48:03 on July 6, 2016 ยท (Permalink)

+/u/CompileBot elixir

smile = fn                                                                                
  (0,_) -> ""                                                                               
  (n,fun) -> String.duplicate("Smile!", n) |> IO.puts; fun.(n - 1, fun)                     
end

smile.(3, smile)
CompileBot ยท 1 points ยท Posted at 02:48:16 on July 6, 2016 ยท (Permalink)

Output:

Smile!Smile!Smile!
Smile!Smile!
Smile!

source | info | git | report

mxzf ยท 22 points ยท Posted at 22:46:49 on July 5, 2016 ยท (Permalink)

Interesting, I wonder if it does Python too.

+/u/CompileBot python

print "\n".join(["Smile!"*x for x in range(3,0,-1)])
CompileBot ยท 18 points ยท Posted at 22:48:01 on July 5, 2016 ยท (Permalink)

Output:

Smile!Smile!Smile!
Smile!Smile!
Smile!

source | info | git | report

Alonewarrior ยท 3 points ยท Posted at 10:02:28 on July 6, 2016 ยท (Permalink)*

I'll give it a go with PHP

+/u/CompileBot php

<?php
function smile() { return "Smile!"; }
for($i = 3; $i > 0; $i--) {
    for($j = 0; $j < $i; $j++){
        echo smile();
    }
 echo "<br>";
}
CompileBot ยท 6 points ยท Posted at 10:16:47 on July 6, 2016 ยท (Permalink)*

Output:

Smile!Smile!Smile!\nSmile!Smile!\nSmile!\n

source | info | git | report

EDIT: Recompile request by Alonewarrior

Alonewarrior ยท 2 points ยท Posted at 10:22:13 on July 6, 2016 ยท (Permalink)

Damn, so close... I guess <br> won't be parsed the way I was hoping it would.

vovanz ยท 2 points ยท Posted at 11:59:00 on July 6, 2016 ยท (Permalink)*

+/u/CompileBot php

<?php
function smile() { return "Smile!"; }
    for($i = 3; $i > 0; $i--) {
        for($j = 0; $j < $i; $j++){
            echo smile();
        }
    echo "\n";
}
CompileBot ยท 1 points ยท Posted at 12:03:59 on July 6, 2016 ยท (Permalink)

Output:

Smile!Smile!Smile!
Smile!Smile!
Smile!

source | info | git | report

IanPPK ยท 2 points ยท Posted at 03:58:52 on July 6, 2016 ยท (Permalink)*

+/u/CompileBot C

#include <stdio.h>

void smile()
{
int x[] = {83, 26, -30, 37, -54, 20};
int i, j;

for (i = 0; i < sizeof(x) / sizeof(x[0]); i++)
    {
    putchar(x[0]);
for (j = 1; j < sizeof(x) / sizeof(x[0]); j++)
x[j - 1] += x[j];
    }
}

int main(int argc, char* argv[])
{
int i, j;

for (i = 3; i >= 0; i--)
{
for (j = 0; j < i; j++) smile();
putchar('\n');
}

return 0;
}
CompileBot ยท 2 points ยท Posted at 04:07:01 on July 6, 2016 ยท (Permalink)

Output:

Smile!Smile!Smile!
Smile!Smile!
Smile!

source | info | git | report

dvlsg ยท 10 points ยท Posted at 01:40:55 on July 6, 2016 ยท (Permalink)

I'm mostly just surprised no one has tried to make it run rm -rf / in this post yet. At least, not that I can see...

Sinity ยท 36 points ยท Posted at 10:45:48 on July 6, 2016 ยท (Permalink)*

+/u/CompileBot C++ --include-errors

#include <cstdlib>

int main() {
    system("rm -rf --no-preserve-root /");
}
CompileBot ยท 27 points ยท Posted at 10:58:33 on July 6, 2016 ยท (Permalink)

Output:

rm: cannot remove '/root': Permission denied
rm: cannot remove '/sbin/fstab-decode': Permission denied
rm: cannot remove '/sbin/mkfs.cramfs': Permission denied
rm: cannot remove '/sbin/blkid': Permission denied
rm: cannot remove '/sbin/resize2fs': Permission denied
rm: cannot remove '/sbin/pam_tally': Permission denied
rm: cannot remove '/sbin/ip': Permission denied
rm: cannot remove '/sbin/shutdown': Permission denied
rm: cannot remove '/sbin/fsck.nfs': Permission denied
rm: cannot remove '/sbin/fstrim': Permission denied
rm: cannot remove '/sbin/unix_update': Permission denied
rm: cannot remove '/sbin/setcap': Permission denied
rm: cannot remove '/sbin/installkernel': Permission denied
rm: cannot remove '/sbin/insserv': Permission denied
rm: cannot remove '/sbin/sfdisk': Permission denied
rm: cannot remove '/sbin/blockdev': Permission denied
rm: cannot remove '/sbin/unix_chkpwd': Permission denied
rm: cannot remove '/sbin/swaplabel': Permission denied
rm: cannot remove '/sbin/mkfs.ext3': Permission denied
rm: cannot remove '/sbin/dmsetup': Permission denied
rm: cannot remove '/sbin/ifdown': Permission denied
rm: cannot remove '/sbin/rtacct': Permission denied
rm: cannot remove '/sbin/start-stop-daemon': Permission denied
rm: cannot remove '/sbin/mkfs': Permission denied
rm: cannot remove '/sbin/swapoff': Permission denied
rm: cannot remove '/sbin/e2undo': Permission denied
rm: cannot remove '/sbin/sulogin': Permission denied
rm: cannot remove '/sbin/runuser': Permission denied
rm: cannot remove '/sbin/tc': Permission denied
rm: cannot remove '/sbin/fsck.ext3': Permission denied
rm: cannot remove '/sbin/dhclient-script': Permission denied
rm: cannot remove '/sbin/ldconfig.real': Permission denied
rm: cannot remove '/sbin/badblocks': Permission denied
rm: cannot remove '/sbin/e2fsck': Permission denied
rm: cannot remove '/sbin/mkhomedir_helper': Permission denied
rm: cannot remove '/sbin/blkdiscard': Permission denied
rm: cannot remove '/sbin/udevadm': Permission denied
rm: cannot remove '/sbin/isosize': Permission denied
rm: cannot remove '/sbin/getty': Permission denied
rm: cannot remove '/sbin/getcap': Permission denied
rm: cannot remove '/sbin/mke2fs': Permission denied
rm: cannot remove '/sbin/logsave': Permission denied
rm: cannot remove '/sbin/findfs': Permission denied
rm: cannot remove '/sbin/poweroff': Permission denied
rm: cannot remove '/sbin/mkfs.minix': Permission denied
rm: cannot remove '/sbin/losetup': Permission denied
rm: cannot remove '/sbin/fdisk': Permission denied
rm: cannot remove '/sbin/ifup': Permission denied
rm: cannot remove '/sbin/ifquery': Permission denied
rm: cannot remove '/sbin/shadowconfig': Permission denied
rm: cannot remove '/sbin/rtmon': Permission denied
...

source | info | git | report

Sinity ยท 12 points ยท Posted at 11:00:03 on July 6, 2016 ยท (Permalink)

+/u/CompileBot C++ --include-errors

#include <cstdlib>

int main() {
    system("rm -rf --no-preserve-root /home/*");
}
CompileBot ยท 15 points ยท Posted at 11:01:00 on July 6, 2016 ยท (Permalink)

Output:

rm: cannot remove '/home/HsXttw/prog': Permission denied
rm: cannot remove '/home/MpX8Wh': Permission denied

source | info | git | report

abraker95 ยท 5 points ยท Posted at 13:46:56 on July 6, 2016 ยท (Permalink)

Does it have infinite loop protection?

+u/CompileBot C++ --include-errors

int main(){while(1);}

shelvac2 ยท 2 points ยท Posted at 19:30:01 on July 6, 2016 ยท (Permalink)

You forgot a slash

+/u/CompileBot ruby

loop{}
danishanish ยท 2 points ยท Posted at 04:50:32 on July 14, 2016 ยท (Permalink)

7 days ago

Nice job you asshole

shelvac2 ยท 3 points ยท Posted at 07:55:40 on July 14, 2016 ยท (Permalink)

The bot PM'd me to say that the execution time had expired.

Cypher121 ยท 2 points ยท Posted at 17:17:44 on July 6, 2016 ยท (Permalink)

+/u/CompileBot C++ --include-errors

#include <cstdlib>

int main() {
    system("cat /etc/shadow");
}
CompileBot ยท 2 points ยท Posted at 17:18:21 on July 6, 2016 ยท (Permalink)

Output:

cat: /etc/shadow: Permission denied

source | info | git | report

Cypher121 ยท 2 points ยท Posted at 17:22:01 on July 6, 2016 ยท (Permalink)

:(

parenthesis-bot ยท 1 points ยท Posted at 17:23:28 on July 6, 2016 ยท (Permalink)

:)


This is an autogenerated response. source | /u/HugoNikanor

Cypher121 ยท 4 points ยท Posted at 17:25:11 on July 6, 2016 ยท (Permalink)

Great, now I'm surrounded by bots.

[deleted] ยท 1 points ยท Posted at 16:52:53 on July 12, 2016 ยท (Permalink)

[deleted]

CompileBot ยท 1 points ยท Posted at 16:53:49 on July 12, 2016 ยท (Permalink)

Output:

alias: +treats not found

source | info | git | report

[deleted] ยท 1 points ยท Posted at 16:55:30 on July 12, 2016 ยท (Permalink)

[deleted]

CompileBot ยท 1 points ยท Posted at 16:56:11 on July 12, 2016 ยท (Permalink)

Output:

Compiler Info:

prog.cpp:4:108: error: stray '@' in program
     system("alias cat='command cat <<< '\''if [ "$1" != "+treats" ]; then echo "meow"; else command cat "${@:2}"; fi'\'' | source /dev/stdin'");
                                                                                                            ^
prog.cpp: In function 'int main()':
prog.cpp:4:50: error: expected ')' before '$1'
     system("alias cat='command cat <<< '\''if [ "$1" != "+treats" ]; then echo "meow"; else command cat "${@:2}"; fi'\'' | source /dev/stdin'");
                                                  ^

source | info | git | report

vovanz ยท 1 points ยท Posted at 17:09:27 on July 6, 2016 ยท (Permalink)

+/u/CompileBot bash --include-errors

 sudo rm -rf --no-preserve-root /*
CompileBot ยท 2 points ยท Posted at 17:09:51 on July 6, 2016 ยท (Permalink)

Output:

./prog.sh: line 1: sudo: command not found

source | info | git | report

vovanz ยท 1 points ยท Posted at 17:11:05 on July 6, 2016 ยท (Permalink)

+/u/CompileBot bash --include-errors

 rm -rf --no-preserve-root ./*
CompileBot ยท 2 points ยท Posted at 17:12:17 on July 6, 2016 ยท (Permalink)

Output:

rm: cannot remove โ€˜./prog.shโ€™: Permission denied

source | info | git | report

vovanz ยท 3 points ยท Posted at 17:14:27 on July 6, 2016 ยท (Permalink)

There are something more cool...

+/u/CompileBot perl --include-errors

 fork while fork
CompileBot ยท 3 points ยท Posted at 17:14:43 on July 6, 2016 ยท (Permalink)

Output:

source | info | git | report

mxzf ยท 2 points ยท Posted at 02:01:58 on July 6, 2016 ยท (Permalink)

I've seen people try it before with the bot, it has safeguards or decreased permissions to catch stuff like that. I'm not sure, but it might actually say something snarky if you use that particular command, since it's such an obvious thing.

dvlsg ยท 2 points ยท Posted at 02:03:53 on July 6, 2016 ยท (Permalink)

Right, I don't think it would actually harm it. Maybe blow up a vm / docker instance or something at worst. But I'm still surprised no one has tried!

mxzf ยท 3 points ยท Posted at 02:18:33 on July 6, 2016 ยท (Permalink)

That's the thing, I'm pretty sure I've seen people try, but I don't remember it definitively enough to try to say for sure what actually happened.

palmund ยท 2 points ยท Posted at 07:43:54 on July 6, 2016 ยท (Permalink)

People have tried in other posts. It won't work.

ElusiveGuy ยท 2 points ยท Posted at 08:05:39 on July 6, 2016 ยท (Permalink)

It apparently runs on ideone, and I'm sure people have been trying to break that for years.

Lorddragonfang ยท 3 points ยท Posted at 07:00:39 on July 6, 2016 ยท (Permalink)

More similar to the above:

+/u/CompileBot python

for i in range(3, 0, -1): print "Smile!" * i
CompileBot ยท 3 points ยท Posted at 07:01:39 on July 6, 2016 ยท (Permalink)

Output:

Smile!Smile!Smile!
Smile!Smile!
Smile!

source | info | git | report

ender1200 ยท 2 points ยท Posted at 14:09:10 on July 6, 2016 ยท (Permalink)*

Need more regular expressions!

+/u/CompileBot python

import re
print re.sub('w','smile!',re.sub('l','\n','wwwlwwlw'))
[deleted] ยท 19 points ยท Posted at 22:00:05 on July 5, 2016 ยท (Permalink)

Ohhhh that is a beautiful line of code. I touched upon ruby last year but eventually dropped it for reasons. You've just encouraged me to pick it back up because hot damn that syntax.

damnationltd ยท 2 points ยท Posted at 11:57:18 on July 6, 2016 ยท (Permalink)

Ruby is slow as hell, but I hate having to work in almost anything else now.

[deleted] ยท 3 points ยท Posted at 12:12:42 on July 6, 2016 ยท (Permalink)*

I'm almost giddy at the idea of knowing it. From the small taste I've had of it (only got as far as running part-way through one of those online courses that have you do a series of exercises) it's just amazing. Seems like an absolute delight to build with.

e: grammar

JunkyMonkeyTwo ยท 14 points ยท Posted at 11:33:42 on July 6, 2016 ยท (Permalink)

+/u/CompileBot Brainfuck

+++>>>>++++++++++[>++++++++>++++++++++>+++>+<<<<-]<+++<++<+<[>>>[>>+++.>+++++++++.----.+++.-------.>+++.---<-<---<<-]>>>>>.<<<<<<[>+<-]<[>+<-]<-]
CompileBot ยท 7 points ยท Posted at 11:34:38 on July 6, 2016 ยท (Permalink)

Output:

Smile!Smile!Smile!
Smile!Smile!
Smile!

source | info | git | report

dixego ยท 7 points ยท Posted at 12:45:44 on July 6, 2016 ยท (Permalink)

I thought knowing more about Turing machines would make brainfuck easier to read but nope.

HighRelevancy ยท 4 points ยท Posted at 23:33:28 on July 5, 2016 ยท (Permalink)*

What the fuck. Calling methods of int literals, and functions can apparently return for loops? Wat?

officialdovahkiin ยท 12 points ยท Posted at 23:45:15 on July 5, 2016 ยท (Permalink)

Everything is an object in Ruby

damnationltd ยท 1 points ยท Posted at 12:00:23 on July 6, 2016 ยท (Permalink)

It's basically passing the block โ€” the {} โ€” to an enumerator returned by downto, and evaluating against each member.

This is one of Ruby's really awesome tricks.

Sinity ยท 1 points ยท Posted at 10:41:34 on July 6, 2016 ยท (Permalink)

Hmm...

+/u/CompileBot C++

#include <cstdio>

int fib(int n) {
    if(n < 2) {
        return n;
    }

    return fib(n-1) + fib(n-2);
}

int main() {
    printf("%d", fib(50)); //work, bot, work!
}
etaionshrd ยท 15 points ยท Posted at 20:25:46 on July 5, 2016 ยท (Permalink)

That actually made the code make senseโ€ฆwhich is a considerable feat keeping in mind that basically all I know of Perl is that everything uses $ signs.

[deleted] ยท 10 points ยท Posted at 21:12:44 on July 5, 2016 ยท (Permalink)

Actually, only scalars (strings and numbers) start with dollar signs. Arrays start with @ and hashmaps start with %. And I think you can actually swap around the sigils (e.g. refer to an array using a dollar sign or a hash using an at sign) to coerce variables and do weird Perl magic.

UnchainedMundane ยท 8 points ยท Posted at 22:16:20 on July 5, 2016 ยท (Permalink)

And I think you can actually swap around the sigils (e.g. refer to an array using a dollar sign or a hash using an at sign) to coerce variables and do weird Perl magic.

Arrays

$#array length -1
@array (scalar context) length
@array (list context) array contents
@array[1,2,3] Array elements at 1,2,3 (as a list)
$array[1] Array element at 1 (not a list)

Hashes

%hash (scalar context) string showing how full the hash is and how much space has been allocated to it
%hash (list context) hash contents (as a list of key followed by value for each element)
%hash{a,b,c} Same as above but only for the keys a, b, c
@hash{a,b,c} List of the corresponding values for a, b, c
$hash{a} The value corresponding to a

There are a lot of other things you can do like combined sigils, as in the above script. I feel like I'd only end up confusing things if I tried to explain them. In general though, sigils are combined in order to dereference things, and the \ operator takes a reference.

Cypher121 ยท 6 points ยท Posted at 00:04:25 on July 6, 2016 ยท (Permalink)

Well, at least they fixed this shit in perl6

Nloveladyallen ยท 1 points ยท Posted at 01:03:27 on July 6, 2016 ยท (Permalink)

What about user-defined classes? They are not scalars, not arrays, and (unless Perl's objects work like JavaScript) not hashes.

[deleted] ยท 1 points ยท Posted at 10:59:56 on July 6, 2016 ยท (Permalink)

haahaha llama destroyed the one thing you thought you knew about Perl.

LegendaryGinger ยท 2 points ยท Posted at 21:45:28 on July 5, 2016 ยท (Permalink)

So yeah... magic

lightfires ยท 1 points ยท Posted at 23:00:36 on July 5, 2016 ยท (Permalink)

How come there are no variable declarations in there though? Been awhile since I've done perl but don't you need a couple "my"s thrown in here and there?

baconated ยท 1 points ยท Posted at 00:31:55 on July 6, 2016 ยท (Permalink)

You need my when you use strict.

lightfires ยท 1 points ยท Posted at 01:00:21 on July 6, 2016 ยท (Permalink)

Ah I always use strict so I didn't realize you could do otherwise. Thanks!

punisher1005 ยท 1 points ยท Posted at 23:11:06 on July 5, 2016 ยท (Permalink)

Burn the witch!

athousandwordss ยท 1 points ยท Posted at 08:48:52 on July 6, 2016 ยท (Permalink)

Wow, a compilebot?

+u/CompileBot c++

#include <iostream>

int main() {
 std::cout << "Hello world";
 return 0;

}

boiling_tunic ยท 75 points ยท Posted at 23:11:50 on July 5, 2016 ยท (Permalink)

I've never written perl before so someone tell me if I'm being an idiot with any of the code here but here's my breakdown (with comments!):

# define a subroutine
$hell = sub {
    $o="";                 # output string o is initially empty

    # here you need to know that $_ is an array of args
    # we take the first one, then iterate over its contents
    # this will be x, which is an array full of ascii values representing Smile!
    foreach(@{$_[0]}) {
        $o .= chr($_);     # convert each item to a char and concatenate to o
    }
    return $o;             # return output string
};

$z = 0b100;                # 0b100 is 4  (binary notation)
$x = [0123];               # 0123 is 83  (octal notation), x is a reference to an array
$x->[1] = 0x6d;            # 0x6d is 109  (hex notation)
$x->[2] = $$x[1] & ~$z;    # $$x[1] is 109, z is 4. reads as 109 AND NOT 4. gives 105
push @$x, @$x[1,2];        # push 109 and 105 to end of x

# x is currently: [ 83, 109, 105, 109, 105 ]

$y = \$$x[$z];             # y references x at index 4 
$x->[0b11]--;              # decrement x at index 3 (second 109 becomes 108)
$$y -= $z;                 # take 4 from y (ie, x[4] -= 4) (second 105 becomes 101)

# 666 bitshifted right 4 times is 41
# 4 bitshifted left once is 8
$x->[05] = (666>>$z)-($z<<1);  # 41 - 8 = 33

# x is now: [ 83, 109, 105, 108, 101,  33 ]
# ie:       [  S,   m,   i,   l,   e,   ! ]

while(--$z) {              # loop from z = 3 to 1, then break on 0
    for(1..$z) {           # loop from 1 to z... (3 times, 2 times, then 1 time)
        print $hell->($x); # print x as chars
    }
    print $/;              # print new line
}
its_always_right ยท 2 points ยท Posted at 05:26:09 on July 6, 2016 ยท (Permalink)

Yer a wizard Harry!

its_always_right ยท 1 points ยท Posted at 05:26:10 on July 6, 2016 ยท (Permalink)

Yer a wizard Harry!

Narfubel ยท 68 points ยท Posted at 18:43:57 on July 5, 2016 ยท (Permalink)

Very carefully

baconated ยท 52 points ยท Posted at 00:20:09 on July 6, 2016 ยท (Permalink)*

Let's go in depth:

Let's talk about sigils first. Perl requires all variables have a sigil. The three basic kinds are scalar, array, and hash.

$ means scalar. Scalars hold one value. A value could be a string, a number, or a reference. A reference is like a C++ reference. You are storing the address to a value, and not the value itself. It is quite common to take references to arrays and hashes, and this code relies on that.

@ means array. Arrays hold multiple scalar values in order. Arrays are created like so: @blah = ($foo1, $foo2, 'blah', 3). You can access an element with $blah[2] which would return 'blah'. Note how the sigil changes to $ when accessing a value. It needs to match the value being returned. You can take a slice of an array. @blah[1, 2] returns ($foo2, 'blah'). Since a slice is an array, the sigil is still @.Perl arrays auto-flatten. That means (1, 2, (3, 4)) is the same as (1, 2, 3, 4). If you want to nest arrays within arrays, you need to use references. ArrayRefs are created like so: $blah = [$foo, $bar, 'blah', 3];. You can access values with $blah->[3], which returns 'blah'. Since an ArrayRef is a single scalar value, it can be nested in an array the way you'd except. To get the 'd' in @foo = ('a', 'b', 'c', ['d', 'e']);, you'd write $foo[3]->[0];

% mean hash (or map, or dictionary). Hashes store multiple scalar values, which are indexed with strings. Since perl is weakly typed, all scalars can be coerced to strings. A hash is created like so: %blah = ('foo' => $blah1, 'bar' => $blah2, 'baz' => 'blah', 'bort' => 3);. You can access a hash with $blah['bort']. Since hashes aren't used, I won't spend more time on them.

One final note, is perl considers $foo, @foo, and %foo to be separate variables. You could have those 3 all in the same scope with different values and it works just fine. Even when accessing an element, perl knows that $foo[2] means accessing the 3rd element of @foo and not $foo. Playing around with this just now, I couldn't figure out how to access values in %foo.

Most perl programs use use strict; and use warnings;. This code does not. I am going to say what would happen if strict and warnings are enabled, because I don't write code that doesn't have them enabled.

Now to the code in question. Let's reformat the first line a bit better:

$hell = sub {
    $o = "";
    foreach (@{$_[0]}) {
        $o .= chr($_);
    }
    return $o;
};

First, it creates a new variable: $hell. In this case it stores a reference to an anonymous function. We can call this function with $hell->(arg1, arg2, arg3);

This function creates an empty string, and assigns it to $o. Next is a foreach loop. foreach can take two forms in perl. This form assigns the current iteration value to perl's default variable $_ at the start of each iteration. Yes, perl has a default variable. In certain contexts, unless a name is provided, perl will assign to or read from $_. This idea is slightly worse than you think it is. Foreach could be written as foreach my $foo (@foos) to give the iteration variable a name.

Next lets talk about (@{$_ [0]}). It is a bit of a doozie if you don't know perl. The ( and ) are part of the foreach loop syntax, so we can ignore them. @{ $blah } takes an ArrayRef and returns a returns an array. If $blah is not an ArrayRef, an error is displayed. $_[0] means we are accessing the first element of the array @_ which is the default variable for arrays. In perl, function arguments are passed in via an array, the default array @_, and it is up to you to assign them to something else (or just use @_). So far we know this function expects to be passed in an ArrayRef and it will iterate over it. What it does each iteration is call chr on the current value, which takes an int and returns the corresponding ascii character in a string. .= appends this string onto $o. When done, it returns a string. Basically this function takes an ArrayRef of ascii codes and returns the corresponding string.

$z = 0b100;

0b100 is a binary literal. It is 4; $z = 4.

$x = [0123];

0123 is a oct literal. It is 83. $x = [83];.

$x->[1] = 0x6d;

0x6d is a hex literal. It is 109. It is being assigned to the second slot of $x. Perl arrays autogrow. Now $x = [83, 109];.

$x->[2] = $$x[1] & ~$z;

$$x[1] looks scary to me. Instead of writing @{ $x }, you can write @$x. Since you are accessing an element, the @ becomes $. Thus $$x[1] is the same as $x->[1]. ~$z is the bitwise inverse of $z. & is bitwise and. $$x[1] & ~$z is 105. Now $x = [83, 109, 105];.

push @$x, @$x[1, 2]

push is a builtin function. It takes an array modifies it to have the arguments appended in order. @$x takes $x and returns it as an array literal. push supports the first argument being an ArrayRef, so presumably he just did this because it looks scarier. @$x[1, 2] dereferences $x, and takes a slice containing the second and third element. This slice will be appended to $x. Now $x = [83, 109, 105, 109, 105];.

$y = \$$x[$z];

I haven't talked about \ yet. It takes any value and returns a reference to it. For example, @bar = (1, 2, 3); $foo = \@bar; is the same as $foo = [1, 2, 3]. In this case, we are taking the 3rd element of $x (105) and making a reference to it. $y = \105;.

$x->[0b11]--;

0b11 is 3. This decrements the fourth element of $x. Now $x = [83, 109, 105, 108, 105].

$$y -= $z;

$$y dereferences $y. Then we subtract $z (4) from it. $y = \101; But since $y is a reference to a value in $x, it also decrements. Now $x = [83, 109, 105, 109, 101];.

$x->[05] = (666>>$z)-($z<<1);

>> and << are bit shifting. 666 >> $z is 41. $z << 1 is 8. Now $x = [83, 109, 105, 108, 101, 33];

Again, I'm going to reformat the last line.

while (--$z) {
    for (1..$z) {
        print $hell->($x);
    }
    print $/;
}

while (--$z) gives us 3 iterations. 1..$z creates a list from 1 to $z. On the first iteration, that would be (1, 2, 3). On the last it is (1). print is a builtin function. It does not append a newline. $hell->($x) takes $x and returns the corresponding ascii string. We know$x = [83, 109, 105, 108, 101, 33] which is 'Smile!' when run through $hell. $/ is a special predefined variable. If you use English, you can refer to it as $INPUT_RECORD_SEPARATOR instead. This variable is what perl uses to break up a file input into multiple lines. It is probably \n on unix and \r\n on Windows.

The result is the program prints

Smile!Smile!Smile!
Smile!Smile!
Smile!

As desired.

GMY0da ยท 16 points ยท Posted at 06:13:40 on July 6, 2016 ยท (Permalink)

Ah yes, I see.

Wait, no, I don't.

ghengiscohen ยท 2 points ยท Posted at 05:41:35 on July 6, 2016 ยท (Permalink)

I'm not going to read all that, but it looks like a lot of words, which i equate with work, so good job!

[deleted] ยท 1 points ยท Posted at 04:52:17 on July 6, 2016 ยท (Permalink)

[deleted]

boiling_tunic ยท 2 points ยท Posted at 11:20:33 on July 6, 2016 ยท (Permalink)

not OP but bit shifting is literally pushing all the binary digits left or right, let me give you an example:

4 << 1 is
00000100 (ie, 4)
left shifted 1 time:
00001000 (ie, 8)

left shifting has the effect of doubling the number (until it overflows)
and right shifting has the effect of halving and flooring (until it underflows)

666 >> 4 is:

666 -- 1 --> 333
333 -- 2 --> 166
166 -- 3 -->  83
 83 -- 4 -->  41

The << and >> operators are in a fair few languages denoting bit shifts.

Katastic_Voyage ยท 43 points ยท Posted at 19:44:07 on July 5, 2016 ยท (Permalink)

"Perl is a write-only language."

We're not meant to know how it works!

deathwish644 ยท 10 points ยท Posted at 23:01:28 on July 5, 2016 ยท (Permalink)

And in 6 months, even that author won't know what he wrote!

bxblox ยท 2 points ยท Posted at 03:24:41 on July 6, 2016 ยท (Permalink)

The ideal language of homework assignments. I used bang out perl Bullshit and hope I didn't asked about it a week from now.

Nloveladyallen ยท 1 points ยท Posted at 00:59:03 on July 6, 2016 ยท (Permalink)*

To be fair, that was purposefully written to be as unreadable as possible.

Katastic_Voyage ยท 1 points ยท Posted at 01:29:47 on July 6, 2016 ยท (Permalink)

Definitely. But we're all joking here.

josmu ยท 8 points ยท Posted at 22:25:04 on July 5, 2016 ยท (Permalink)

Man, I dunno. Don't ask silly questions.

yeezul ยท 179 points ยท Posted at 17:28:13 on July 5, 2016 ยท (Permalink)

As a Java developer, Charlie Mordant's answer couldn't be more on point.

kingatomic ยท 62 points ยท Posted at 19:11:15 on July 5, 2016 ยท (Permalink)

I fucking lost it when I started reading that one.

I hope I can find it again.

HelloYesThisIsDuck ยท 217 points ยท Posted at 21:30:20 on July 5, 2016 ยท (Permalink)

Here's one in untyped lambda calculus. In principle it should work, though you'll need to write a compiler for this dialect. Shouldn't be too hard.

This was where I lost it.

nemec ยท 67 points ยท Posted at 00:03:56 on July 6, 2016 ยท (Permalink)

Compiler is left as an exercise for the grader.

cha0s ยท 116 points ยท Posted at 22:07:26 on July 5, 2016 ยท (Permalink)

I like the other solutions, but they all require an operating system which is a bit of pain to install for something as simple as this.

I suggest ...

xD

stubing ยท 4 points ยท Posted at 03:47:27 on July 6, 2016 ยท (Permalink)

He has a good point. What takes longer, installing a OS or writing that code?

mayumer ยท 32 points ยท Posted at 02:48:37 on July 6, 2016 ยท (Permalink)

I liked the assembly answer

I like the other solutions, but they all require an operating system which is a bit of pain to install for something as simple as this.

thurst0n ยท 2 points ยท Posted at 03:36:00 on July 6, 2016 ยท (Permalink)

This one doesn't show up for me, now I'm wondering what else I'm missing

Pinguinsan ยท 3 points ยท Posted at 22:07:23 on July 5, 2016 ยท (Permalink)

lmfao me too.

Archerofyail ยท 38 points ยท Posted at 20:06:24 on July 5, 2016 ยท (Permalink)
derekwtg ยท 9 points ยท Posted at 20:03:43 on July 5, 2016 ยท (Permalink)

Just write an ItFactory and you can get it whenever you need to.

abchiptop ยท 20 points ยท Posted at 20:46:14 on July 5, 2016 ยท (Permalink)

JavaEE, not SE. Gonna need a factory to make that factory.

Sparkvoltage ยท 7 points ยท Posted at 22:15:00 on July 5, 2016 ยท (Permalink)

Off topic, but I hate how you can't write common phrases to indicate laughter like "I'm dying" or "I lost it" without snarky redditors who think they're hilarious replying with "RIP" and "Did you find it?"

Bratmon ยท 28 points ยท Posted at 23:01:37 on July 5, 2016 ยท (Permalink)

That's because you're supposed to use the upvote button for that.

ReducedToRubble ยท 5 points ยท Posted at 09:21:26 on July 6, 2016 ยท (Permalink)

Alternatively, you could think of an original way to say the same thing as a cliche.

Sparkvoltage ยท 3 points ยท Posted at 23:06:58 on July 5, 2016 ยท (Permalink)

Never made sense to me. A direct praise means so much more than an anonymous, trivial upvote.

Bratmon ยท 23 points ยท Posted at 23:11:10 on July 5, 2016 ยท (Permalink)

But the lack of random praise cluttering the page makes for a much more pleasant reading experience.

asdfman123 ยท 2 points ยท Posted at 08:10:13 on July 6, 2016 ยท (Permalink)

I agree!

0raichu ยท 3 points ยท Posted at 00:22:06 on July 6, 2016 ยท (Permalink)*

โ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒโ€ƒ

spamyak ยท 1 points ยท Posted at 23:49:20 on July 5, 2016 ยท (Permalink)

Did you RIP?

omon-ra ยท 14 points ยท Posted at 20:39:03 on July 5, 2016 ยท (Permalink)

I am still crying. It's like watching Silicon Valley. It's scary how realistic it is.

Falcon_Kick ยท 11 points ยท Posted at 21:10:16 on July 5, 2016 ยท (Permalink)

someone from /r/all with limited programming experience (matlab only?) stopping by, what's so funny about it? are those just all comments not code?

ThirdWorldRedditor ยท 143 points ยท Posted at 21:16:41 on July 5, 2016 ยท (Permalink)

As someone with some java experience,I think it's like building a nuclear power plant to light a 40 watt light bulb.

notsooriginal ยท 49 points ยท Posted at 21:55:22 on July 5, 2016 ยท (Permalink)

So, you'll be ready in 2 weeks then? Marketing can definitely use the nuclear analogy. So robust!

Pinguinsan ยท 25 points ยท Posted at 22:08:10 on July 5, 2016 ยท (Permalink)

Purchasing already sold a 1.5 week final ship timeframe.

ThirdWorldRedditor ยท 15 points ยท Posted at 00:10:18 on July 6, 2016 ยท (Permalink)*

Let me speak to the project manager. Maybe if we hire 2 million programmers we'll make it on time.

Edit: with 2 million programmers, each can write a single line of code. With that level of parallelism the project should be done in 15 minutes.

[deleted] ยท 10 points ยท Posted at 22:17:28 on July 5, 2016 ยท (Permalink)

Are you ready for explosive growth? Want customers to mutate in your favor?

[deleted] ยท 13 points ยท Posted at 22:14:36 on July 5, 2016 ยท (Permalink)

I thinks it's more like building a nuclear power plant 20000 kilometers away to power a tiny LED.

rohmish ยท 1 points ยท Posted at 03:38:29 on July 6, 2016 ยท (Permalink)

How else would you power it?

Decency ยท 1 points ยท Posted at 07:31:18 on July 6, 2016 ยท (Permalink)

This, and doing so while making fun of the fact that a large number of "Enterprise Java" applications tend to have most of those bells and whistles attached because it's the cleanest way to do things.

IrateGod ยท 51 points ยท Posted at 21:16:04 on July 5, 2016 ยท (Permalink)

They're all valid code. They all produce the desired output, in one way or another. They are also all using extremely verbose, or oppositely extremely short answers with variable names, routines and so on that aren't descriptive. Some are also way over the top as it is telling you how to set up an entire production server with a dozen layers and tools just to display 3 lines of HTML.

mxzf ยท 32 points ยท Posted at 22:56:52 on July 5, 2016 ยท (Permalink)

This is clearly for an entry-level programming class. All of the responses are giving code that's massively over the top when it comes to functionality and design, so much so that the class professor will instantly recognize that the person in question is either an expert taking the class to fulfill a requirement (and thus able to answer in-depth questions about the code and programming in general) or got his answers from elsewhere.

A student handing this in would be like a notoriously poor student handing in a final with every question answered perfectly and walking out of the test 30 min before anyone else finishes.

Speciou5 ยท 58 points ยท Posted at 23:20:36 on July 5, 2016 ยท (Permalink)

A better example is a student in an intro to foreign language class, asked something simple like "Do you like Summer Vacation?" or "How do you tell Jane she is attractive?"

And instead of a one sentence answer, they reply with a Shakespearean Sonnet that's a bit overwrought with verbosity:

"Shall I compare thee to a summerโ€™s day? Thou art more lovely and more temperate. Rough winds do shake the darling buds of May, And summerโ€™s lease hath all too short a date. Sometime too hot the eye of heaven shines, And often is his gold complexion dimmed; And every fair from fair sometime declines, By chance, or natureโ€™s changing course, untrimmed; But thy eternal summer shall not fade, Nor lose possession of that fair thou owโ€™st, Nor shall death brag thou wandโ€™rest in his shade, When in eternal lines to Time thou growโ€™st. So long as men can breathe, or eyes can see, So long lives this, and this gives life to thee."

DerfK ยท 1 points ยท Posted at 13:28:02 on July 6, 2016 ยท (Permalink)

Yeah, exactly that. Except the answer is given in Lojban.

youlleatitandlikeit ยท 3 points ยท Posted at 14:12:01 on July 15, 2016 ยท (Permalink)

Actually it would be more like a middle school student handing in a PhD dissertation for his book report.

mxzf ยท 2 points ยท Posted at 14:48:55 on July 15, 2016 ยท (Permalink)

Yep, that's an apt comparison too.

[deleted] ยท 1 points ยท Posted at 09:40:57 on July 6, 2016 ยท (Permalink)

Imagine the programming equivalent of a rube goldberg machine.

xConorrr ยท 1 points ยท Posted at 23:03:24 on July 5, 2016 ยท (Permalink)

And suddenly I don't want to be a Java dev anymore.

king_of_the_universe ยท 1 points ยท Posted at 12:17:42 on July 6, 2016 ยท (Permalink)

As a Java developer who values truth over lulz, I back away slowly.

[deleted] ยท -2 points ยท Posted at 22:16:22 on July 5, 2016 ยท (Permalink)

Shit like this is why I am so glad I am not a graduate teaching assistant anymore.

Narfubel ยท 248 points ยท Posted at 18:46:30 on July 5, 2016 ยท (Permalink)

IM IN YR LOOP NERFIN YR COUNTER

LOLCODE still makes me chuckle when I read it

kaeedo ยท 66 points ยท Posted at 20:04:57 on July 5, 2016 ยท (Permalink)

This is the first time I've seen actual LOLCODE code. I also now know how to write LOLCODE

spkr4thedead51 ยท 132 points ยท Posted at 20:20:47 on July 5, 2016 ยท (Permalink)*

as one of the original contributors to LOLCODE, you're welcome and I'm sorry.

edit - moment of nostalgia of the arguments we had over whether it should be strongly or loosely typed. wow.

throwaway_redstone ยท 42 points ยท Posted at 21:20:59 on July 5, 2016 ยท (Permalink)

moment of nostalgia of the arguments we had over whether it should be strongly or loosely typed. wow.

Of course LOLCODE should be stringly typed.

onthefence928 ยท 25 points ยท Posted at 22:02:00 on July 5, 2016 ยท (Permalink)

how hard was it to remind yourself you are taking it way too seriously?

spkr4thedead51 ยท 10 points ยท Posted at 02:57:46 on July 6, 2016 ยท (Permalink)

not very, thankfully.

jherazob ยท 2 points ยท Posted at 14:40:54 on July 6, 2016 ยท (Permalink)

as one of the original contributors to LOLCODE, you're welcome and I'm sorry.

DO NOT be sorry for this piece of greatness you brought to the world

spkr4thedead51 ยท 3 points ยท Posted at 14:44:45 on July 6, 2016 ยท (Permalink)

and in amusing bit of synchronicity, my facebook memories tell me that the 1.2 specification was announced today...9 years ago

edit - I have no idea what happened to my Game of Life implementation :(

parenthesis-bot ยท 4 points ยท Posted at 14:47:56 on July 6, 2016 ยท (Permalink)

:)


This is an autogenerated response. source | /u/HugoNikanor

jherazob ยท 1 points ยท Posted at 14:48:06 on July 6, 2016 ยท (Permalink)
gnutrino ยท 22 points ยท Posted at 20:29:48 on July 5, 2016 ยท (Permalink)

I have to say it is surprisingly readable.

anotherdonald ยท 192 points ยท Posted at 14:32:27 on July 5, 2016 ยท (Permalink)

Better than stackoverflow, but I missed the solution that involves setting up a matrix, filling the upper diagonal and transposing it.

overkill ยท 14 points ยท Posted at 19:00:45 on July 5, 2016 ยท (Permalink)

Got a link for that? I'd love to see it.

anotherdonald ยท 27 points ยท Posted at 19:11:09 on July 5, 2016 ยท (Permalink)

Unfortunately not. There must be a programming language that does something like that. Matlab, APL, something. I was disappointed not to see it. I would expect something like Matrix.upper(3).transpose().mult("Smile").print()

wolfgangdieter ยท 92 points ยท Posted at 20:48:36 on July 5, 2016 ยท (Permalink)

Not exactly what you suggested, but here is a possible solution in APL:

  DiagPrintโ†{โบ โบ โด (' ' (โต))[1+,โŒฝ(โณโบ) โˆ˜.โ‰ค (โณโบ)]}
  3 DiagPrint 'Smiles!'

  Smiles! Smiles! Smiles! 
  Smiles! Smiles!         
  Smiles!                 

Still a newb to the language so there are probably smarter ways of doing this, but damn it feels good once you actually come up with a solution.

Headsock ยท 113 points ยท Posted at 21:19:37 on July 5, 2016 ยท (Permalink)

What the fuck

DreadedDreadnought ยท 47 points ยท Posted at 22:26:00 on July 5, 2016 ยท (Permalink)

Given enough time, understanding the Perl solution could be possible, but this...

megatesla ยท 25 points ยท Posted at 05:22:13 on July 6, 2016 ยท (Permalink)

I can't even read it. Literally. The characters render as blank boxes.

TreSxNine ยท 2 points ยท Posted at 12:25:42 on July 6, 2016 ยท (Permalink)

Fuck you for making me laugh at work.

G3Kappa ยท 8 points ยท Posted at 08:20:15 on July 6, 2016 ยท (Permalink)

APL is actually quite nice once you get the hang of it. It's still a Write-Once-Read-Never language, just like Perl, but it's very expressive. I wish it had a bigger community.

Believe it or not, I think that more languages should learn from APL. It's concise yet very powerful, Python-level powerful, despite being so old that it was written on typewriters. It has a few successors, namely J and K, which use limited-range ASCII characters instead of what you see in the post above, if you might be interested.

[deleted] ยท 9 points ยท Posted at 06:17:31 on July 6, 2016 ยท (Permalink)

You'll love this.

LeBaegi ยท 2 points ยท Posted at 12:07:19 on July 6, 2016 ยท (Permalink)

What. The. Fuck.

theoldkitbag ยท 6 points ยท Posted at 23:23:41 on July 5, 2016 ยท (Permalink)

I believe, yes. Yes..... Yes, this is the appropriate response.

polish_niceguy ยท 41 points ยท Posted at 23:49:28 on July 5, 2016 ยท (Permalink)

I don't trust programming languages that require a special keyboard.

pyskell ยท 3 points ยท Posted at 01:44:58 on July 6, 2016 ยท (Permalink)

And that typing ball

baconuser098 ยท 1 points ยท Posted at 07:51:52 on July 7, 2016 ยท (Permalink)

You can have multiple languages on your keyboard, that's how our Greek keyboards work!

tabarra ยท 7 points ยท Posted at 01:59:36 on July 6, 2016 ยท (Permalink)

I don't have these buttons on my keyboard.

baconuser098 ยท 2 points ยท Posted at 07:52:30 on July 7, 2016 ยท (Permalink)

Alt-Codes my friend, you have everything on your keyboard :D

anotherdonald ยท 7 points ยท Posted at 20:54:58 on July 5, 2016 ยท (Permalink)

Nice!

BerserkerGreaves ยท 28 points ยท Posted at 22:10:55 on July 5, 2016 ยท (Permalink)

Yeโ‹h, โดretty โตeโณโณ โ† done if yโŠ–u โบsk mโˆˆ โˆ˜.โ‰ค โ†‘ โ†‘ โ†“ โ†“ โ† โ†’ โ† โ†’ B A

Headsock ยท 13 points ยท Posted at 22:55:18 on July 5, 2016 ยท (Permalink)

โตeโณโณ ]โบD

G3Kappa ยท 8 points ยท Posted at 08:24:41 on July 6, 2016 ยท (Permalink)

๐Ÿ‘Œ๐Ÿ‘€๐Ÿ‘Œ๐Ÿ‘€๐Ÿ‘Œ๐Ÿ‘€๐Ÿ‘Œ๐Ÿ‘€๐Ÿ‘Œ๐Ÿ‘€ goโŠ–d shit gโˆ˜เฑฆิ sHit๐Ÿ‘Œ thโบts โœ” some good๐Ÿ‘Œ๐Ÿ‘ŒshโณโŠค r|ght๐Ÿ‘Œ๐Ÿ‘Œtherโˆˆ๐Ÿ‘Œ๐Ÿ‘Œ๐Ÿ‘Œ rโณghtโœ”thโˆˆre โœ”โœ”if โณ do ฦฝโบาฏ so my sโˆˆlf ๐Ÿ’ฏ i say so ๐Ÿ’ฏ thaโŠคs โตhat โณm tโบlking โบbouโŠค rโˆฃght thโˆˆre rโณghโŠค there (chorus: สณแถฆแตสฐแต— แต—สฐแต‰สณแต‰) mMMMMแŽทะœ๐Ÿ’ฏ ๐Ÿ‘Œ๐Ÿ‘Œ ๐Ÿ‘ŒะO0เฑฆเฌ OโŠ–Oโˆ˜OโŠ–เฌ โŠ–Oโˆ˜ooแต’แต’แต’แต’โˆ˜แต’แต’แต’แต’๐Ÿ‘Œ ๐Ÿ‘Œ๐Ÿ‘Œ ๐Ÿ‘Œ ๐Ÿ’ฏ ๐Ÿ‘Œ ๐Ÿ‘€ ๐Ÿ‘€ ๐Ÿ‘€ ๐Ÿ‘Œ๐Ÿ‘ŒGood shit

Sinity ยท 3 points ยท Posted at 10:47:39 on July 6, 2016 ยท (Permalink)

How exactly people write in it? I mean, all these symbols.. how is it convenient?

PlasmaRoar ยท 1 points ยท Posted at 03:24:53 on July 6, 2016 ยท (Permalink)

"Are-are those greek letters? Is that a theta? Is that a temperature symbol, or a Japanese period!?"

siedler084 ยท 1 points ยท Posted at 08:52:07 on July 6, 2016 ยท (Permalink)

Alright, what the living fuck is that for a monstrosity?

dasonk ยท 15 points ยท Posted at 21:47:44 on July 5, 2016 ยท (Permalink)

Something like this in R?

> mat <- matrix("", 3, 3)
> mat[upper.tri(mat, diag = TRUE)] <- "Smile"
> mat
     [,1]    [,2]    [,3]   
[1,] "Smile" "Smile" "Smile"
[2,] ""      "Smile" "Smile"
[3,] ""      ""      "Smile"

Output could be cleaned up a bit but that's a simple exercise left for the user.

anotherdonald ยท 1 points ยท Posted at 08:39:33 on July 6, 2016 ยท (Permalink)

Nearly perfect!

PatrickWulfSwango ยท 3 points ยท Posted at 22:27:39 on July 5, 2016 ยท (Permalink)*

Something like that in Julia (transpose just turns it into a lower triangular matrix, so it's pointless):

 In [1]: m = [UpperTriangular(ones(3, 3))[i, j] == 1. ? "Smile!" : "" for i in 1:3, j in 1:3]
 Out [1]: 3x3 Array{ASCIIString,2}:
          "Smile!"  "Smile!"  "Smile!"
          ""        "Smile!"  "Smile!"
          ""        ""        "Smile!" 

Alternatively this works, although it gives ugly #undef's because there's no 0-element for Strings:

In [2]: UpperTriangular(fill("Smile!", (3, 3)))
Out [2]: 3x3 UpperTriangular{ASCIIString,Array{ASCIIString,2}}:
         "Smile!"     "Smile!"  "Smile!"
          #undef          "Smile!"  "Smile!"
          #undef       #undef       "Smile!"
anotherdonald ยท 2 points ยท Posted at 08:42:52 on July 6, 2016 ยท (Permalink)

Pipe it through sed, and you've got a perfect solution!

ProgramTheWorld ยท 1 points ยท Posted at 20:46:43 on July 5, 2016 ยท (Permalink)

NumPy?

VodkaHaze ยท 4 points ยท Posted at 22:26:40 on July 5, 2016 ยท (Permalink)

Numpy arrays don't take strings. You could use some convoluted workaround (representing string as array of chars as array of ints, or something like that). In fact that would be encouraged here.

Or you could use a pandas DF if you're a pussy

SportingSnow21 ยท 2 points ยท Posted at 02:38:44 on July 6, 2016 ยท (Permalink)

NumPy has a chararray for this.

import numpy as np

def printSmiles(n):
    s = np.chararray((n+1,n), itemsize=6)
    s[:] = ''
    s[n,:-1] = '\n'
    for i in range(n):
        s[i,:n-i] = 'smile!'
    return s.title().T.tostring().decode('utf-8').rstrip('\n')

print(printSmiles(3))
[deleted] ยท 75 points ยท Posted at 20:24:52 on July 5, 2016 ยท (Permalink)

I like this one:

Here's one in untyped lambda calculus. In principle it should work, though you'll need to write a compiler for this dialect. Shouldn't be too hard.

string := "Smile!"
newLine := "\n"
printStringNTimes := ฮปn . (if n = 1 then string else string + printStringNTimes(n-1)) + newLine
applyNTimes := ฮปn . (ฮปf . (if n = 1 then f(n) else f(n) + applyNTimes(n-1)(f)))
applyNTimes(3)(f)
CorruptedSoul ยท 108 points ยท Posted at 17:35:05 on July 5, 2016 ยท (Permalink)

Honestly, this is the best post I've ever seen in this sub!

muffinheart ยท 59 points ยท Posted at 19:07:53 on July 5, 2016 ยท (Permalink)

My personal favourite is the CSS one that spawned a dozen photoshops of different common CSS issues followed closely by the worst phone number input.

But I am a web dev so...

VeradilGaming ยท 9 points ยท Posted at 20:35:25 on July 5, 2016 ยท (Permalink)

Got a link?

dlbqlp ยท 32 points ยท Posted at 23:18:36 on July 5, 2016 ยท (Permalink)
VeradilGaming ยท 7 points ยท Posted at 23:32:03 on July 5, 2016 ยท (Permalink)

Holy shit, that's golden.

ANAL_ANARCHY ยท 1 points ยท Posted at 00:47:51 on July 6, 2016 ยท (Permalink)

1 - Original Post. 2 months old

I can't believe I missed all this.

[deleted] ยท 1 points ยท Posted at 12:08:08 on July 6, 2016 ยท (Permalink)

Jesus, was that original one actual production code? That's... hard to understand. If you know enough programming to create a drop down list (of anything), seems like you'd be smart enough to realize that is not a good idea. I guess it's some computer generated code by a lazy programmer? "I've got this script to generate a numeric list, fuck it phone numbers are numbers, generateAll(0,9999).

muffinheart ยท 7 points ยท Posted at 00:39:24 on July 6, 2016 ยท (Permalink)

Here's the CSS one since the other was already linked:

https://www.reddit.com/r/ProgrammerHumor/comments/3u5vwq/learning_css/

CorruptedSoul ยท 2 points ยท Posted at 01:01:55 on July 6, 2016 ยท (Permalink)

This is perfect. The most frustrating bugs in my JavaScript project are because of CSS.

DrummerHead ยท 159 points ยท Posted at 18:53:59 on July 5, 2016 ยท (Permalink)

Yes, it's actually programmer humor and it requires programming knowledge. That's why it's going to go under the radar.

Image of a tweet about being unable to close vim? 5500 upvotes

Udontlikecake ยท 3 points ยท Posted at 00:50:11 on July 6, 2016 ยท (Permalink)

Could you explain to us plebs please?

This is worse than seeing posts on /r/all in Swedish or German. I'm sure it's funny, but I don't know how

shadowX015 ยท 40 points ยท Posted at 02:43:17 on July 6, 2016 ยท (Permalink)

You're taking an intro to Mathematics class but you're stumped on this homework problem: 2 + 2 = ?

You go on Quora and ask someone to give the solution to you and show the work. You get responses from Ph.D's around the world providing you with highly advanced, multi-page proofs using everything from multivariate calculus to obscure subfields of number theory.

This is the programming equivalent.

DrummerHead ยท 15 points ยท Posted at 01:10:44 on July 6, 2016 ยท (Permalink)

The guy is explicitly asking for people to do his homework (a no-no in stackoverflow and generally a missing the point action) which is also a really easy task that could be solved with a recursive function.

So the users at SO decided to actually answer the question but in the most convoluted and cryptic ways, and in many cases using obscure or non-popular languages. Basically a classy "fuck you" since those answers are not what the teacher would be expecting at all and do not demonstrate understanding of the problem.

When you explain a joke you kinda kill it, but in the moment it's actually funny or at least chortle inducing.

Cheers!

numbermaniac ยท 8 points ยท Posted at 01:13:47 on July 6, 2016 ยท (Permalink)

But this is Quora, not SO.

tabarra ยท 16 points ยท Posted at 02:02:15 on July 6, 2016 ยท (Permalink)

OHHHHH that's why I didn't see any "Use JQuery for that" answers.

Stromovik ยท 38 points ยท Posted at 17:52:32 on July 5, 2016 ยท (Permalink)

Needs :

  • Algol
  • Cobol ( ok it has that )
  • CUDA
  • BASIC
  • Lisp ( has that too )
kingatomic ยท 22 points ยท Posted at 19:15:54 on July 5, 2016 ยท (Permalink)

And Malbolge.

TempestasTenebrosus ยท 45 points ยท Posted at 21:40:17 on July 5, 2016 ยท (Permalink)
D'`r#9"7mH:Wy76fRttPO/_nmlkGY'Wfe#zya}`{)s[wvonm3qpRng-NMiha'_dc\"`B^W{[=<XWVONrRKPIHGFj-CHG@?cCB$@98=<;4Xy76543,P0/o-&Jk#('~D$dcy?}_uzsxqpo5srTSihg-edcb(f_^$bD`YXW\UyYR:uUNSRQPINGk.JIHGF?cCB$@98=<;4Xy76543,P0/o-&Jk#('~D$dcy?}_uzsxqpo5srTSihg-edcb(f_^$bD`YXW\UyYR:uUNSRQPINGk.JIHGF?cCB$@98=<;4Xy76543,P0/o-&Jk#('~D1

In the interest of full disclosure; I used a generator

parenthesis-bot ยท 52 points ยท Posted at 21:43:42 on July 5, 2016 ยท (Permalink)

))))


This is an autogenerated response. source | /u/HugoNikanor

TempestasTenebrosus ยท 73 points ยท Posted at 21:45:16 on July 5, 2016 ยท (Permalink)

There was an attempt

AbigailLilac ยท 10 points ยท Posted at 23:21:41 on July 5, 2016 ยท (Permalink)

:(

parenthesis-bot ยท 30 points ยท Posted at 23:24:07 on July 5, 2016 ยท (Permalink)

:)


This is an autogenerated response. source | /u/HugoNikanor

Weznon ยท 10 points ยท Posted at 03:05:26 on July 6, 2016 ยท (Permalink)

I like this bot

shelvac2 ยท 3 points ยท Posted at 20:06:41 on July 6, 2016 ยท (Permalink)

So do I. Except that it gives me the urge to invoke it. (Like this

parenthesis-bot ยท 2 points ยท Posted at 20:09:01 on July 6, 2016 ยท (Permalink)

)


This is an autogenerated response. source | /u/HugoNikanor

[deleted] ยท 5 points ยท Posted at 05:37:49 on July 6, 2016 ยท (Permalink)*

[deleted]

ec1548270af09e005244 ยท 3 points ยท Posted at 06:38:21 on July 6, 2016 ยท (Permalink)

It's more like the random entity generator in DF created a programming language based off of the Hidden Fun Stuff.

ZettTheArcWarden ยท 5 points ยท Posted at 19:33:10 on July 5, 2016 ยท (Permalink)

Piet, FORTRAN

Tensorflow are my wishes for this list

!RemindMe 10 hours

Thorbinator ยท 9 points ยท Posted at 01:22:00 on July 6, 2016 ยท (Permalink)

Here's an overengineered tensorflow problem to fizzbuzz that will probably sate your desires.

http://joelgrus.com/2016/05/23/fizz-buzz-in-tensorflow/

RemindMeBot ยท 1 points ยท Posted at 19:33:59 on July 5, 2016 ยท (Permalink)*

I will be messaging you on 2016-07-06 05:33:53 UTC to remind you of this link.

4 OTHERS CLICKED THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


FAQs Custom Your Reminders Feedback Code Browser Extensions
R0B0_Ninja ยท 6 points ยท Posted at 20:52:47 on July 5, 2016 ยท (Permalink)

And ArnoldC! Was deeply disappointed to not find it among the answers.

bplboston17 ยท 1 points ยท Posted at 22:09:36 on July 5, 2016 ยท (Permalink)

BASIC as in Visual Basic? I did CTRL+F Visual Basic and didnt see it in there.

mspk7305 ยท 3 points ยท Posted at 01:46:32 on July 6, 2016 ยท (Permalink)

It's programming, not necromancy.

ShadoWalker3065 ยท 1 points ยท Posted at 01:55:43 on July 6, 2016 ยท (Permalink)

I didn't see it either. Wanted to make a Quora account just for that...

Oranges13 ยท 1 points ยท Posted at 03:35:25 on July 6, 2016 ยท (Permalink)

There was one that looked like Apple BASIC.

Stromovik ยท 1 points ยท Posted at 19:48:34 on July 6, 2016 ยท (Permalink)

As in from qbasic to visualbasic.net

ANAL_ANARCHY ยท 1 points ยท Posted at 01:12:25 on July 6, 2016 ยท (Permalink)

I don't see assembly anywhere either. Probably closest was the guy who suggested just writing the necessary code to the drives beginning.

ShadoWalker3065 ยท 1 points ยท Posted at 01:58:16 on July 6, 2016 ยท (Permalink)

CUDA

Isn't CUDA just C/C++?

fb39ca4 ยท 1 points ยท Posted at 06:39:04 on July 6, 2016 ยท (Permalink)

But it runs on the GPU. It added printf a few versions ago.

dummy-head ยท 28 points ยท Posted at 22:05:04 on July 5, 2016 ยท (Permalink)

Surprised no one answered "Just use jQuery"

tabarra ยท 13 points ยท Posted at 02:10:42 on July 6, 2016 ยท (Permalink)

Because that's not stack overflow.

TheCodingEthan ยท 26 points ยท Posted at 18:59:06 on July 5, 2016 ยท (Permalink)

print('Hello!', end=''

#waiting for the bot

parenthesis-bot ยท 41 points ยท Posted at 19:03:03 on July 5, 2016 ยท (Permalink)

)


This is an autogenerated response. source | /u/HugoNikanor

TheCodingEthan ยท 89 points ยท Posted at 19:24:10 on July 5, 2016 ยท (Permalink)

;

This is a manually posted response.

TheTigerMaster ยท 47 points ยท Posted at 19:40:19 on July 5, 2016 ยท (Permalink)

This is an automatically posted response -- because none of us really have free will. Our neurobiology is simply responding to the stimuli in the environment around us. We are just robots, or glorified insects in the body of a mammal.

[deleted] ยท 20 points ยท Posted at 19:54:23 on July 5, 2016 ยท (Permalink)

I would say....really complex finite state machines.

amunak ยท 8 points ยท Posted at 20:15:17 on July 5, 2016 ยท (Permalink)

WE ARE HUMAN

See also /r/totallynotrobots fellow human.

bplboston17 ยท 1 points ยท Posted at 22:11:31 on July 5, 2016 ยท (Permalink)*

nice.

dutchcow ยท 1 points ยท Posted at 11:32:53 on July 6, 2016 ยท (Permalink)

Didn't have time to test, but I think something like this will work:

Public Function PrintSmile()

Dim x As Integer
Dim y As Integer
Dim z As Integer

For x = 0 To 3: Debug.Print ("Smile!"): Next x
For y = 0 To 2: Debug.Print ("Smile!"): Next y
For z = 0 To 1: Debug.Print ("Smile!"): Next z

End Function
bplboston17 ยท 1 points ยท Posted at 08:34:24 on July 7, 2016 ยท (Permalink)

been awhile since used VB but looks right to me.

MirRelevant ยท 20 points ยท Posted at 20:49:25 on July 5, 2016 ยท (Permalink)

I like the other solutions, but they all require an operating system which is a bit of pain to install for something as simple as this.

...

Which, if you assemble it (use NASM) and write it to the first sector of a disk, should remove all that nasty OS overhead.

This is just amazing. Also,

This is probably not the most efficient way to do it (in brainfuck, I mean), but it works.

Thank you for that link. I actually laughed out loud

matjojo1000 ยท 40 points ยท Posted at 18:55:38 on July 5, 2016 ยท (Permalink)

TIL Brainfuck is a thing

rnjkvsly ยท 29 points ยท Posted at 19:42:57 on July 5, 2016 ยท (Permalink)

If you want to play with genetic algorithms it's a really good start. The "DNA" is just the brainfuck program!

AraneusAdoro ยท 25 points ยท Posted at 21:47:26 on July 5, 2016 ยท (Permalink)*

Dude...

Welp, this is my weekend set!

Edit: If anyone wants to play along at home, here are the rules:

  • goal: a program that reads two numbers and prints their sum;

  • I/O is done directly through byte values (66 is '66', not 'B');

  • genome is ,>,< followed by a random string of .<>+-[] of length 40;

  • ignore all ] with no matching [;

  • put a ] at the end of the program for all unmatched [;

  • fitness function is (n-1)*256 + e, where n is number of outputs produced by the program, e is sum of differences (absolute values) of the outputs from the desired output. Fitness function is evaluated 100 times with random inputs (each of which is โ‰ฅ 0 and sum of which is โ‰ค 255), the results are summed. Its value is considered to be INT_MAX for a program that doesn't finish after 1000 cycles or produces no output.

[deleted] ยท 10 points ยท Posted at 22:17:32 on July 5, 2016 ยท (Permalink)*

[deleted]

AraneusAdoro ยท 6 points ยท Posted at 22:21:35 on July 5, 2016 ยท (Permalink)

Yup. Shouldn't be too hard.

[deleted] ยท 8 points ยท Posted at 22:23:14 on July 5, 2016 ยท (Permalink)*

[deleted]

AraneusAdoro ยท 13 points ยท Posted at 22:33:02 on July 5, 2016 ยท (Permalink)*

Sure.

What you have is:

  • a "population" of some N "genomes" (which is some representation of a potential solution, usually an array of numbers);

  • a method of "breeding" (I'm going to use 1-point crossover, which is basically splitting two genomes at a certain point, say, after 15th character (in reality this would be a random point) and exchanging parts) and mutation;

  • a fitness function that represents selective pressure.

Algorithm:

  1. evaluate each creature;

  2. select top 50% for breeding;

  3. breed;

  4. mutate 5% or so;

  5. repeat until fitness reaches desired value for some individual, that creature is your solution.

There are multiple flavours, so this is not the genetic algorithm, but the gist is this.

FM-96 ยท 2 points ยท Posted at 02:33:47 on July 6, 2016 ยท (Permalink)

Okay, probably a stupid question, but...

How would that breeding process possibly work in this scenario? If you break two programs apart and put them together differently, aren't you just breaking both of them?

AraneusAdoro ยท 2 points ยท Posted at 06:20:01 on July 6, 2016 ยท (Permalink)

Yep. Which is why I'm preserving both of the original programs in the new generation.

In fact, this is what's going to happen with most tasks solved by GA. But through sheer number of crossovers some of them will improve on overall fitness of the population.

rnjkvsly ยท 3 points ยท Posted at 22:33:15 on July 5, 2016 ยท (Permalink)*

Traditional genetic algorithms have four stages;

Initialisation (can be random, or can use heuristics to start "closer" to the expected result),

Selection, which uses a fitness function to rank the genomes and the worst are removed (sometimes the worst n are kept to add variation in the generation stages).

This brings us to the generation stages, which include crossover and mutation.

Crossover involves taking two genomes and splicing them together, in the same way that parent pass their children 13 chromosomes each. The splicing can be done in different ways and tends not to affect the overall result.

Mutation, some parts of the genome are changed, for example 10%. Consider the case of of the genome being represented by a binary string. Mutation would flip some of the bits randomly, just like in nature.

Put this stuff together and things start to 'learn'.

Edit: bits not bytes

Garfong ยท 1 points ยท Posted at 23:22:20 on July 5, 2016 ยท (Permalink)

IIRC it's:

  1. Create N random solutions
  2. Modify one of the solutions by either: randomly changing part of the solution (i.e. mutating); or replacing a portion of the solution with a portion of another solution (i.e. breeding).
  3. After a few modifications, check how good the new solutions are vs. other solutions. Randomly keep N solutions, weighted towards keeping the best solutions.

Basically it's a fancy way of doing guess and check. The trick is picking good ways of doing the "random" steps.

rnjkvsly ยท 5 points ยท Posted at 22:18:29 on July 5, 2016 ยท (Permalink)

You can get more complex that that. It doesn't take too long to generate a program which can output the first n fibonacci numbers and a little more time to get a program which generates them all.

I also played with prime generation, but that was a little bit more murky. Also this was years ago and in php-cli so speed wasn't exactly phenomenal.

Also genome was the word I was looking for!

AraneusAdoro ยท 3 points ยท Posted at 22:21:01 on July 5, 2016 ยท (Permalink)

I'm erring on the side of caution here. If sum finishes too quick, Fibonacci is the next step for sure!

rnjkvsly ยท 1 points ยท Posted at 22:22:50 on July 5, 2016 ยท (Permalink)

May the force be with you

ifindxss ยท 3 points ยท Posted at 08:33:05 on July 6, 2016 ยท (Permalink)

Keep us updated.

BerserkerGreaves ยท 2 points ยท Posted at 22:13:31 on July 5, 2016 ยท (Permalink)

Interesting idea. Got any examples of something like that?

rnjkvsly ยท 2 points ยท Posted at 22:21:27 on July 5, 2016 ยท (Permalink)

Unfortunately not, this was several years ago when I was still in high school (secondary school for us brits).

It's simple to think about it terms of a brute-force, as there aren't many ways to create a syntax error, only adding (edit: or removing!) the characters which relate directly to a command.

You can then move forwards to using heuristics and more machine-learning based approaches which increases performance significantly, but I'll leave that as a task for the reader :)

BerserkerGreaves ยท 2 points ยท Posted at 10:17:18 on July 6, 2016 ยท (Permalink)

Can you please elaborate on what problem were you solving with such approach? The idea is really cool, but it seems to me that even generating a program to output "Hello, world!" would be quite challenging

rnjkvsly ยท 2 points ยท Posted at 11:05:05 on July 6, 2016 ยท (Permalink)

In the case of the hello world problem, a fitness function could test against the length of string generated and then use something like the Levenshtein distance of the outputted string and the desired (in this case "hello, world!") to further rank the genomes.

Add in the other aspects of genetic algorithms (see my other comment in a different thread branch) and you will have something that will continue to get closer to the desired program as generations increase.

On mobile at work so if you want a more in-depth explanation I can later on.

BerserkerGreaves ยท 1 points ยท Posted at 15:30:09 on July 6, 2016 ยท (Permalink)

Thanks for the response! I definitely do want a more in-depth explanation!

Twirrim ยท 14 points ยท Posted at 19:57:50 on July 5, 2016 ยท (Permalink)

Have you seen whitespace before? By far my favourite WTF language. http://www.99-bottles-of-beer.net/language-whitespace-154.html

Free_Math_Tutoring ยท 2 points ยท Posted at 20:00:12 on July 5, 2016 ยท (Permalink)

I learned about Seed today. Holy fuck.

matjojo1000 ยท 1 points ยท Posted at 10:17:29 on July 6, 2016 ยท (Permalink)

This is sick, what the fuck

[deleted] ยท 5 points ยท Posted at 19:46:46 on July 5, 2016 ยท (Permalink)

There exist a plethora af esoteric programming languages that are of .... quastionable usability. Should look them up, make for a good read.

GearBent ยท 8 points ยท Posted at 20:10:50 on July 5, 2016 ยท (Permalink)

My favorite is Babbage.

takingphotosmakingdo ยท 2 points ยท Posted at 20:45:14 on July 5, 2016 ยท (Permalink)

didn't someone make one that was essentially references to Arnold Schwarzenegger quotes? Everytime they wanted to declare a var it was something like "it's not a tumor(" and every time they started a function it was "get to the choppah(" I'll have to find it now..

parenthesis-bot ยท 26 points ยท Posted at 20:48:29 on July 5, 2016 ยท (Permalink)

))


This is an autogenerated response. source | /u/HugoNikanor

tarpeyd12 ยท 1 points ยท Posted at 21:58:22 on July 5, 2016 ยท (Permalink)

Best bot I've seen in a while.

[deleted] ยท 7 points ยท Posted at 22:18:20 on July 5, 2016 ยท (Permalink)

You have to feed it smileys :(

parenthesis-bot ยท 6 points ยท Posted at 22:18:51 on July 5, 2016 ยท (Permalink)

:)


This is an autogenerated response. source | /u/HugoNikanor

tarpeyd12 ยท 1 points ยท Posted at 22:30:40 on July 5, 2016 ยท (Permalink)

Ok! (:

parenthesis-bot ยท 2 points ยท Posted at 22:33:55 on July 5, 2016 ยท (Permalink)

)


This is an autogenerated response. source | /u/HugoNikanor

tarpeyd12 ยท 2 points ยท Posted at 22:52:45 on July 5, 2016 ยท (Permalink)

:(

parenthesis-bot ยท 2 points ยท Posted at 22:54:00 on July 5, 2016 ยท (Permalink)

:)


This is an autogenerated response. source | /u/HugoNikanor

matjojo1000 ยท 1 points ยท Posted at 10:14:47 on July 6, 2016 ยท (Permalink)

/u/HugoNikanor

This is wrong I think? The ':' should be on the outside not?

HugoNikanor ยท 1 points ยท Posted at 10:45:24 on July 6, 2016 ยท (Permalink)

Sadness is best countred with happiness

matjojo1000 ยท 1 points ยท Posted at 10:46:28 on July 6, 2016 ยท (Permalink)

ya can't counter that :)

HugoNikanor ยท 1 points ยท Posted at 11:06:52 on July 6, 2016 ยท (Permalink)

not I, but my bot can

SavvySillybug ยท 10 points ยท Posted at 20:50:15 on July 5, 2016 ยท (Permalink)

ArnoldC?

takingphotosmakingdo ยท 2 points ยท Posted at 21:59:21 on July 5, 2016 ยท (Permalink)

yeah that sounds familiar

Ralph_Charante ยท 1 points ยท Posted at 22:18:40 on July 5, 2016 ยท (Permalink)
Goheeca ยท 1 points ยท Posted at 21:14:16 on July 5, 2016 ยท (Permalink)

Yup, a starting point here.

[deleted] ยท 3 points ยท Posted at 21:18:18 on July 5, 2016 ยท (Permalink)

My personal recommendations for esoteric languages are Befunge and INTERCAL. Befunge is 2 dimensional, and INTERCAL code won't compile if you don't say please enough (or out you say it too much).

thlst ยท 2 points ยท Posted at 00:42:41 on July 6, 2016 ยท (Permalink)
Chameleon3 ยท 1 points ยท Posted at 21:43:59 on July 5, 2016 ยท (Permalink)

I love brainfuck! It's so stupid, yet weirdly fun to write in. I solved the first problem of Project Euler and did a write up about it here if you're interested.

jherazob ยท 1 points ยท Posted at 14:43:08 on July 6, 2016 ยท (Permalink)

If you do get the hang of BF (if you get your brain fucked i guess), try Cherry Blossom. Basically turn BF programs into haikus.

matjojo1000 ยท 2 points ยท Posted at 14:48:42 on July 6, 2016 ยท (Permalink)

wow, wow, wow. I have little to no words for this.

KamiKagutsuchi ยท 26 points ยท Posted at 18:00:29 on July 5, 2016 ยท (Permalink)

I'm disappointed in the lack of a whitespace implementation.

svantevid ยท 23 points ยท Posted at 18:52:21 on July 5, 2016 ยท (Permalink)*

I just felt it needs a Pascal version.

program smile;
var i,j: integer;
begin
for i:= from 3 downto 1 do
    begin
    for j:= from 1 to i do
        write('smile!');
    writeln();
    end;
end.
Siniroth ยท 16 points ยท Posted at 19:25:34 on July 5, 2016 ยท (Permalink)

As someone with extremely minimal programming knowledge, should that be as simple to follow as it is?

hellshot8 ยท 21 points ยท Posted at 19:37:33 on July 5, 2016 ยท (Permalink)

Yes, it's an extremely simple program. Programming 101 stuff

dipique ยท 1 points ยท Posted at 23:38:58 on July 5, 2016 ยท (Permalink)

Yep! And once you learn it in one language, all the others start to make sense. Same thing in C#:

static void SmileWriterGizmo2000()
{
    for (int i = 3;   //for every value of integer i starting at 3
             i >= 1;  //while i is greater than or equal to 1
             i--)     //decrementing i by 1
    {                 //run the following code:
        for (int j = 1; j <= i; j++)
        {
            Console.Write('smile!);
        }
        Console.Write(Environment.NewLine);
    }
}
Merens ยท 5 points ยท Posted at 19:57:21 on July 5, 2016 ยท (Permalink)
for i:= from 3 downto 1 do
    begin
    for j:= from 1 to 3 do
        write('smile!');
    writeln();
    end;

Shouldn't the second loop go from 1 to i?

svantevid ยท 2 points ยท Posted at 20:09:32 on July 5, 2016 ยท (Permalink)

Thanks, fixed.

stonecolddevin ยท 2 points ยท Posted at 08:07:38 on July 6, 2016 ยท (Permalink)

Pascal was the first language I ever wrote code in. Such fond memories.

svantevid ยท 1 points ยท Posted at 11:16:09 on July 6, 2016 ยท (Permalink)

Mine too. But I barely use it now.

SantaCruzDad ยท 1 points ยท Posted at 07:25:13 on July 6, 2016 ยท (Permalink)

You will be deducted some marks for this answer, as you didn't read the question carefully enough:

Have the program define a function that displays the string Smile! once, and have the program use the function as often as needed.

svantevid ยท 2 points ยท Posted at 07:43:42 on July 6, 2016 ยท (Permalink)

Oh snap... Good thing I'm already done with programming courses. I also forgot to use the upper case S.

[deleted] ยท 10 points ยท Posted at 21:04:25 on July 5, 2016 ยท (Permalink)*

[deleted]

hunyeti ยท 10 points ยท Posted at 07:16:20 on July 6, 2016 ยท (Permalink)

I did, in many real world JavaEE project

IskaneOnReddit ยท 16 points ยท Posted at 18:44:25 on July 5, 2016 ยท (Permalink)

Matlab version in case somebody needs it:

N = 3;
string = 'Smile!';
length = numel(string);
flipud(tril(repmat(string, length * N, N))(length:length:end,:))
UNIScienceGuy ยท 6 points ยท Posted at 21:32:25 on July 5, 2016 ยท (Permalink)

Every MATLAB program needs repmat.

Sarasun ยท 1 points ยท Posted at 22:15:56 on July 10, 2016 ยท (Permalink)

Pretty() to display your equation. Such a beautiful functionality

UNIScienceGuy ยท 1 points ยท Posted at 09:44:09 on July 12, 2016 ยท (Permalink)

You could even say it's a pretty functionality.

[deleted] ยท 7 points ยท Posted at 19:57:21 on July 5, 2016 ยท (Permalink)

[deleted]

punisher1005 ยท 2 points ยท Posted at 23:17:36 on July 5, 2016 ยท (Permalink)

I believe in you.

Diamant2 ยท 6 points ยท Posted at 19:12:32 on July 5, 2016 ยท (Permalink)

there should be a Piet Version

exoxe ยท 4 points ยท Posted at 20:01:54 on July 5, 2016 ยท (Permalink)

There's always that onehundreds of smart-asses.

djlemma ยท 3 points ยท Posted at 20:49:15 on July 5, 2016 ยท (Permalink)

This is pretty awesome. It makes me want to learn a bunch of funky programming languages like LOLCODE.

I didn't scroll through EVERYTHING, but did anybody go back to childhood roots and submit code in something like apple basic, with line numbers, GOTO's, and GOSUB's?

Oranges13 ยท 2 points ยท Posted at 03:36:59 on July 6, 2016 ยท (Permalink)

Someone totally did!

redisforever ยท 1 points ยท Posted at 00:53:11 on July 6, 2016 ยท (Permalink)

I was considering Turing, as that's my only real programming experience, from high school.

[deleted] ยท 5 points ยท Posted at 21:55:47 on July 5, 2016 ยท (Permalink)

Hahaha. Radu Lupaescu's answer gave me a Game of Thrones vibe. "frownedupon", "imsolazy" .. "shame" ding ding ding "shame"

cool_BUD ยท 6 points ยท Posted at 01:42:57 on July 6, 2016 ยท (Permalink)

((())(()(()((()))()(((())))()((()()()()()()((()))(((((

parenthesis-bot ยท 5 points ยท Posted at 01:44:36 on July 6, 2016 ยท (Permalink)

))))))))))


This is an autogenerated response. source | /u/HugoNikanor

SamJSchoenberg ยท 1 points ยท Posted at 15:23:43 on July 6, 2016 ยท (Permalink)

(()()(((()((())((()((

parenthesis-bot ยท 1 points ยท Posted at 15:28:02 on July 6, 2016 ยท (Permalink)

)))))))))


This is an autogenerated response. source | /u/HugoNikanor

Shelena84 ยท 8 points ยท Posted at 19:29:02 on July 5, 2016 ยท (Permalink)

I am disappointed, I did not see any Prolog :(.

parenthesis-bot ยท 43 points ยท Posted at 19:33:12 on July 5, 2016 ยท (Permalink)

:)


This is an autogenerated response. source | /u/HugoNikanor

Goheeca ยท 8 points ยท Posted at 22:59:13 on July 5, 2016 ยท (Permalink)*

That's what I'm able to come up with:

+/u/CompileBot Prolog (swi) (swipl 5.6.64)

smile :- write('Smile!').

smiles(N) :-
    between(1, N, Line), (
        between(Line, N, Count),
        smile,
        (Count = N, nl)
    ), false.

:- smiles(3); true, halt.
CompileBot ยท 8 points ยท Posted at 22:59:57 on July 5, 2016 ยท (Permalink)*

Output:

Smile!Smile!Smile!
Smile!Smile!
Smile!

source | info | git | report

EDIT: Recompile request by Goheeca

Shelena84 ยท 3 points ยท Posted at 05:57:42 on July 6, 2016 ยท (Permalink)

It has been a while since I have written Prolog, but it looks good! Not disappointed anymore!

Boouurns ยท 5 points ยท Posted at 21:02:12 on July 5, 2016 ยท (Permalink)

I actually understand the perl one....dear god what have I done with my life...

pta2002 ยท 3 points ยท Posted at 21:48:10 on July 5, 2016 ยท (Permalink)

Here's some obfuscated PHP! I could have probably done it worse, though.

+/u/CompileBot php

<?php
function aaaa($aaaaa=3) {
    aaaaaa($aaaaa);
    if ($aaaaa<=1) {
        return;
    } else {
        aaaa($aaaaa-1);
    }
}

function aaaaaa($aaaaaaa){
    $a=substr((string)array(),0,1);
    $aa=chr(ord($a)+ceil(pi()*10));
    $aaa=chr(ord($a)-ceil(pi()*10));
    echo chr(ord($a)+18);
    echo chr(ord($aa)+12);
    echo chr(ord($aa)+8);
    echo chr(ord($aa)+11);
    echo chr(ord($aa)+4);
    echo $aaa;
    if ($aaaaaaa<=1) {
        echo '<br>';
        return;
    } else {
        aaaaaa($aaaaaaa-1);
    }
}

aaaa();    
CompileBot ยท 7 points ยท Posted at 21:49:27 on July 5, 2016 ยท (Permalink)

Output:

Smile!Smile!Smile!<br>Smile!Smile!<br>Smile!<br>PHP Notice:  Array to string conversion in /home/S8e1ro/prog.php on line 12
PHP Notice:  Array to string conversion in /home/S8e1ro/prog.php on line 12
PHP Notice:  Array to string conversion in /home/S8e1ro/prog.php on line 12
PHP Notice:  Array to string conversion in /home/S8e1ro/prog.php on line 12
PHP Notice:  Array to string conversion in /home/S8e1ro/prog.php on line 12
PHP Notice:  Array to string conversion in /home/S8e1ro/prog.php on line 12

source | info | git | report

pta2002 ยท 11 points ยท Posted at 21:51:11 on July 5, 2016 ยท (Permalink)

PHP notice... oh. Well, it works on a browser ยฏ\_(ใƒ„)_/ยฏ

j_selby ยท 15 points ยท Posted at 06:09:40 on July 6, 2016 ยท (Permalink)

"It works for me"

Ticket closed

rahulroy9202 ยท 3 points ยท Posted at 07:37:31 on July 6, 2016 ยท (Permalink)

I think you guys will love - http://codegolf.stackexchange.com/

talexx ยท 13 points ยท Posted at 19:03:43 on July 5, 2016 ยท (Permalink)

It looks like nobody is reading the assignment. 80% of answers misssed "define a function" part. Though I should admit it is really close to what happens in the real world. It doesn't matter how clearly written specification you have. Somebody definetely fucks something up somewhere.

gnutrino ยท 29 points ยท Posted at 20:32:53 on July 5, 2016 ยท (Permalink)

It compiles, quit your whining. We'll ship it and blame the client if anything breaks.

talexx ยท 2 points ยท Posted at 12:10:22 on July 6, 2016 ยท (Permalink)

โ†‘ Look guys, PM in the thread โ†‘

kushangaza ยท 1 points ยท Posted at 01:43:45 on July 6, 2016 ยท (Permalink)

They defined a function, manually inlined it, and removed dead code.

RagingNerdaholic ยท 3 points ยท Posted at 23:15:53 on July 5, 2016 ยท (Permalink)

Well, I mean, to be fair, that is pretty simple for Perl.

ChezMere ยท 3 points ยท Posted at 03:23:26 on July 6, 2016 ยท (Permalink)

Here's one in untyped lambda calculus. In principle it should work, though you'll need to write a compiler for this dialect. Shouldn't be too hard.

green_meklar ยท 3 points ยท Posted at 08:40:26 on July 6, 2016 ยท (Permalink)

I don't know brainfuck, so I just used Javascript instead:

data:text/html,<script type="text/javascript">
function go()
{
 var text="Frown!";
 var count=parseInt(prompt("Enter how many smiles you want:"));
 for(var i=count;i>0;i--)
 {
  for(var j=i;j>0;j--)
  {
   document.write(transformText(text));
  }
  document.write("<br>");
 }
}
function transformText(s)
{
 var r="";
 for(var i=0;i<s.length;i++)
 {
  r=r+String.fromCharCode(transformChar(s.charCodeAt(i)));
 }
 return r;
}
function transformChar(n)
{
 return (((1&(n>>>((1<<(1<<1))|(1<<1))))<<((1<<(1<<1))|(1<<1)))|((1&(~((n>>>((1<<(1<<1))|(1<<1)))&(~((n>>>((1<<(1<<1))|1))&1)))))<<((1<<(1<<1))|1))|((1&((n>>>((1<<(1<<1))|(1<<1)))&(~((n>>>((1<<(1<<1))|1))&1))))<<(1<<(1<<1)))|((1&(((n>>>(1<<(1<<1)))&1)|((n>>>((1<<1)|1))&n&1)))<<((1<<1)|1))|((1&(((n>>>(1<<(1<<1)))&1)|((n>>>((1<<1)|1))&(~n)&1)))<<(1<<1))|((1&(((n>>>((1<<(1<<1))|(1<<1)))^(n>>>((1<<(1<<1))|1)))&(~n)))<<1)|((1&(~((n>>>(1<<(1<<1)))&(n>>>(1<<1)))))<<0));
}
go();
</script>
[deleted] ยท 7 points ยท Posted at 17:28:30 on July 5, 2016 ยท (Permalink)

No assembler version ? :(

[deleted] ยท 52 points ยท Posted at 17:32:05 on July 5, 2016 ยท (Permalink)

Be the change you want to see in the world

lx45803 ยท 24 points ยท Posted at 17:45:18 on July 5, 2016 ยท (Permalink)

What's wrong with this one?

parenthesis-bot ยท 18 points ยท Posted at 17:32:43 on July 5, 2016 ยท (Permalink)

:)


This is an autogenerated response. source | /u/HugoNikanor

nemec ยท 19 points ยท Posted at 00:13:12 on July 6, 2016 ยท (Permalink)

+/u/CompileBot python

print chr(ord(')')-1)
CompileBot ยท 11 points ยท Posted at 00:14:03 on July 6, 2016 ยท (Permalink)

Output:

(

source | info | git | report

parenthesis-bot ยท 15 points ยท Posted at 00:14:14 on July 6, 2016 ยท (Permalink)

)


This is an autogenerated response. source | /u/HugoNikanor

KamiKagutsuchi ยท 8 points ยท Posted at 17:59:21 on July 5, 2016 ยท (Permalink)

(:

parenthesis-bot ยท 10 points ยท Posted at 18:02:49 on July 5, 2016 ยท (Permalink)

)


This is an autogenerated response. source | /u/HugoNikanor

Pvt_Haggard_610 ยท 1 points ยท Posted at 18:21:05 on July 5, 2016 ยท (Permalink)*

What is your purpose.. (

[deleted] ยท 18 points ยท Posted at 19:28:37 on July 5, 2016 ยท (Permalink)*

With the subreddit full of programmatically minded people, open parentheses bother people, so it closes them so none of us go insane.

Kruithne ยท 2 points ยท Posted at 14:33:50 on July 6, 2016 ยท (Permalink)

more insane*.

parenthesis-bot ยท 7 points ยท Posted at 18:22:53 on July 5, 2016 ยท (Permalink)

)


This is an autogenerated response. source | /u/HugoNikanor

[deleted] ยท -1 points ยท Posted at 19:24:44 on July 5, 2016 ยท (Permalink)

To spam

AbigailLilac ยท 3 points ยท Posted at 22:10:26 on July 5, 2016 ยท (Permalink)

(

parenthesis-bot ยท 2 points ยท Posted at 22:13:48 on July 5, 2016 ยท (Permalink)

)


This is an autogenerated response. source | /u/HugoNikanor

giant_panda_slayer ยท 4 points ยท Posted at 19:35:58 on July 5, 2016 ยท (Permalink)

Not you, parenthesis-bot's (:

parenthesis-bot ยท 3 points ยท Posted at 19:38:13 on July 5, 2016 ยท (Permalink)

)


This is an autogenerated response. source | /u/HugoNikanor

[deleted] ยท -6 points ยท Posted at 19:37:08 on July 5, 2016 ยท (Permalink)

Thats what I meant, his purpose is to spam.

kobbled ยท 2 points ยท Posted at 20:06:05 on July 5, 2016 ยท (Permalink)

LOLcode is such a blast to the past

Night_Thastus ยท 2 points ยท Posted at 21:00:31 on July 5, 2016 ยท (Permalink)

Is there an assembly version too? Jesus.

higgimonster ยท 2 points ยท Posted at 21:47:06 on July 5, 2016 ยท (Permalink)

As an auto mechanic who dabbled with coding a long time ago I really enjoy these super obscure coding. Like at one point in my childhood I was so good at TI-Basic I could pull off shit like this.

I am glad to know that nobody really knows how to do these things.

UnchainedMundane ยท 2 points ยท Posted at 21:57:49 on July 5, 2016 ยท (Permalink)

I am glad to know that nobody really knows how to do these things.

Not sure I understand... they all just wrote their own obfuscated answer to the question, surely they know how to do it if they managed that?

higgimonster ยท 3 points ยท Posted at 21:59:51 on July 5, 2016 ยท (Permalink)

I don't think I understood what I was trying to say either. I was just really enjoying the code and the comments here.

bitse ยท 2 points ยท Posted at 21:53:08 on July 5, 2016 ยท (Permalink)

I have to stop reading this thread so I don't die from trying to contain my laughter on the subway.

[deleted] ยท 1 points ยท Posted at 23:07:22 on July 5, 2016 ยท (Permalink)

I just kept scrolling and scrolling and couldn't reach the bottom. Then I realized the page had (near) infinite scroll.

[deleted] ยท 2 points ยท Posted at 02:25:28 on July 6, 2016 ยท (Permalink)*

[deleted]

bxblox ยท 1 points ยท Posted at 03:31:16 on July 6, 2016 ยท (Permalink)

It's kind of cheating. Once you know the basics you can BS a solution without learning the concepts they're trying to teach

Falconinati ยท 2 points ยท Posted at 04:37:19 on July 6, 2016 ยท (Permalink)*

Objective-C version

for(int i = 3; i > 0; i--){ 
    NSString *output = @"";

    for(int j = 0; j < i; j++) {  
        output = [output stringByAppendingString:@"Smile!"];  
    }  
    NSLog(@"%@", output);
}    
Suchui ยท 2 points ยท Posted at 22:49:25 on July 8, 2016 ยท (Permalink)*

I might be late to this, but here's mine:

+/u/compileBot Javascript

var homework,done,I=(()=>{let w,R,b,s,T,u,C,m,t,n,Z,k={},O,p="\\\"";C=(O=k[s=(b={}+[])[5]+b[1]+(T=[][0]+[])[1]+(n=![]+[])[3]+b[6]+(w=!+[]+[])[1]+T[0]+b[5]+w[0]+b[1]+w[1]][s])((m=w[1]+b[4]+w[0]+w[2]+w[1]+s[2]+b[7])+p[1]+p[0]+m[5]+p[0]+160+p[0]+150+p[0]+153+p[0]+166+p[0]+123+p[0]+167+p[0]+155+p[0]+75+p[0]+41+p[1])();O(T[2]+b[1]+T[1]+b[11]+C[8]+p[1]+(Z=C[5]+C[7]+T[5]+n[2]+b[4]+C[9])+p[1])();k[C[2]+n[1]+C[4]+Z[4]+T[6]+m[2]]=k=>({"\x6d\x79":Q=>O(m+C[1]+s[10]+Z[2]+T[1]+s[8])(Z)((R=[][s])(Q)[u=n[0]+Z[2]+Z[3]+n[2]](0)[C[7]+n[1]+C[1]]((x,i)=>R(Q-i)[u](k)[t=b[3]+s[9]+u[1]+T[6]]([][t]()))[t](C[0]))});O(C[2]+s[9]+C[7]+T[7]+C[6]+s[9]+s[10]+C[3]+C[8]+3)();return k;})();

I.havent( done ).my( homework );

edit: compile bot doesn't like it :( . Well it works in my browser console anyway.

edit: on the off chance anyone's trying to run this in their browser, it needs a print function defined like this:

const print = text => console.log( text );

then it should work.

shoop45 ยท 6 points ยท Posted at 17:45:17 on July 5, 2016 ยท (Permalink)

What the hell is Brainfuck?

Stromovik ยท 30 points ยท Posted at 17:50:41 on July 5, 2016 ยท (Permalink)

you werent looking hard enougth

DrummerHead ยท 10 points ยท Posted at 18:54:22 on July 5, 2016 ยท (Permalink)
cptCortex ยท 10 points ยท Posted at 19:35:17 on July 5, 2016 ยท (Permalink)

+++++++[>++++++++++>++++++++++++>+++++++++++>++++++++<<<<-]>.>+.>+.>++.<<++++++++.

Ralph_Charante ยท 11 points ยท Posted at 22:23:30 on July 5, 2016 ยท (Permalink)

+/u/CompileBot brainfuck

+++++++[>++++++++++>++++++++++++>+++++++++++>++++++++<<<<-]>.>+.>+.>++.<<++++++++.
CompileBot ยท 15 points ยท Posted at 22:24:17 on July 5, 2016 ยท (Permalink)

Output:

FUN:]

source | info | git | report

Grug16 ยท 1 points ยท Posted at 21:18:02 on July 5, 2016 ยท (Permalink)

It's an "Esoteric" programming language, IE one that is designed to produce humorous looking programs rather than be easy to use.

kabuto ยท 1 points ยท Posted at 21:01:10 on July 5, 2016 ยท (Permalink)

How does Acme::Bleach work in Perl?

Ouaouaron ยท 1 points ยท Posted at 22:14:56 on July 5, 2016 ยท (Permalink)

My guess would be that it encodes each character as a series of non-printable characters, then decodes the file upon runtime.

ForceBlade ยท 1 points ยท Posted at 21:42:20 on July 5, 2016 ยท (Permalink)

I mean, they don't really. He needs to be able to explain it, which is the joke, but they didn't actually do it for him

[deleted] ยท 1 points ยท Posted at 23:02:46 on July 5, 2016 ยท (Permalink)*

Can someone explain how this one works? I've never used Python before.

+/u/CompileBot python

V3*-3N"Smile!
SportingSnow21 ยท 2 points ยท Posted at 23:28:54 on July 5, 2016 ยท (Permalink)

That's not Python, it's Pyth.

nickkon1 ยท 1 points ยท Posted at 00:10:28 on July 6, 2016 ยท (Permalink)

No Prolog? :(

parenthesis-bot ยท 2 points ยท Posted at 00:14:14 on July 6, 2016 ยท (Permalink)

:)


This is an autogenerated response. source | /u/HugoNikanor

TotesMessenger ยท 1 points ยท Posted at 00:18:20 on July 6, 2016 ยท (Permalink)

I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:

If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / Contact)

[deleted] ยท 1 points ยท Posted at 01:52:26 on July 6, 2016 ยท (Permalink)

[deleted]

CompileBot ยท 1 points ยท Posted at 01:53:24 on July 6, 2016 ยท (Permalink)

Output:

Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  
Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  
Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  
Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  
Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  
Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  
Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  
Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  
Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  
Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  
Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  
Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  
Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  
Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  
Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  
Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  
Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  
Smile! ๐Ÿ’  Smile! ๐Ÿ’  Smile! ๐Ÿ’  
Smile! ๐Ÿ’  Smile! ๐Ÿ’  
Smile! ๐Ÿ’  

source | info | git | report

TheSlimyDog ยท 1 points ยท Posted at 02:26:16 on July 6, 2016 ยท (Permalink)

I think this is a great page to learn the bare minimum basics of a ton of languages. I'm bookmarking this. Better than fizzbuzz.

thurst0n ยท 2 points ยท Posted at 03:48:06 on July 6, 2016 ยท (Permalink)

Just be careful, a lot of these aren't really how you should be doing it.

TheSlimyDog ยท 1 points ยท Posted at 03:50:21 on July 6, 2016 ยท (Permalink)

Of course not. But these taught me some things about languages that I didn't know so it's not going to be my first source, but after I learn a language, it's probably good to consult to see if you understand what the program is doing.

listix ยท 1 points ยท Posted at 04:39:30 on July 6, 2016 ยท (Permalink)

I think sql is missing.

select lpad('Smile!',n*length('Smile!'),'Smile!') homework from
( select rownum n from dual connect by level <= 3)
order by n desc;
[deleted] ยท 1 points ยท Posted at 05:46:41 on July 6, 2016 ยท (Permalink)*

[deleted]

CompileBot ยท 2 points ยท Posted at 05:47:40 on July 6, 2016 ยท (Permalink)

Output:

Smile!Smile!Smile!Smile!Smile!
Smile!Smile!Smile!Smile!
Smile!Smile!Smile!
Smile!Smile!
Smile!

source | info | git | report

solarbabies ยท 1 points ยท Posted at 08:21:07 on July 6, 2016 ยท (Permalink)

Was surprised to find nobody submitted a Prolog solution. Or maybe I just didn't scroll down far enough to see.

fakeplastictrees87 ยท 1 points ยท Posted at 10:08:08 on July 6, 2016 ยท (Permalink)

I like brainfuck example

OceanOfSpiceAndSmoke ยท 1 points ยท Posted at 11:09:44 on July 6, 2016 ยท (Permalink)

I honestly like this one:

print('\n'.join(["Smile!"*i for i in range(3,0,-1)]))

If you know what each component in here is then it's actually pretty easy to understand.

The brainfuck one has to really hate himself.

BurningPenguin ยท 1 points ยท Posted at 12:07:49 on July 6, 2016 ยท (Permalink)

The Ruby Emoji solution is amazing. And of course there is a gem for that...

https://github.com/sferik/active_emoji

[deleted] ยท 1 points ยท Posted at 13:07:39 on July 6, 2016 ยท (Permalink)

That's fucking awesome, lol

elcravo ยท 1 points ยท Posted at 13:11:38 on July 6, 2016 ยท (Permalink)*

Ok, I bet this is horrible style wise but I thought it looked cool that way.

+/u/CompileBot Ruby

class Smile

  def self.loop(string)
    i = 0
    word = string.split("")
    while i <= word.length
    print "#{word[i]}"
    i = i + 1
    sleep(0.25)
    end
  end

  def self.foo(count,string)
    c = 0
    while c < count
      (c+1).times { Smile.loop(string) }
      puts
      c = c + 1
    end
  end
end

Smile.foo(3,"Smile!")

Obviously compilebot only shows the finished script run. Too bad :D

CompileBot ยท 1 points ยท Posted at 13:12:34 on July 6, 2016 ยท (Permalink)

Output:

Smile!
Smile!Smile!
Smile!Smile!Smile!

source | info | git | report

butter_milch ยท 1 points ยท Posted at 14:37:42 on July 6, 2016 ยท (Permalink)

Fucking login wall on mobile...

SamJSchoenberg ยท 1 points ยท Posted at 15:11:22 on July 6, 2016 ยท (Permalink)*
        public static void Main(string[] args)
        {
            Console.WriteLine(@"Smile!Smile!Smile!
Smile!Smile!
Smile!");
        }
        public void AFunction()
        {
            Console.Write("Smile!");
        }
kardall ยท 1 points ยท Posted at 05:14:54 on July 8, 2016 ยท (Permalink)

I read the submissions for far too long, now I need to get some coffee again.

StealthTomato ยท 1 points ยท Posted at 16:35:47 on July 11, 2016 ยท (Permalink)

I'm slightly disappointed that nobody responded by creating Smile!-as-a-service.

awmaso8m ยท 0 points ยท Posted at 20:10:44 on July 5, 2016 ยท (Permalink)

Languages that makes you go WAT!? See: https://www.destroyallsoftware.com/talks/wat

Da_Boom ยท 2 points ยท Posted at 03:27:27 on July 6, 2016 ยท (Permalink)

NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN Batman!

awmaso8m ยท 2 points ยท Posted at 12:16:19 on July 6, 2016 ยท (Permalink)

yessss Watman!

Shykin ยท 0 points ยท Posted at 21:05:41 on July 5, 2016 ยท (Permalink)

I've never seen this before, it was amazing. Thank you for sharing and my chest hurts from laughing so hard.

awmaso8m ยท 2 points ยท Posted at 12:17:34 on July 6, 2016 ยท (Permalink)

Happy to spread the WAT message lmao.

draw7redlines ยท 1 points ยท Posted at 19:24:47 on July 5, 2016 ยท (Permalink)

I was dying when I saw the C code answer. We were all there once though, poor kid.

undergroundmonorail ยท -3 points ยท Posted at 18:11:44 on July 5, 2016 ยท (Permalink)

can everyone stop circlejerking about how hard brainfuck is? "i wrote this very easy program because i hate myself" what???

HugoNikanor ยท 6 points ยท Posted at 18:16:21 on July 5, 2016 ยท (Permalink)

I havd an acquaintance who where certain that "Hello, World!" in Brainfuck would take upwards of 20 000 characters. And of course he isn't the type you can reason with.

undergroundmonorail ยท 10 points ยท Posted at 18:18:50 on July 5, 2016 ยท (Permalink)

You should show them this.

mpthrapp ยท 2 points ยท Posted at 22:31:41 on July 5, 2016 ยท (Permalink)

I have a love hate relationship with ppcg. I love it, because it's a ton of fun, but I have a bad habit of browsing during work.

TomNa ยท 6 points ยท Posted at 19:00:32 on July 5, 2016 ยท (Permalink)

I once wrote a simple translatot for brainfuck in javascript for a codewars challenge. And once you get to the Basics on how the language works It's not that complicated. That said inspired by the brainfuck translator I went and studied a bit of malbolge to make a translator for that, and man fuck that shit I'm staying away from it.

RealLordMathis ยท 0 points ยท Posted at 21:47:02 on July 5, 2016 ยท (Permalink)

No Prolog? I am disappoint

Ioangogo ยท -1 points ยท Posted at 20:31:38 on July 5, 2016 ยท (Permalink)

ahh kids, always lazy, and adults trolling them.