Tech litmus test

tech litmus test,

you have 20 mins to solve this. starting from now. seriously.

try to do it, if you fail you have to leave Holla Forums.

Other urls found in this thread:

pastebin.com/YxjsxUJP
twitter.com/AnonBabble

while(True): print(""" * * * * * * * * * * * * * * * * * * * * * * * * * * * * *""")

FIRST

void stars(unsigned int n){ for (auto i = 0u; i

Python 3
n = int(next(open(0)))print('\n'.join(''.join('*' if x == y or n - 1 - x == y else ' ' for x in range(n)) for y in range(n)))

nice work guys

Do your own homework, fag.

Mathfag here.

cross[n_] := SparseArray[{Band[{1, 1}], Band[{1, n}, Automatic, {1, -1}]} -> "*", {n, n}, " "]cross[9] // Grid

for (int i = n * n + n - 2; i >= -1 ; --i) { putc(10 * (i % (n + 2) == 0 || i % n == n - 1) + 32 - 22 * ((i + 1) % (n + 1) == 0), stdout);}

I've already done this
#include #include #include #include int main (int argc, char* argv[]) { if (argc != 2) { printf("It needs one number parameter\n"); return 1; } int size = atoi(argv[1]) + 1; int last = size - 2; char muh_determinism[size]; memset(muh_determinism, ' ', last); muh_determinism[0] = '*'; muh_determinism[last] = '*'; muh_determinism[last + 1] = '\n'; write(STDOUT_FILENO, muh_determinism, size); for(int i = 0; i < last; i++) { muh_determinism[i] = ' '; muh_determinism[last - i] = ' '; muh_determinism[i + 1] = '*'; muh_determinism[last - i - 1] = '*'; write(STDOUT_FILENO, muh_determinism, size); } return 0;}

Never seen someone use := to define a function, but it's in the documentation so apparently it's a thing. Is that a legacy thing or what?

:= is SetDelayed. It causes the rule to be evaluated each time it is called rather than immediately. With an =, it would try to evaluate that expression immediately and fail due to n being unbound.

Lazy as fuck.

That's the point of Wolfram, prototyping shit quickly.

That's the point of lazy evaluation :^)

I'm too lazy to look it up on rosettacode and steal an answer

DESIGNATED
E
S
I
G
N
A
T
E
D

I see what you meant, not really though, it's not lazy in the argument. With some additional fuckery you can get close to that though. Hold forms .

Wanted to see a solution taking advantage of printf variable field width:

top kek.

Codemonkey must have fucked something up, because 8ch absolutely refuses to let me post this code, even in code tags:

pastebin.com/YxjsxUJP

I wanted to see a GirCode version. Something that finally gets the right answer, but boggles the mind as to why someone do it so wrong.

In what scenario would I ever need to do such a task?

Best solution right here, faggots:

void stars(const unsigned long size){ for (long i = 1; i other ? i : other, '*', i < other ? i : other, '*'); }}

That's right, carriage return. Suck my dick.

Forgot a fucking newline, goddamn I'm retarded:

void stars(const unsigned int size){ for (int i = 1; i other ? i : other, '*', i < other ? i : other, '*'); }}

It's like fizzbuzz, it helps weed out complete morons. No one will pay you to do it, but they certainly won't pay you for anything else if you cannot.

And just for fun, the same solution in Python:

def stars(size): for i in range(size): other = size - i - 1 print('{}*\r{}*'.format( ' ' * (i if i > other else other), ' ' * (i if i < other else other)))

print((0*" ") + "*" + (7*" ") + "*")print((1*" ") + "*" + (5*" ") + "*")print((2*" ") + "*" + (3*" ") + "*")print((3*" ") + "*" + (1*" ") + "*")print((4*" ") + "*" + (0*" "))print((3*" ") + "*" + (1*" ") + "*")print((2*" ") + "*" + (3*" ") + "*")print((1*" ") + "*" + (5*" ") + "*")print((0*" ") + "*" + (7*" ") + "*")

pajeet/10

It might be GirlCode

Best answer.

x' :: Int -> [String]x' n | n

Here ya go.

It took me 6,000,000 hours in vim. Actually, about 2 minutes

#include using namespace std;int main() { int size; cout > size; int counter = 0; for(int i = 0; i < size; i++){ for(int j = 0; j < size; j++){ if(i == j || j == (size - i - 1)){ cout

