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

Pages: 1-

Improve my shitcode [Clojure]

Name: Anonymous 2016-06-03 0:14

This makes a square shape of text as such:

Y o u h a v e b e e n t r o l l e d
o e
u l
l
h o
a r
v t
e
n
b e
e e
e b
n
e
t v
r a
o h
l
l u
e o
d e l l o r t n e e b e v a h u o Y


(require '[clojure.string :as s])

(defn square-text
[text]
(let [backwards (s/reverse text)
space (s/join (repeat (- (* 2 (count text)) 3) " "))
spaceify (fn [str] (s/join (interpose " "
(s/split str
(re-pattern "")))))]
(do (prn (spaceify text))
(loop [f (subs text 1 (- (count text) 1))
b (subs backwards 1 (- (count backwards) 1))]
(when-not (empty? f)
(prn (str (first f) space (first b)))
(recur (subs f 1) (subs b 1))))
(prn (spaceify backwards)))))

Name: Anonymous 2016-06-03 1:27

>>1
Clojure is not a LISP.

Name: Anonymous 2016-06-03 2:09

>>2
Did I say it was??

Name: Anonymous 2016-06-03 2:59

javascript is better

"use strict";
let square = text => {
let a = text.split(""),
b = a.slice(1, -1).concat(a.slice(1, -1))
b.forEach((_, c) => {b[c] += " ".repeat(2 * a.length - 3) + b.pop()})
return a.join(" ") + "\n" + b.join("\n") + "\n" + a.reverse().join(" ")
}

console.log(square("You have been trolled"))
Y o u h a v e b e e n t r o l l e d
o e
u l
l
h o
a r
v t
e
n
b e
e e
e b
n
e
t v
r a
o h
l
l u
e o
d e l l o r t n e e b e v a h u o Y

Name: Anonymous 2016-06-03 4:48

Clojure is not a lisp
Javashit is a lisp

Name: Anonymous 2016-06-03 9:10

Too narrow of scope in your design. You should cover the generation of any arbitrary regular polygon based on a number of sides or an angle between the edges (including negative angles for concave polygons).

Name: Anonymous 2016-06-03 9:16

>>5
XML makes Java the acceptable lisp.

Name: Anonymous 2016-06-03 10:38

>>1
Evah Neeb de Llort, the slayer of poon.

Name: Anonymous 2016-06-03 12:13

Haskell implementation
squareText s = putStr g
where
g = foldr (\a b -> a ++ "\n" ++ b) " " $
(map (\(a,b) -> b ++ [a]) $
zip (init $ reverse s) $
map (\(a,b) -> a : b) $
zip (init s) f) ++ [reverse p]
f = [(tail.init) p]
++ (replicate ((length p)-4)
(concat $ replicate ((length p) - 2) " "))
++ [(tail.init) (reverse p)]
p = init $
concat $
map (\(a, b) -> [a] ++ [b]) $
zip s (repeat ' ')

Name: Anonymous 2016-06-04 7:59

#!/usr/bin/env python

import sys

s = ' '.join(sys.argv[1:])
for i in xrange(len(s)):
print (' '.join(s) if not i
else ' '.join(reversed(s)) if i == len(s) - 1
else s[i] + ' ' * (2 * len(s) - 3) + s[-i-1])

Name: Anonymous 2016-06-04 8:07

python2.7 in the current year?

Name: Anonymous 2016-06-04 22:39

>>10
Python: code less, create more.

Name: Anonymous 2016-06-05 5:58

% gnu octave
(@(s)(@(t)(@(u)(@(v)(@(w)char(max(t,max(u,max(v,w)))))(v'))(fliplr(flipud(u))))(t'))(padarray(int8(s),length(s)-1,32,'post')))('You have been trolled')


i certainly have

Name: Cudder !cXCudderUE 2016-06-05 19:58

All the above code is a FAIL for having useless memory allocations.

#include <stdio.h>

void prtsqr(char *s) {
int n = strlen(s);
char *t = s + n - 1;
puts(s);
goto mainloop;
do {
printf("%c%*s%c\n", s<t? *s : *t, n-2, " ", s<t ? *t : *s);
mainloop:
if(s<t) {
*s ^= *t;
*t ^= *s;
*s ^= *t;
}
t--;
s++;
} while(*(s+1));
puts(t);
}

int main() {
prtsqr("You have been trolled");
return 0;
}

Name: Anonymous 2016-06-05 21:14

>>14
allocate my anus

Name: Anonymous 2016-06-05 22:59

>>14
goto my anus

Name: Anonymous 2016-06-05 23:41

>>14
hax my anus

Name: Anonymous 2016-06-06 3:27

>>14
the 70s called, they want their code back

Name: Anonymous 2016-06-06 10:33

>>14
Nice off-by-one error there, shitface.

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