/prog/ Challenge 9001
1
Name:
Anonymous
2011-05-01 19:51
The correct title of this article is /prog/ Challenge 9001 . It appears incorrectly here because of technical restrictions.
The task:
Print numbers from 1 to 1000 without using any loop or conditional statements. Don't just write the printf() or cout statement 1000 times.
inb4 lipthfags and dead dogs using some obscure functionality of their obscure languages.
2
Name:
Anonymous
2011-05-01 20:00
So, the instructions are we can't use loops or some such. Does this also apply to operations which conceal looping activity?
3
Name:
Anonymous
2011-05-01 20:02
I'll leave it up to your own judgement. But more marks are given for completely loopless and conditionless solutions.
4
Name:
Anonymous
2011-05-01 20:05
print "\n".join(map(str,range(1,1001)))
I bet the Perl version is even shorter.
5
Name:
Anonymous
2011-05-01 20:11
var Progs: array[boolean] of procedure(I: longint);
procedure h(i: longint);
begin
writeln(i);
Progs[(i+1) > 1000](i+1);
end;
procedure a(i: longint);
begin
end;
begin
progs[false] := @h;
progs[true] := @a;
h(1);
end.
6
Name:
Anonymous
2011-05-01 20:21
Looping means goto, which means the solution is to unroll the loop.
(macrolet ((code () `(progn ,@(loop for i from 1 to 1000 collect `(print ,i))))) (code))
What this code does is generate the code: (progn (print 1) ... (print 1000))
Looping isn't used in any of the code that runs, hence it should fulfill your requirement (it is however used in the generation code. There is no way to avoid this without writing it by hand, and only an idiot would do that. I could of course, post the macroexpansion without posting the generation code, but it turns out it's too long to fit in a post).
7
Name:
Anonymous
2011-05-01 20:22
>>5
Any jump/call can be used to emulate a loop, which is what you're doing.
8
Name:
Anonymous
2011-05-01 20:35
>>7
what I am doing is your mom
9
Name:
Anonymous
2011-05-01 20:46
#include <iostream>
template<int I>
void print()
{
std::cout << I << std::endl;
print<I+1>();
}
template<>
void print<1000>()
{
std::cout << 1000;
}
int main()
{
print<1>();
std::cin.get();
}
10
Name:
Anonymous
2011-05-01 20:48
[1..1000] |> List.iter (fun n -> System.Console.WriteLine(n))
11
Name:
Anonymous
2011-05-01 20:53
>>1
That's trivial in functional languages, just as
>>10 has demonstrated.
12
Name:
Anonymous
2011-05-01 21:11
import java.io.*;
public class Loopless {
public static int x;
public static int[] ary = new int[1000];
public static void main(String[] args) {
counting(1);
}
public static void counting(int i) {
System.out.println(""+i);
try {
x = ary[i];
}
catch(Exception e) {
System.exit(0);
}
counting(++i);
}
}
13
Name:
Anonymous
2011-05-01 21:12
>>9
Awesome.
>>10
[1..1000] is essentially a for-loop construct
14
Name:
Anonymous
2011-05-01 21:19
>>12
The
try...catch is just for output aesthetics.
15
Name:
Anonymous
2011-05-01 21:27
>>13
Only if you consider map to be equivalent to for-loop.
16
Name:
Anonymous
2011-05-01 21:31
>>5,10,12 Make use of jumps/calls which are themselves equivalent to loops.
>>6,9 Generate code which prints it (unrolling the loop).
As OP disallowed loops (I assume in runtime code, it shouldn't matter what you use in generation code), only
>>6,9 are valid answers.
If you insist on disallowing loops in generating code, the only way to solve it is to only include the output of the generated code, but that is disallowed in the requirements.
This means that the challenge is only solvable by macros (as in Lisp,
>>6 ), source code generation (any language), templates (as in SEPPLES,
>>9 ) if some form of loops (control-flow) are allowed in the code generator.
If control-flow is not allowed anywhere, the problem is not solvable as per requirements the OP asked.
OP also sucks for being a bastard from the imageboards responsible for spamming our board and trolling (noko (not saging and making threads proclaiming his ignorance), over 9000 meme, corruption of the word lisp, spamming, insulting non-terrible dogs and other infractions).
17
Name:
Anonymous
2011-05-01 21:52
18
Name:
Anonymous
2011-05-01 21:59
>>16
I could never wrap my head around C templates. How is
>>6 not just another example of recursion, albeit fancy?
19
Name:
Anonymous
2011-05-01 22:03
C templates
*scratches head*
20
Name:
Anonymous
2011-05-01 22:06
>>18
Where is the recursion? All it does is generate the code
(progn (print 1) ... (print 1000)) which itself features no recursion. A smart compiler may be able to unroll a loop like that.
21
Name:
Anonymous
2011-05-01 22:08
>>20
No, sorry, that's me thinking one number and typing another. I meant to refer to
>>9 .
22
Name:
Anonymous
2011-05-01 22:11
So far
>>9 is the only one that doesn't make use of run-time loops
or compile-time loops.
23
Name:
Anonymous
2011-05-01 22:14
>>21
It uses compile-time recursion. Recursion is allowed according to the OP's rules, though.
It works by unwinding the code into this:
print_1();
print_2();
print_3();
...
print_999();
print_1000();
And the compiler likely inlines those functions so in reality it would just be unwound into this:
std::cout << 1 << std::endl;
std::cout << 2 << std::endl;
std::cout << 3 << std::endl;
...
std::cout << 999 << std::endl;
std::cout << 1000 << std::endl;
24
Name:
Anonymous
2011-05-01 22:15
int lol(int num)
{
num && lol(num-1) && printf("%d\n", num);
return num;
}
int main()
{
printf("1\n");
lol(1000);
return 0;
}
25
Name:
Anonymous
2011-05-01 22:21
>>24
num && lol(num-1) && printf("%d\n", num);
without using any loop or conditional statements
26
Name:
Anonymous
2011-05-01 22:23
printf("1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n81\n82\n83\n84\n85\n86\n87\n88\n89\n90\n91\n92\n93\n94\n95\n96\n97\n98\n99\n100\n101\n102\n103\n104\n105\n106\n107\n108\n109\n110\n111\n112\n113\n114\n115\n116\n117\n118\n119\n120\n121\n122\n123\n124\n125\n126\n127\n128\n129\n130\n131\n132\n133\n134\n135\n136\n137\n138\n139\n140\n141\n142\n143\n144\n145\n146\n147\n148\n149\n150\n151\n152\n153\n154\n155\n156\n157\n158\n159\n160\n161\n162\n163\n164\n165\n166\n167\n168\n169\n170\n171\n172\n173\n174\n175\n176\n177\n178\n179\n180\n181\n182\n183\n184\n185\n186\n187\n188\n189\n190\n191\n192\n193\n194\n195\n196\n197\n198\n199\n200\n201\n202\n203\n204\n205\n206\n207\n208\n209\n210\n211\n212\n213\n214\n215\n216\n217\n218\n219\n220\n221\n222\n223\n224\n225\n226\n227\n228\n229\n230\n231\n232\n233\n234\n235\n236\n237\n238\n239\n240\n241\n242\n243\n244\n245\n246\n247\n248\n249\n250\n251\n252\n253\n254\n255\n256\n257\n258\n259\n260\n261\n262\n263\n264\n265\n266\n267\n268\n269\n270\n271\n272\n273\n274\n275\n276\n277\n278\n279\n280\n281\n282\n283\n284\n285\n286\n287\n288\n289\n290\n291\n292\n293\n294\n295\n296\n297\n298\n299\n300\n301\n302\n303\n304\n305\n306\n307\n308\n309\n310\n311\n312\n313\n314\n315\n316\n317\n318\n319\n320\n321\n322\n323\n324\n325\n326\n327\n328\n329\n330\n331\n332\n333\n334\n335\n336\n337\n338\n339\n340\n341\n342\n343\n344\n345\n346\n347\n348\n349\n350\n351\n352\n353\n354\n355\n356\n357\n358\n359\n360\n361\n362\n363\n364\n365\n366\n367\n368\n369\n370\n371\n372\n373\n374\n375\n376\n377\n378\n379\n380\n381\n382\n383\n384\n385\n386\n387\n388\n389\n390\n391\n392\n393\n394\n395\n396\n397\n398\n399\n400\n401\n402\n403\n404\n405\n406\n407\n408\n409\n410\n411\n412\n413\n414\n415\n416\n417\n418\n419\n420\n421\n422\n423\n424\n425\n426\n427\n428\n429\n430\n431\n432\n433\n434\n435\n436\n437\n438\n439\n440\n441\n442\n443\n444\n445\n446\n447\n448\n449\n450\n451\n452\n453\n454\n455\n456\n457\n458\n459\n460\n461\n462\n463\n464\n465\n466\n467\n468\n469\n470\n471\n472\n473\n474\n475\n476\n477\n478\n479\n480\n481\n482\n483\n484\n485\n486\n487\n488\n489\n490\n491\n492\n493\n494\n495\n496\n497\n498\n499\n500\n501\n502\n503\n504\n505\n506\n507\n508\n509\n510\n511\n512\n513\n514\n515\n516\n517\n518\n519\n520\n521\n522\n523\n524\n525\n526\n527\n528\n529\n530\n531\n532\n533\n534\n535\n536\n537\n538\n539\n540\n541\n542\n543\n544\n545\n546\n547\n548\n549\n550\n551\n552\n553\n554\n555\n556\n557\n558\n559\n560\n561\n562\n563\n564\n565\n566\n567\n568\n569\n570\n571\n572\n573\n574\n575\n576\n577\n578\n579\n580\n581\n582\n583\n584\n585\n586\n587\n588\n589\n590\n591\n592\n593\n594\n595\n596\n597\n598\n599\n600\n601\n602\n603\n604\n605\n606\n607\n608\n609\n610\n611\n612\n613\n614\n615\n616\n617\n618\n619\n620\n621\n622\n623\n624\n625\n626\n627\n628\n629\n630\n631\n632\n633\n634\n635\n636\n637\n638\n639\n640\n641\n642\n643\n644\n645\n646\n647\n648\n649\n650\n651\n652\n653\n654\n655\n656\n657\n658\n659\n660\n661\n662\n663\n664\n665\n666\n667\n668\n669\n670\n671\n672\n673\n674\n675\n676\n677\n678\n679\n680\n681\n682\n683\n684\n685\n686\n687\n688\n689\n690\n691\n692\n693\n694\n695\n696\n697\n698\n699\n700\n701\n702\n703\n704\n705\n706\n707\n708\n709\n710\n711\n712\n713\n714\n715\n716\n717\n718\n719\n720\n721\n722\n723\n724\n725\n726\n727\n728\n729\n730\n731\n732\n733\n734\n735\n736\n737\n738\n739\n740\n741\n742\n743\n744\n745\n746\n747\n748\n749\n750\n751\n752\n753\n754\n755\n756\n757\n758\n759\n760\n761\n762\n763\n764\n765\n766\n767\n768\n769\n770\n771\n772\n773\n774\n775\n776\n777\n778\n779\n780\n781\n782\n783\n784\n785\n786\n787\n788\n789\n790\n791\n792\n793\n794\n795\n796\n797\n798\n799\n800\n801\n802\n803\n804\n805\n806\n807\n808\n809\n810\n811\n812\n813\n814\n815\n816\n817\n818\n819\n820\n821\n822\n823\n824\n825\n826\n827\n828\n829\n830\n831\n832\n833\n834\n835\n836\n837\n838\n839\n840\n841\n842\n843\n844\n845\n846\n847\n848\n849\n850\n851\n852\n853\n854\n855\n856\n857\n858\n859\n860\n861\n862\n863\n864\n865\n866\n867\n868\n869\n870\n871\n872\n873\n874\n875\n876\n877\n878\n879\n880\n881\n882\n883\n884\n885\n886\n887\n888\n889\n890\n891\n892\n893\n894\n895\n896\n897\n898\n899\n900\n901\n902\n903\n904\n905\n906\n907\n908\n909\n910\n911\n912\n913\n914\n915\n916\n917\n918\n919\n920\n921\n922\n923\n924\n925\n926\n927\n928\n929\n930\n931\n932\n933\n934\n935\n936\n937\n938\n939\n940\n941\n942\n943\n944\n945\n946\n947\n948\n949\n950\n951\n952\n953\n954\n955\n956\n957\n958\n959\n960\n961\n962\n963\n964\n965\n966\n967\n968\n969\n970\n971\n972\n973\n974\n975\n976\n977\n978\n979\n980\n981\n982\n983\n984\n985\n986\n987\n988\n989\n990\n991\n992\n993\n994\n995\n996\n997\n998\n999\n1000\n");
27
Name:
Anonymous
2011-05-01 22:25
>>26
This is in fact fine, according to the OP. It only uses printf() once.
28
Name:
Anonymous
2011-05-01 22:25
>>25
That's not a conditional or loop statement (for, while, if). It's an expression, not a statement.
29
Name:
Anonymous
2011-05-01 22:30
>>28
There would be a conditional in run-time, though. It needs to check whether
num is non-zero.
30
Name:
Anonymous
2011-05-01 22:36
class abc
{
public:
abc()
{
static int n = 1;
std::cout << n++ << '\n';
}
};
int main()
{
delete new abc[1000];
return 0;
}
31
Name:
Anonymous
2011-05-01 22:42
>>23
Actually, looking at the disassembly it doesn't inline them. Huh.
32
Name:
Anonymous
2011-05-01 22:46
>>30
u mena
delete[] new abc[1000];
33
Name:
Anonymous
2011-05-01 22:54
>>32
Thanks, that's what I mena.
34
Name:
Anonymous
2011-05-01 23:18
main = mapM_ print [1..1000]
>>13
Nope.
35
Name:
Anonymous
2011-05-01 23:24
>>34
Actually, here you go:
main = mapM_ print $ take 10 xs
where xs = 1 : map (+1) xs
36
Name:
Anonymous
2011-05-01 23:25
37
Name:
Anonymous
2011-05-02 0:10
In other news: Osama is dead.
38
Name:
Anonymous
2011-05-02 0:13
>>37
Who gives a shit, there are more important things to worry about, like writing the best program to suit OP's restrictions.
39
Name:
Anonymous
2011-05-02 0:29
40
Name:
Anonymous
2011-05-02 2:46
system("/usr/bin/seq 1000");
41
Name:
Anonymous
2011-05-02 2:57
42
Name:
Anonymous
2011-05-02 3:04
>>41
You mean ``underpaid, overworked sysadmin''.
43
Name:
Anonymous
2011-05-02 4:12
(1..1000)>>.say
That's autoparallel, not looped. (There was no mention of ordering.)
No loops and no tests and in C no less:
#include <signal.h>
static void handler(int signum) { exit(0); }
float output(int x) {
float a=1/x--;
printf("%d\n", 1000 - x);
output(x);
return a; // not tail recursive
}
int main(void) {
struct na;
na.sa_handler = handler;
sigemptyset(&na.sa_mask);
sigaction(SIGFPE, &na, NULL);
output(1000);
return 0;
}
44
Name:
Anonymous
2011-05-02 4:48
#include "void.h"
__BEGIN__COUNT__PRINTER__(1, 1000)
45
Name:
Anonymous
2011-05-02 4:55
Is try {} catch considered a loop construct for this challenge?
46
Name:
Anonymous
2011-05-02 4:59
>>43
Recursion can be equivalent to looping, it's still control-flow. The basic loop itself is nothing more than a jump to the start of a block that would eventually read the jump to the loop. Recursion with TCO is completly equivalent to it, goto is equivalent to it, recursion without TCO is very close to it (stack increases).
>>45
It's an indirect transfer of control, which makes it perfectly capable of looping.
OP may not consider those loops, but they were as much loops as normal ones (yes, this includes mapping constructors, declarative ones, generators and so on).
47
Name:
Anonymous
2011-05-02 5:31
>>46
Okay, so all C programs (with implicit call to main, and yes, it is called) are automatically disqualified?
Actually it doesn't matter. Your description combined with the absence of conditionals renders virtually all languages not only non-TC but incapable of producing the result.
Not that that would stop me if I really wanted to do it. I'd just abuse an MMU, or write the program in malbolge.
48
Name:
>>46
2011-05-02 5:41
>>47
Not exactly, you can use virtually any language to generate code. In C, you'd just write:
#include <stdio.h>
int main(void)
{
int i;
printf("#include <stdio.h>\nint main(void){");
for (i = 1; i <= 1000; i++) printf("printf(\"%d\\n\");",i);
printf("return 0;}");
return 0;
}
/* run with:
cc generator.c > out.c
cc out.c
./out
*/
49
Name:
Anonymous
2011-05-02 5:44
>>45 here. Observe: the forced recursion of code.
import sys
sys.setrecursionlimit(1003)
def recurse(n):
try:
1/n
recurse(n-1)
print(n)
except ZeroDivisionError:
pass
recurse(1000)
50
Name:
Anonymous
2011-05-02 6:14
Are you retarded or trolling?
>>47
Since everyone seems to like using non-standard looping construct equivalents, I think I'll be a bit abusive as well and just use some unportable x86 shellcode:
#include <stdio.h>
#include <stdlib.h>
char magic[] = { 0x33, 0xF6, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x5D, 0x83, 0xC5, 0x07, 0x83, 0xEC, 0x08, 0x83, 0xC4,
0x08, 0x46, 0x81, 0xFE, 0xE8, 0x03, 0x00, 0x00, 0x7F, 0x11, 0x56, 0xE8, 0x04, 0x00, 0x00, 0x00,
0x25, 0x64, 0x0A, 0x00, 0x55, 0x68, 0x12, 0x34, 0x56, 0x78, 0xC3, 0x6A, 0x00, 0x68, 0x12, 0xEF,
0xCD, 0xAB, 0xC3};
void main(void)
{
void (*p)() = magic;
*(int*)(magic+0x26) = &printf;
*(int*)(magic+0x2E) = &exit;
p();
}
Only tested on Win32, but it should work on *nix too as long as libc calling convention is cdecl (which it should be).
For those too lazy to use a disassembler, the code is roughly this:
xor esi,esi
call $
pop ebp
add ebp, 7
sub esp, 8
l:
add esp, 8
inc esi
cmp esi,3e8h
jg end
push esi
call z:
db '%d', 0ah,00
z:
push ebp ; l
push printf
ret
end:
No direct looping, but push/push/ret is essentially a call which returns to wherever you want it, which creates a loop.
52
Name:
>>51
2011-05-02 6:40
(after end, it should be a push 0 / push exit / ret, but i forgot to include it in the disassembly (it's in the shellcode))
53
Name:
Anonymous
2011-05-02 6:41
>>9 here, still winning, and I'm back for more
#include <iostream>
typedef void (*print_func)(int);
print_func funcs[2];
void print_func1(int x)
{
std::cout << x << std::endl;
funcs[x / 1000](x + 1);
}
void print_func2(int x)
{
}
int main()
{
funcs[0] = print_func1;
funcs[1] = print_func2;
print_func1(1);
std::cin.get();
}
54
Name:
Anonymous
2011-05-02 7:08
>>49
"try: 1/n, except: pass" is essentially the same as "if n == 0: break". Think about it.
55
Name:
Anonymous
2011-05-02 7:14
>>53
You're not winning and this latest one doesn't even give a successful return status.
56
Name:
Anonymous
2011-05-02 7:33
>>55
doesn't even give a successful return status
Please be trolling.
57
Name:
Anonymous
2011-05-02 7:51
import java.util.Timer;
import java.util.TimerTask;
public class LoopLess {
static int[] f = new int[10001];
static int i = 0;
static Timer t = new Timer();
public static void main(String[] args) {
TimerTask tt = new TimerTask() {
public void run() {
try {
System.out.println(++i + f[i * 10]);
} catch (Exception e) {
t.cancel();
}
}
};
t.scheduleAtFixedRate(tt, 0, 10);
}
}
58
Name:
Anonymous
2011-05-02 8:03
map , range , all count as a loop.
((λ (m)
((λ (t)
((λ (o)
((o (λ (x) (display x) (+ x 1))) 1))
(m (m t t) t)))
(m (λ (f) (λ (x) (f (f x))))
(λ (f) (λ (x) (f (f (f (f (f x))))))))))
(λ (n m)
(λ (f) (λ (x) ((m (n f)) x)))))
And for those faggots that use map,
(map print (iota 5 1))
59
Name:
Anonymous
2011-05-02 9:21
#include <stdio.h>
void f(int i)
{
i %= 1001;
printf("%d\n", i);
f(i+1);
}
int main(void)
{
f(1);
}
60
Name:
Anonymous
2011-05-02 9:30
INPUT:
seq 1000 | cowsay -f milk
OUTPUT:
_________________________________________
/ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 \
| 17 18 19 20 21 22 23 24 25 26 27 28 29 |
| 30 31 32 33 34 35 36 37 38 39 40 41 42 |
| 43 44 45 46 47 48 49 50 51 52 53 54 55 |
| 56 57 58 59 60 61 62 63 64 65 66 67 68 |
| 69 70 71 72 73 74 75 76 77 78 79 80 81 |
| 82 83 84 85 86 87 88 89 90 91 92 93 94 |
| 95 96 97 98 99 100 101 102 103 104 105 |
| 106 107 108 109 110 111 112 113 114 115 |
| 116 117 118 119 120 121 122 123 124 125 |
| 126 127 128 129 130 131 132 133 134 135 |
| 136 137 138 139 140 141 142 143 144 145 |
| 146 147 148 149 150 151 152 153 154 155 |
| 156 157 158 159 160 161 162 163 164 165 |
| 166 167 168 169 170 171 172 173 174 175 |
| 176 177 178 179 180 181 182 183 184 185 |
| 186 187 188 189 190 191 192 193 194 195 |
| 196 197 198 199 200 201 202 203 204 205 |
| 206 207 208 209 210 211 212 213 214 215 |
| 216 217 218 219 220 221 222 223 224 225 |
| 226 227 228 229 230 231 232 233 234 235 |
| 236 237 238 239 240 241 242 243 244 245 |
| 246 247 248 249 250 251 252 253 254 255 |
| 256 257 258 259 260 261 262 263 264 265 |
| 266 267 268 269 270 271 272 273 274 275 |
| 276 277 278 279 280 281 282 283 284 285 |
| 286 287 288 289 290 291 292 293 294 295 |
| 296 297 298 299 300 301 302 303 304 305 |
| 306 307 308 309 310 311 312 313 314 315 |
| 316 317 318 319 320 321 322 323 324 325 |
| 326 327 328 329 330 331 332 333 334 335 |
| 336 337 338 339 340 341 342 343 344 345 |
| 346 347 348 349 350 351 352 353 354 355 |
| 356 357 358 359 360 361 362 363 364 365 |
| 366 367 368 369 370 371 372 373 374 375 |
| 376 377 378 379 380 381 382 383 384 385 |
| 386 387 388 389 390 391 392 393 394 395 |
| 396 397 398 399 400 401 402 403 404 405 |
| 406 407 408 409 410 411 412 413 414 415 |
| 416 417 418 419 420 421 422 423 424 425 |
| 426 427 428 429 430 431 432 433 434 435 |
| 436 437 438 439 440 441 442 443 444 445 |
| 446 447 448 449 450 451 452 453 454 455 |
| 456 457 458 459 460 461 462 463 464 465 |
| 466 467 468 469 470 471 472 473 474 475 |
| 476 477 478 479 480 481 482 483 484 485 |
| 486 487 488 489 490 491 492 493 494 495 |
| 496 497 498 499 500 501 502 503 504 505 |
| 506 507 508 509 510 511 512 513 514 515 |
| 516 517 518 519 520 521 522 523 524 525 |
| 526 527 528 529 530 531 532 533 534 535 |
| 536 537 538 539 540 541 542 543 544 545 |
| 546 547 548 549 550 551 552 553 554 555 |
| 556 557 558 559 560 561 562 563 564 565 |
| 566 567 568 569 570 571 572 573 574 575 |
| 576 577 578 579 580 581 582 583 584 585 |
| 586 587 588 589 590 591 592 593 594 595 |
| 596 597 598 599 600 601 602 603 604 605 |
| 606 607 608 609 610 611 612 613 614 615 |
| 616 617 618 619 620 621 622 623 624 625 |
| 626 627 628 629 630 631 632 633 634 635 |
| 636 637 638 639 640 641 642 643 644 645 |
| 646 647 648 649 650 651 652 653 654 655 |
| 656 657 658 659 660 661 662 663 664 665 |
| 666 667 668 669 670 671 672 673 674 675 |
| 676 677 678 679 680 681 682 683 684 685 |
| 686 687 688 689 690 691 692 693 694 695 |
| 696 697 698 699 700 701 702 703 704 705 |
| 706 707 708 709 710 711 712 713 714 715 |
| 716 717 718 719 720 721 722 723 724 725 |
| 726 727 728 729 730 731 732 733 734 735 |
| 736 737 738 739 740 741 742 743 744 745 |
| 746 747 748 749 750 751 752 753 754 755 |
| 756 757 758 759 760 761 762 763 764 765 |
| 766 767 768 769 770 771 772 773 774 775 |
| 776 777 778 779 780 781 782 783 784 785 |
| 786 787 788 789 790 791 792 793 794 795 |
| 796 797 798 799 800 801 802 803 804 805 |
| 806 807 808 809 810 811 812 813 814 815 |
| 816 817 818 819 820 821 822 823 824 825 |
| 826 827 828 829 830 831 832 833 834 835 |
| 836 837 838 839 840 841 842 843 844 845 |
| 846 847 848 849 850 851 852 853 854 855 |
| 856 857 858 859 860 861 862 863 864 865 |
| 866 867 868 869 870 871 872 873 874 875 |
| 876 877 878 879 880 881 882 883 884 885 |
| 886 887 888 889 890 891 892 893 894 895 |
| 896 897 898 899 900 901 902 903 904 905 |
| 906 907 908 909 910 911 912 913 914 915 |
| 916 917 918 919 920 921 922 923 924 925 |
| 926 927 928 929 930 931 932 933 934 935 |
| 936 937 938 939 940 941 942 943 944 945 |
| 946 947 948 949 950 951 952 953 954 955 |
| 956 957 958 959 960 961 962 963 964 965 |
| 966 967 968 969 970 971 972 973 974 975 |
| 976 977 978 979 980 981 982 983 984 985 |
| 986 987 988 989 990 991 992 993 994 995 |
\ 996 997 998 999 1000 /
-----------------------------------------
\ ____________
\ |__________|
/ /\
/ / \
/___________/___/|
| | |
| ==\ /== | |
| O O | \ \ |
| < | \ \|
/| | \ \
/ | \_____/ | / /
/ /| | / /|
/||\| | /||\/
-------------|
| | | |
<__/ \__>
61
Name:
Anonymous
2011-05-02 9:37
>>60
not valid
Milk has conditional statement, you can't drink it if it's too old.
62
Name:
Anonymous
2011-05-02 9:39
>>61
_____________________________________
/ Yes you can motherfucker, drink me, \
\ drink me now. /
-------------------------------------
\ ____________
\ |__________|
/ /\
/ / \
/___________/___/|
| | |
| ==\ /== | |
| O O | \ \ |
| < | \ \|
/| | \ \
/ | \_____/ | / /
/ /| | / /|
/||\| | /||\/
-------------|
| | | |
<__/ \__>
63
Name:
Anonymous
2011-05-02 9:42
>>59
Doesn't terminate. Stack overflow doesn't count as "terminating".
64
Name:
Anonymous
2011-05-02 9:47
>>63
Noboday said anything about terminating.
An stack overflow counts as "terminating" to me since it terminates the program. No machine has infinite sized stack.
65
Name:
Anonymous
2011-05-02 10:03
66
Name:
Anonymous
2011-05-02 10:05
67
Name:
Anonymous
2011-05-02 10:25
>>4
$ perl -E 'map say,1..1000'
68
Name:
Anonymous
2011-05-02 10:33
from subprocess import call
from sys import argv
n = int(' '.join(argv[1:] + ['1']).split()[0])
print n
([0] * 1000)[n]
call(['python', argv[0], str(n + 1)])
69
Name:
Anonymous
2011-05-02 11:29
>>68
You can access an interpreter with the code module.
70
Name:
Anonymous
2011-05-02 12:01
>>69
Yeah, I thought there was probably something like that. Thanks.
71
Name:
Anonymous
2011-05-02 12:16
>>68
Here's a version that doesn't quit with an error:
from subprocess import call
from sys import argv, exit
n = int(' '.join(argv[1:] + ['1']).split()[0])
print n
([lambda: 0] * 1000 + [exit])[n]()
call(['python', argv[0], str(n + 1)])
And the
code module is stupid and I hate it.
72
Name:
Anonymous
2011-05-02 12:56
>>71
And the code module is stupid and I hate it.
Welcome to
/prog/ , enjoy your stay.
73
Name:
Anonymous
2011-05-02 13:36
Fellow /prog/ riders, here's the ultimate VALID PERL CODE :
perl -e '$??s:;s:s;;$?::s&&=]=>%-|{=%;|1%3{&;y; -/:-@[-`{-};`-{/" -;;s;;$_;see'
74
Name:
Anonymous
2011-05-02 13:38
>>73
That can't be true. It cannot be.
75
Name:
Anonymous
2011-05-02 13:40
/prog/ challenge 9002:
Create the worst
/prog/ challenge of all time. Contest over.
>>1 wins.
76
Name:
Anonymous
2011-05-02 13:43
77
Name:
Anonymous
2011-05-02 14:05
You won't like this:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define LIMIT 1000
int main(int argc, char *argv[])
{
if (argc == 1)
execlp(argv[0], argv[0], "0", NULL);
if (argc == 2)
{
int x = atoi(argv[argc-1]);
printf("%d\n", x);
if ( x >= LIMIT)
return 0;
sprintf(argv[argc-1], "%d", x + 1);
execlp(argv[0], argv[0], argv[argc-1], NULL);
}
return 0;
}
78
Name:
Anonymous
2011-05-02 14:26
79
Name:
Anonymous
2011-05-02 15:00
>>40 is what i would say
winner
80
Name:
Anonymous
2011-05-02 15:05
>>62
From the makers of
GIRLS GONE WILD comes,
MILK GONE BAD .
81
Name:
Anonymous
2011-05-02 15:32
Prelude> mapM_ (print) [1..1000]
82
Name:
Anonymous
2011-05-02 16:06
83
Name:
Anonymous
2011-05-02 17:48
84
Name:
Anonymous
2011-05-02 18:11
>>83
You. Go back to where you came from.
85
Name:
Anonymous
2011-05-02 18:53
>>84
You return
whence you came.
86
Name:
Anonymous
2011-05-03 8:04
ENTERPRISE C SOLUTION
#include <stdio.h>
typedef void (*F1)(int);
typedef void (*F2)(F1,int);
typedef void (*F3)(F2,F1,int);
void P(int n) { printf("%d\n",n); }
void T1(F1 f1, int n) {f1(n);f1(n+1);f1(n+2);f1(n+3);f1(n+4);f1(n+5);f1(n+6);f1(n+7);f1(n+8);f1(n+9); }
void T2(F2 f2, F1 f1, int n) {f2(f1,n);f2(f1,n+10);f2(f1,n+20);f2(f1,n+30);f2(f1,n+40);f2(f1,n+50);f2(f1,n+60);f2(f1,n+70);f2(f1,n+80);f2(f1,n+90); }
void T3(F3 f3, F2 f2, F1 f1, int n) { f3(f2,f1,n);f3(f2,f1,n+100);f3(f2,f1,n+200);f3(f2,f1,n+300);f3(f2,f1,n+400);f3(f2,f1,n+500);f3(f2,f1,n+600);f3(f2,f1,n+$
int main() { T3(T2,T1,P,1); return 0; }
87
Name:
Anonymous
2011-05-03 10:02
>>86
I don't know what enterprise you worked for, but no company has
best practices like this.
88
Name:
Anonymous
2011-05-03 12:29
#define P0 printf("%d\n",++i);
#define P1 P0 P0
#define P2 P1 P1
#define P3 P2 P2
#define P4 P3 P3
#define P5 P4 P4
#define P6 P5 P5
#define P7 P6 P6
#define P8 P7 P7
#define P9 P8 P8
int main(void) {
int i = 0;
P3 P5 P6 P7 P8 P9
return 0;
}
89
Name:
Anonymous
2011-05-03 12:55
>>87
Its a joke to refer to most hairy hacked-up code as "Enterprise Solution"
90
Name:
Anonymous
2011-05-04 1:29
This thread is PIG DISGUSTING
91
Name:
Anonymous
2011-05-04 2:02
>>1
main = putStrLn ("1\n" ++ "10\n" ++ "11\n" ++ "100\n" ++ "101\n" ++ "110\n" ++ "111\n" ++ "1000\n")
92
Name:
Anonymous
2011-05-04 3:47
>>53
Nice job. You translated my beautiful Pascal solution(
>>5 ) into ugly, broken C
93
Name:
Anonymous
2011-05-04 4:20
int i = 1;
struct hi
{
hi();
};
hi()
{
std::cout << i << "\n";
i++;
}
int main()
{
hi[1000];
return 0;
}
94
Name:
>>9,53
2011-05-04 6:07
>>92
a)
Progs[(i+1) > 1000](i+1);
This uses a conditional. Sure, you're not using
if, but it will generate a
cmp in assembly.
b)
That's C++, not C.
95
Name:
Anonymous
2011-05-04 10:18
_______________
< DRINK MY ANUS >
---------------
\ ____________
\ |__________|
/ /\
/ / \
/___________/___/|
| | |
| ==\ /== | |
| O O | \ \ |
| < | \ \|
/| | \ \
/ | \_____/ | / /
/ /| | / /|
/||\| | /||\/
-------------|
| | | |
<__/ \__>
96
Name:
Anonymous
2011-05-04 12:24
#include <algorithm>
#include <iostream>
int main() {
std::for_each(1, 1000, [](int x) { std::cout << x << std::endl; });
return 0;
}
And before you faggots say that's not allowed because for_each does iteration, I want you to know that
map in whatever precious functional language you're using is implemented with iteration. for_each is C++'s map.
97
Name:
Anonymous
2011-05-04 12:36
>>96
Just wanted to say that you're wrong as much as them. Map, for-each, for_each and recursion count as ``loops''.
98
Name:
Anonymous
2011-05-04 14:06
.........,....................,......,.............,......,........................
...,,..,...........................,......:,,::,,:,.,,,,:,.,,.........,...,..,,....
..,..,,.....,......2illl▓▓███████████▓▓▓▓▓▓██▓.........,..,,..
,...,..,...,.k▓█▓▓▓▓lBEnjjBllllllBjzv░1JTHtq8tL;..,...nll█▓.......,...,,
..,......v▓█M:..,::,,:;1JBt;,...,....q:......:vFll▓▓llEL.....█▓,......,...
,...,.....█,,,...░;........;x,.......,:,,..,,:,,........,░,,,.....█lM.......,,
.....,:n█▓...,..Lii███▓B1........tj▓▓▓█████lM.,,........j█▓;......
...W██▓w,,..,Y▓▓█████M...k██▓▓▓█▓lll▓▓v▓▓▓▓▓;.▓█▓...
..#ll█::vn▓▓▓▓g;J:..,.t█▓................,n▓▓glll▓▓▓▓Wl▓▓.wll█..
...zi█;:..,..,t▓7▓▓░2ll█▓:......,.X▓Bq..,.........Bll▓▓█▓.El█3.F█lll
.....▓█1t;3█▓.,...Wl██,..,..f▓▓Mi█W,rB▓▓▓█lB;..▓█lBt█lK.:;█..
....,.f█▓W███▓▓7:..▒▓█M..tjBl▓██▓Bjzr▒█▓Bj██jY.,..,h█▓2..
.....,..j█.jll█Bl▓▒ll█fjllllll█llBIjj█6;:..▒▓▓▓████,l█▓......Bl█▓..,..
,......U█.;r█████▓▓▓█▓▓█▓▓█████Bj..C██W.....yi█;:.......
........j█...█████████████▓lM:.k▓M..f▓█W,...,..lll█8:.....,...
,......N▓,..B██▓▓.█M1▓▓.,..j█....,;8l██▓W,.....░ll██r:.....,,..,,
......r▓▓.....▒ll▓▓▓██▓█▓▓██▓▓▓▓881xtll▓▓██▓I....,..,,..,...
......I█▓.6;,.░;,,,..,..;r░::v7::,..;YTn;xtll▓▓█▓▓n..........,,..,.....
.....w█▓..,JjlgglllBjkT:,..,.........,,.,W▓▓▓▓H...............,,..,..,,..
,......U█▓r....,......,......,;rll▓l█▓▓▓▓t,..,..........,..,,..,..,,.,,....
.........▒ll███▓▓▓▓███▓▓▓BBj::....,......,.....,,..,..,,..,..,,.,,...
,...,..,.............,...,......,......,..,...,..,......,......,...,......,........
99
Name:
Anonymous
2011-05-04 14:22
All answers are invalid, because the OS uses loops and conditionals to load the program.
100
Name:
Anonymous
2011-05-04 14:27
>>99
Not really solvable unless you decide to take some specific platform and fully unroll all the code for display.
101
Name:
Anonymous
2011-05-04 16:09
Would
f x y = 10 * x + y
w = flip map [0..9] . f
main = putStrLn $ unwords $ map (show . (1+)) $ w =<< w =<< w =<< [0]
count? It does use map , though.
102
Name:
Anonymous
2011-05-04 16:12
(unfold
(λ (x) (< x 1000))
display add1)
But unfold is a loop.