[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: yhomxphjier61.png (44 KB, 419x675)
44 KB
44 KB PNG
>there has to be a better way to do this
>>
There is, but it's unreadable
>>
>>106914709
it would be slow as fuck.
think about performance
>>
>>106914709
There's no better way than a hashmap. Just keep grinding, storage is cheap.
>>
>>106914709
the essence of efficiency (not really, this is retarded)
(defun fizz-buzz-single (object predicates actions
&optional post-action)
(let ((result (flatten-tree
(cl-map 'list
(lambda (predicate action)
(when (funcall predicate object)
(funcall action object)))
predicates actions))))
(if post-action
(funcall post-action result)
result)))

(defun fizz-buzz (objects predicates actions &optional post-action)
(mapcar
(lambda (object)
(funcall #'fizz-buzz-single
object predicates actions post-action))
objects))

(fizz-buzz-single 15
(list (lambda (n) (= (mod n 3) 0))
(lambda (n) (= (mod n 5) 0))
(lambda (n) (not (or (= (mod n 3) 0)
(= (mod n 5) 0)))))
(list (lambda (n) "Fizz")
(lambda (n) "Buzz")
(lambda (n) n))
(lambda (lst)
(if (= (length lst) 2)
(mapconcat #'identity lst)
(car lst))))


(fizz-buzz (number-sequence 10 20)
(list (lambda (n) (= (mod n 3) 0))
(lambda (n) (= (mod n 5) 0))
(lambda (n) (not (or (= (mod n 3) 0)
(= (mod n 5) 0)))))
(list (lambda (n) "Fizz")
(lambda (n) "Buzz")
(lambda (n) n))
(lambda (lst)
(if (= (length lst) 2)
(mapconcat #'identity lst)
(car lst))))
>>
>>106915053
and yeah i know this is missing the point of the op. there's just nowhere else to share how i see the fizzbuzz problem. obv the original intention of the task is to test if someone knows basic control structures, but it's also application of an action (i.e. a block of code) on an object based on a predicate (i.e condition) run against the same object. this may or may not be useful when writing code (mostly not)
>>
>he gave up at 36k lines
You just don't have what it takes kid
>>
>>106914709
Whats with the lack of comments? How am I supposed to know what those lines do?
>>
>>106914709
Actually you need to abstract "Buzz" into another object.
>>
Needs a microservice for each possibility.
>>
>>106915053
You are duplicating the code in the first two predicates and in the third one (with a not), this should tell you that the design is not quite right
>>
>>106914709
Do you have a Helm chart so I can deploy this on my cluster?
>>
File: fizzbuzz-in-clojure.jpg (216 KB, 1049x678)
216 KB
216 KB JPG
>>106915053
>>
>>106916007
Typical Java programmer always making everything overcomplicated
>>
>>106914793
no any modern compiler will optimize it. https://godbolt.org/z/53hTG7KKa
can't be bothered to write more
>>
>>106915936
yes, i need to remove it...
>>
>>106914709
The other way requires giving up your soul to the devil.
>>
>>106914709
Yeah, but if it works it works
>>
>>106914709
You could simply generate these and store then in a MySQL table. In you code, you can just query the table based on the id. It would also be very expandable because you could simply generate the rows for more numbers if you need them in the future without having to change your actual fizzbuzz code.
>>
>>106914709
If only.
>>
>>106914709
>there has to be a better way to do this
There is:
with open('fizzbuzz.py', 'w') as f:
f.write('def fizzbuzz(n):\n')
for i in range(1, 100001):
if i % 15 == 0:
f.write(f' {"if" if i == 15 else "elif"} n == {i}:\n print("FizzBuzz")\n')
elif i % 3 == 0:
f.write(f' {"if" if i == 3 else "elif"} n == {i}:\n print("Fizz")\n')
elif i % 5 == 0:
f.write(f' elif n == {i}:\n print("Buzz")\n')
else:
f.write(f' {"if" if i == 1 else "elif"} n == {i}:\n print({i})\n')
>>
>>106914709
There literally isn't
>>
>>106916066
haha
        int a = 810092048;
for (int b = 1; b < 101; b++) {
String[] s = new String[]{Integer.toString(b), "Fizz", "Buzz", "FizzBuzz"};
System.out.println(s[a & 3]);
a = a >> 2 | a << 28 & 1073741823;
}
>>
>>106914793
compiler would turn this into a jmp table most likely
>>
>>106915053
I still don't understand how this gibberish is "better" than C like languages
>>
>>106917780
this particular case complicates a simple task for theoretical mumbo jumbo, of course it's gibberish.
>"better"
have you seen me anywhere shilling for lisp itt? i fucking did not. and i will not. stick with what works for you.



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

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.