[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Create a program in any programming language that outputs all

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 73
Thread images: 3

File: contact.png (268KB, 1600x1600px) Image search: [Google]
contact.png
268KB, 1600x1600px
Create a program in any programming language that outputs all possible combinations of characters "ayy lmao" (space included). Code with least characters used wins.
>>
#usr/bin/python
Print "OP has AIDS"
>>
import Data.List
permutations"ayy lmao"
>>
File: 1409685055752.jpg (59KB, 483x430px) Image search: [Google]
1409685055752.jpg
59KB, 483x430px
<?php
$s = "ayy lmao";
$o = str_shuffle ( $s );
echo $o;
?>
>>
#include <algorithm>
#include <string>
#include <iostream>

int main(int, char *)
{
const std::string dicks("ayy lmao");
std::sort(dicks.begin(), dicks.end());

do {
std::cout << dicks << '\n';
} while(std::next_permutation(dicks.begin(), dicks.end()))

return 0;
}
>>
>>45280295
What language is this? And why are you importing something that you aren't using?
>>
>>45280316
Woops, should be char ** in main.
>>
>>45280313
can we see source for str_shuffle. Knowing that that's PHP they will no doubt have fucked it up beyond believe and it's probably O(n^3)
>>
>>45280318
That's Haskell. And I am in fact using it.
>>
>>45280295
Same as
#include "shit.h"
int main() { premutations("ayy lmao"); return 0 }

Irrelevant
>>
>>45280341
Nice
>>
.


A language just for this problem, a dot lists all permutations of "ayy lmao".
>>
>>45280356
Only that it's part of the standard library.
Should the c++ guy not be allowed to include <string> or <iostream> ?
>>
>>45280328
why not
 int main(void) 

if you don't use the arguments anyway?
>>
>>45280376
he should not
standard string libraries are for casuals
>>
OP here. I should clarify that using shortcuts is forbidden. You should implement the algorithm yourself, otherwise the solution is void.
>>
>>45280398
what?
given which kind of instruction set?
>>
File: 1408789436482.jpg (12KB, 237x212px) Image search: [Google]
1408789436482.jpg
12KB, 237x212px
>>45280313
Stupid of me, couldve been much shorter:

echo str_shuffle ( "ayy lmao" );
>>
>>45280407
Any instruction set which doesn't abstract the problem further. You should be able to do it with regular control flow commands and any data structure you may find useful. But the solution should not be abstracted, it should be clear in the code how the permutations are being printed.
>>
ayyyyyyyy
>>
>>45280441
Sorry, not printed but chosen. It should be clear how permutations are chosen. Printing is trivial after that.
>>
>>45280412
> str_shuffle() shuffles a string. One permutation of all possible is created.
>ONE
>>
>>45280474
Technically if he runs it in a loop forever, it will print out all combinations eventually.
>>
>>45280491
Yeah but then it's not a complete solution to the problem.
>>
>>45280474
<?php
while(true) {
echo str_shuffle ( "ayy lmao" );
}
?>


wa la
>>
>>45280398
There you go op, I revised my Haskell version
main=print$p"ayy lmao"
p s=s:q s [] where
q [] _ =[]
q (t:n) m=foldr i (q n (t:m)) (p m) where
i k r=let (_,l) = i' id k r in l
i' _ [] r=(n, r)
i' f (y:z) r=let (v,l) = i' (f.(y:)) z r
in (y:v,f (t:y:v):l)
>>
>>45280505
Impressive
>>
>>45280542
http://hackage.haskell.org/package/base-4.7.0.1/docs/src/Data-List.html#permutations
not really
>>
>>45280558
Slightly disappointing.
>>
>>45280586
haha, what did you expect?
I copy pasted stuff from standard libraries for school assignments aswell

I ddidn't paste the haskell code here, but yeah, that's how you do it, if you have access to an implementaion but are not allowed to use it
>>
>>45280542
lol OP confirmed for not knowing shit about programming
>>
let rec shuffle s l = function
| [] ->
begin
match l with
| [] -> print_endline s
| _ -> ()
end
| c :: cs ->
shuffle (Printf.sprintf "%c%s" c s) [] (List.rev_append l cs);
shuffle s (c :: l) cs
;;

shuffle "" [] ['a'; 'y'; 'y'; ' '; 'l'; 'm'; 'a'; 'o'; ];;
>>
>>45280670
what language?
>>
>>45280313
THANK YOU BASED 4 CHAN
>>
>>45280638
this x forty keks
>>
perms([]) -> [[]];
perms(L) -> [[H|T] || H <- L, T <- perms(L--[H])].

ayy lmao
>>
>>45280756
Faggot, you for real?
>>
>>45280756
ocaml
i just produced a tail rec version (no stack violation)
let rec shuffle next s l = function
| [] ->
begin
match l with
| [] ->
List.iter print_char s;
print_newline ()
| _ -> ()
end;
next ()
| c :: cs ->
shuffle
(fun () -> shuffle next s (c :: l) cs)
(c :: s) [] (List.rev_append l cs);
;;

let char_list_if_string s =
let rec loop i accu =
if i = -1 then
accu
else
loop (pred i) (s.[i] :: accu) in
loop (pred (String.length Sys.argv.(1))) []
;;

shuffle (fun () -> ()) [] [] (char_list_if_string Sys.argv.(1));;
>>
>>45280823
Forgot my tags.

perms([]) -> [[]];
perms(L) -> [[H|T] || H <- L, T <- perms(L--[H])].
>>
>>45280497
>least characters wins
<? while(true) echo str_shuffle('ayy lmao')?>
>>
>>45280868
not guaranteed to work
>>
>>45280868
Fuck me.
<? for(;;) echo str_shuffle('ayy lmao')?>


Can it be shortened any more than that?
>>
>>45280886
No code is guaranteed to work if you're using a shitty compiler.
>>
>>45280868
>>45280893
I agree with >>45280886 we have no garantee that your code will produce all the permutations
0/10
>>
use List::Util qw(shuffle);
s +.*+join "",shuffle split //,"ayy lmao"+e,$_{$_} or $_{$_}+=print "$_\n" while 1


Least characters. All combinations. Perl wins again.

b:\>perl ayy.pl|wc
9830 17206 98304

b:\>


>>45280893
It outputs more than all combinations which is incorrect.
>>
>>45280931
>It outputs more than all combinations which is incorrect.
was not requested

>>45280931 look at >>45280295
and perl fails, like always
>>
>>45280931
Not specified in OP. Not a rule.

>>45280925
It will work. In theory it may not, but in practice it will, and practice trumps all.

But you can cut off the closing tags:
<? for(;;) echo str_shuffle('ayy lmao')
>>
>>45280963
>look at >>45280295
Doesn't even output anything. It's not even a proper program.
>>
>>45280842
thanks
>>
>>45280976
>Not specified in OP. Not a rule.
If OP asks to write a program that calculates square root of 81 and you output 0 1 2 3 4 5 6 7 8 9 10 11 (...), it's not a correct output even though a part of it is the answer OP asked for. Same with your code.
>>
>>45280981
works like that for ghci
and need about:
 main = print 
added for ghc, in case some autist is to stupid to recognice it as valid
>>
>>45281005
you must produce the full code

filthy lazy Haskell noob
>>
You guys are aware that you're doing this 14 yo's homework, right?
>>
>>45281020
I just responded to >>45280931 which uses shuffle and split aswell, so fuck of
>>
>>45281030
>implying his/her homework is in OCaml
>>
>>45281004
Right, because you're not "calculating" it. Stop using shitty analogies. If he asked you to write a program that "outputs" the square root of 81, your example would be correct, as it does indeed output the square root of 81.
>>
>>45281030
None of code posted would help him in any way. If only you knew a tiny bit of programming you could see it for yourself.
>>
>>45281043
It's pretty obvious that it would be incorrect but even after such example (it's not an analogy) you think it's correct, I won't argue with you anymore.
>>
>>45281030
the homework most likelly has to be done in some imperative language (java?), so apart from a specialiced C++ case, there is nothing helpfull in this thread
>>
>>45281048
>>45281063
    public static <T> void Permutation(T[] t, T[] a, int x) {
if (x >= t.length) {
StringBuilder sb = new StringBuilder("");
for (T i : t) {
sb.append(i);
}
System.out.println(sb);
return;
}
for (int i = 0; i < t.length; i++) {
t[x] = a[i];
Permutation(t, a, x+1);
}
}
>>
>>45280165
while (1) {
putchar("ayy lmao"[rand()%8]);
}

