First forkbomb in dart lang

2

Let‘s golf it to the max!

So I wondered why there is no forkbomb on the web for dart... so I created one. I started to golf it to:

Dart, 98 bytes

import'dart:isolate';class f{static k(o){f().r();}r(){for(;;)Isolate.spawn(k,0);}}main(){f().r();}

Try it online!

Any suggestions or golfing even further wins.


Update log:

(-1 Byte) Updated spacing thanks to @KevinCruijssen

0x45

Posted 2020-02-20T12:04:06.470

Reputation: 810

Question was closed 2020-02-21T15:18:17.017

1You can remove the space before r() – Kevin Cruijssen – 2020-02-20T12:11:02.637

@KevinCruijssen so simple, yet so powerful – 0x45 – 2020-02-20T12:13:43.667

6

I'm voting to close this question as off-topic because it is asking for malicious code, which is not permitted per https://codegolf.meta.stackexchange.com/q/4829.

– pppery – 2020-02-21T04:39:36.857

Forkbombing is malicious? I can add a warning though. – 0x45 – 2020-02-21T10:26:11.770

Forkbomb explanation – ouflak – 2020-02-21T11:13:36.710

Answers

2

New golf:

Dart, 98 58 bytes

import'dart:isolate';main(x){for(;;)Isolate.spawn(main,0);}

Try it online!

0x45

Posted 2020-02-20T12:04:06.470

Reputation: 810

Ah, nice one. I don't think it can be shorter than this tbh. Unless there is a way to get rid of the import and use the dart:isolate:Isolate.spawn directly in Dart (I usually develop/golf in Java, where directly import usage is possible, but I haven't been able to find something similar for Dart through google). Another option would be if there is a shorter alternative for Isolate.spawn, maybe some asyc multithreading kind of construction. – Kevin Cruijssen – 2020-02-20T13:00:40.810

Because the main function is already a function, you don't need to define a separate function. Am I right? – a'_' – 2020-02-20T13:07:42.233

@ a'_' yes correct. – 0x45 – 2020-02-20T13:11:04.053

@KevinCruijssen I didn’t find a solution to this yet too – 0x45 – 2020-02-20T13:15:41.697

I kind of completely do not understand. If you already know the answer, why have you asked the question? – my pronoun is monicareinstate – 2020-02-20T13:47:12.070

I just found it out.. my original post was my best golf – 0x45 – 2020-02-20T14:05:38.277

1

90 86 bytes

I don't know Dart too well, but you can save some bytes by using the Constructor of class f instead of the method r. This allows you to get rid of the f().r() inside the static method k(o), as well as the .r() after the f() in the main method:

import'dart:isolate';class f{static k(o){}f(){for(;;)Isolate.spawn(k,0);}}main(){f();}

Try it online.

Kevin Cruijssen

Posted 2020-02-20T12:04:06.470

Reputation: 67 575

Oh yeah... nice one! – 0x45 – 2020-02-20T12:28:13.970

@0x45 Saved 4 more bytes. :) – Kevin Cruijssen – 2020-02-20T12:40:26.023

Found another solution saving alot – 0x45 – 2020-02-20T12:53:19.807