Enjoy this shit:
(defun cross3 (n1 &optional (n2 0) (cnt 0) (lnstatic n1) (str (make-string (1- (* (1+ n1) n1)) :initial-element #\Space)))
(cond ((= (* cnt lnstatic) (* lnstatic lnstatic)) str)
(T (when (= cnt 0)
(setf (aref str (+ (1- n1) (* cnt lnstatic))) #\*)
(setf (aref str (+ n2 (* cnt lnstatic))) #\*))
(setf (aref str (+ (1- n1) (* cnt (1+ lnstatic)))) #\*)
(setf (aref str (+ n2 (* cnt (1+ lnstatic)))) #\*)
(unless (= (1+ cnt) lnstatic)
(setf (aref str (+ lnstatic (* cnt (1+ lnstatic)))) #\Newline))
(cross3 (1- n1) (1+ n2) (1+ cnt) lnstatic str))))

Other version:

(defun cross (n1 &optional (n2 0) (ln n1))
(let ((str (make-string ln :initial-element #\Space)))
(cond ((zerop n1) nil)
(T (setf (aref str (1- n1)) #\*)
(setf (aref str n2) #\*)
(format t "~&~A" str)
(cross (1- n1) (1+ n2) ln)))))

My naming system should give me cancer soon.

Kek.

I copypasted the wrong version of my code

#include using namespace std;int main() { int size; cout > size; for(int i = 0; i < size; i++){ for(int j = 0; j < size; j++){ if(i == j || j == (size - i - 1)){ cout

Just use argv you cunt.

Does not solve the problem, you had one job.

I see.
But n is being declared as the parameter that the function is taking, how would it be unbound? I see the error it's throwing, but it looks like the result is the same. Is it just a best practices thing?

It is evaluating the right hand side as soon as you create the function which is why you get that error, and at that time nothing has been substituted for n.

Not only is it best practise to use :=, for some functions you won't even get the right results. (see pic 1).

= is useful for things you know are going to be constant, and also for amortization (see pic 2).

Why not do?

void stars(const unsigned int size){ for (int i = 1, int other = size; i other ? i : other, '*', i < other ? i : other, '*');}

Err, wrote it quick and didn't even compare answers. Here's fib with a leading zero term.

Learned something new everyday. Just wish it didn't have to be regarding this revolting language, but you know, that's life.
Thanks for the explanation, user.

np. I love the language though

Where are my recursive bros?

import mathdef kappa1(n, m): if n

I expect they're not using Python. Use a language designed for unlimited recursion like Scheme or Haskell if you want to do it this way.

Your program stops working at an input of around 2000. That's not a reasonable input for this program but it is for a lot of other programs. Using recursion like this in Python is a bad habit.

cross_pat =: monad definepa =. (y , y) $ 1 , y $ 0cr =. +. |.(32 + 10 * cr pa) { a.)cross_pat 9

I would imagine that most python programmers have not heard of tail call optimization.

looks cute


Python has some libraries that try to optimize tail recursion. Guido doesn't like tail recursion, so there is no official way to make it not slow and overflow the stack.


What language is that?

Not as short as some of the other Python (3) solutions but it's readable

def astrix(n): for line in range(0, n): pp = [line, n - line - 1] for char in range(0, n): if char in pp: print('*', end='') else: print(' ', end='') print()

It's J.

I would have if I'd wanted to work on it more than "it works", but yours there does look cleaner.

Also, looking at yours, I'm just noticing that the leading carriage return is redundant.

(define (stars n) (let ((str (make-string n #\space)) (rep (lambda (s m) (substring-replace s m (+ m 1) #\space #\*)))) (define (impl i) (cond ((< i n) (newline) (display (rep (rep str i) (- n i 1))) (impl (+ i 1))))) (impl 0)))
in (((Scheme))), because why not

Not sure if it has to be Java or not, but anyway:

max = 9for n in 0..max-1; first = [n, (max-1-n)].min last = [n, (max-1-n)].max if first == last puts ' '*first + "*" else puts ' '*first + "*" + ' '*(last-(first+1)) + '*' endend

Here's a java one too.

package challenges.starcross;import java.util.Arrays;public class StarCrossing { public static void main(String[] args) { Integer size = new Integer(args[0]); makeCross(size); } public static void makeCross(int size) { for (int n=0;n

100 characters not counting unnecessary whitespace:
def star(n): for i in range(0, n): a, b = sorted((i, n - 1 - i)) print(' ' * a + '*' + ' ' * (b - a - 1) + '*' * (a != b))

has 118. Get beat.

import starsstars.start()

the hackerrank demo test has something like that except you made a staircase. it's just a loop within a loop, isn't it?

Can no one stop the 100 char slayer?

So which of these solutions is the most optimized?

Why would I be gauging efficiency while using python?

Because you imply character count has anything to do with a program being good.

What else did I imply, great interpreter-of-what's-not-there?

That you're a filthy weeaboo faggot who should hang himself posthaste

...

wow fuck you too

It never has to be Java.

really though, it'd be impressive to see it shorter

If I tweak the mathematica version and use the same function name as you, it comes out to 90 chars.

star[n_] := [email protected]/* */[{Band[{1, 1}], Band[{1, n}, {n, 1}, {1, -1}]} -> "*", n, " "]

And also, they are right to call you a fag for caring about the number of characters.

(defun star (x) (stary x))

According to SICP I should blackbox the function away and you shouldn't care about what's inside. Trust me it works.

javascript
length = j = 9p = Math.powfor(i = 0; i < length; i++) console.log((p(2,length) | p(2,--j) | p(2,i)).toString(2).slice(1,length+1).replace(/0/g," ").replace(/1/g,"*"))

(defun emptyspace (y) (cond (( left max) t) ((= right left) (emptyspace left) (princ "*") (emptyspace left) (fresh-line) (stary (+ left 1) (- right 1) max)) ((> left right) (stary-print right left) (stary (+ left 1) (- right 1) max)) (t (stary-print left right) (stary (+ left 1) (- right 1) max))))(defun star (x) (stary 1 x x))

Not using any string fuckery or math wizardy but whatever.

I wanted to see something interesting, is all. Something shorter might have a novel approach

Louis Reasoner pls

I'd like to see an over engineered solution, preferably one using * sprites used as an opengl texture.

Why would you create all that rendering bloat when you can just rig up a database to store the results to the problem for every possible input value?

#include "stdlib.h"#include "stdio.h"int main(int argc, char** argv){ if (argc != 1) return 1; int size = atoi(*argv); for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { if (x == y || x == (size - y - 1)) { printf("*"); } else { printf(" "); } } printf("\n"); } return 0;}

be gentle i'm just a compsci bab

Cmon Holla Forums we need Star.c As A Service

I have no idea what I'm looking at, and I'm here to stay, fuck you.

I'll get started on the SOAP xml. Anyone remember that bullshit?.

ITT: People don't understand what Code Golf is.

Irrelevant unless we are all using the same language.

Untrue. Code Golf can be done between different languages, which adds the difficulty of picking the right one to get the least amount of characters.

;; computer spell to display an X;; of given width and height(define (spaces n) (when (> n 0) (display #\space) (spaces (- n 1))))(define (star n) (spaces n) (display #\*))(let loop ((end (- (read) 1)) (start 0)) (when (>= end 0) (let* ((a (min start end)) (b (max start end))) (star a) (when (not (eq? a b)) (star (- b a 1)))) (newline) (loop (- end 1) (+ start 1))))

I wonder why Lisp was made using parenthesis instead of brackets. If they're used so much, it would be nicer if one didn't have to use a shift-key combination all the time.

(((Lisp)))

Yup. I remember hating the living shit out of it.


Is that Schindler's Lisp?

Lisp is sixty years old and based on mathematical notation.

m=ARGV[0].to_i-1;for n in 0..m;f,l=[n,(m-n)].sort;puts ' '*f+"*"+((f!=l)?' '*(l-f-1)+'*':'');end

In the year of our lord and savior, Jesus Christ, two thousands and sixteen an unnamed but very large bank implemented a SOAP API that I am forced to use.

Minute and a half:def f(width): for i in xrange(width): s = [" "]*width s[i] = "*" s[width-i-1] = "*" print("".join(s))

(define stars (lambda (m) (letrec ((star (lambda (n) (if (or (= n 1) (zero? n)) '(1) (cons n (star (- n 2)))))) (print-line! (lambda (n) (unless (zero? n) (cond ((= n 1) (display "*\n")) (else (display (string-append "*" (make-string (- n 2) #\space) "*\n"))))))) (do-stars (lambda (sl) (let ((h (quotient (length sl) 2))) (letrec ((quux (lambda (s b i) (unless (null? s) (display (make-string b #\space)) (print-line! (car s)) (quux (cdr s) (if (>= i h) (sub1 b) (add1 b)) (add1 i)))))) (quux sl 0 0)))))) (do-stars (append (star m) (cdr (reverse (star m))))))))