Should print them all eventually.
>>
#!/usr/bin/env python
import itertools
for x in itertools.permutations('ayy lmao'):
print(''.join(x))
>>
from itertools import permutations as p
print(list(p("ayy lmao")))
>>
>>45281119
Why not
while (1) {
putchar("ay lmo"[rand()%8]);
}
>>
#!/usr/local/bin/an
"ayy lmao"


$ whatis an   
an (4) - Aironet Communications 4500/4800 IEEE 802.11FH/b wireless network device
an (6) - Anagram generator
>>
>>45281133
gotta love python
>>
>>45281162
Or just
while(1)
putchar("ay lmo"[rand()%8]);
>>
>>45281119
>>45281162
It can't give more than the bare minimum because reasons.
>>
>>45280976
>It will work. In theory it may not, but in practice it will, and practice trumps all.

won't that just echo random permutations? I mean, sure it may eventually spit out the correct set, but it'll also potentially produce duplicates and won't print a set of predictable size.

I mean, it /technically/ doesn't violate OP's rules, but you have to admit that it's inelegant and produces useless output.
>>
>>45281258
>I mean, it /technically/ doesn't violate OP's rules, but you have to admit that it's inelegant and produces useless output.
my fellow anon, it's 4chan
>>
>>45281301
>it's 4chan

I give the benefit of the doubt. Besides, collective "we" aren't a complete pack of morons...I mean, there have been tremendously intellectually complex results produced from this site.
>>
>>45281258
>where is that list of permutations I asked you to produce?
>it's somewhere there is that pile of trash, go look for it yourself
>>
object ayylmao extends App {
val ayylmao = "ayylmao".toList
ayylmao.permutations.foreach(e => println(e))
}
Thread posts: 73
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.