ITT: We code random shit
Ill start
>fizzbuzzint main() {
int i;
for (i = 1; i < 101; i++) {
if (i % 3 == 0 && i % 5 == 0) { printf("\nfizzbuzz"); continue; }
if (i % 3 == 0) { printf("\nfizz"); continue; }
if (i % 5 == 0) { printf("\nbuzz"); continue; }
printf("\n%d", i);
}
return 0;
}
>tfw learning C for two weeks and am already better than 95% of job applicants.
>95% of C progammers can't fizzbuzz
makes sense
>>56934650
how can u even pass a class without knowing how to do this, in the first place ?
>>56934913
Maybe, but only in Murica, I guess
trying to figure out how 4chan picks its IDs colors (black or white)clear();
var lel = document.getElementsByClassName("posteruid");
var lBlack = 9999999999;
var hWhite = 0;
for (var i = 0; i < lel.length; i++) {
var str = "";
if (i % 2 === 1) {
var lel2 = lel[i].getElementsByClassName("hand")[0];
var rgb = lel2.style.backgroundColor;
var rgb = rgb.substring(4, rgb.length-1)
.replace(/ /g, '')
.split(',');
str += "[" + rgb[0];
str += " " + rgb[1];
str += " " + rgb[2] + "] ";
var bw = 0.299 * Number(rgb[0])
+ 0.587 * Number(rgb[1])
+ 0.114 * Number(rgb[2]);
str += "--> " + bw;
if (lel2.style.color === "black" && bw < lBlack)
lBlack = bw;
if (lel2.style.color === "white" && bw > hWhite)
hWhite = bw;
}
}
console.log("lB = " + lBlack + "\nhW = " + hWhite);
Damn op ya blew it.
>>56934650
pretty sure the continue statement is usless
>>56934650
you should break your self
furry node irc bot
(cors proxy is because these sites are banned in russia where my computer is)var i = require('irc-js'),
r = require('request').defaults({headers: {'User-Agent': 'fuck/1.0 (benis)', 'X-Requested-With': 'JSON'}}),
sid
i.connect({nick: 'e6211', server: {address: 'irc.rizon.net'}}, b => {
b.join('#/g/ftp', (e, c) => {
r.get('https://cors-anywhere.herokuapp.com/https://inkbunny.net/api_login.php?username=guest',
(a,b,d) => {sid = JSON.parse(d)})
b.match(/\!e621\s(.*)/, e621)
b.match(/\!fur\s(.*)/, e621)
b.match(/\!ink\s(.*)/, ink)
function e621(o, m){
r.get(`https://cors-anywhere.herokuapp.com/http://e621.net/post/index.json?\
limit=320&tags=${m}%20-equine%20-not_furry%20-pokemon%20-my_little_pony`,
(a, b, d) => {
let s = JSON.parse(d)
let n = Math.floor(Math.random()*s.length + 1)
try{
o.reply(`e621 (${n} out of ${(s.length==320)?'over 320':s.length}) - ${s[n].file_url}`)
}
catch(err){
o.reply((String(err).indexOf('TypeError') >= 0)?'TypeError, prob not found':err)
console.log(err)
}
})
}
function ink(o, m){
r.get(`https://cors-anywhere.herokuapp.com/https://inkbunny.net/api_search.php?sid=${sid.sid}&text=${m}`,
(a, b, d) => {
let s = JSON.parse(d).submissions
let n = Math.floor(Math.random()*s.length + 1)
try{
console.log(`inkbunny (${n} out of ${(s.length==30)?'over 30':s.length}) - ${s[n].file_url_full}`)
}
catch(err){
o.reply((String(err).indexOf('TypeError') >= 0)?'TypeError, prob not found':err)
console.log(err)
}
})
}
})
})
var FizzBuzz = function() {
var i;
for(i = 0; i <= 20; i++) {
if(i % 3 === 0 && i % 5 === 0) {
document.write("Fizzbuzz");
}
else if(i % 3 === 0) {
document.write("fizz");
}
else if(i % 5 === 0) {
document.write("buzz");
}
else {
document.write(i);
}
}
}
I'm not trolling btw, is there a faster way to do this?
>>56934650
I cringed.
I seriously hope this thread is bait.
Verbose Master Raceclass niceMeme
{
public static void main (String[] args) throws java.lang.Exception
{
int x = 100;
do {
if ((x%5 == 0) && (x%3 == 0)){
System.out.println("fizzbuzz!");
} else if (x%3==0) {
System.out.println("fizz");
} else if (x%5==0){
System.out.println("buzz");
}
x--;
} while (x>0);
}
}
>>56936935
You can and should declare i in the loop parentheses
>>56937089
Why not prior to that?
>>56937103
Extra line
>>56937103
besides >>56937221 its often recommended to limit the scope of a variable as much as possible, so if you don't use i outside of the for loop, then perhaps it should only exist within the for loop.
However, var in Javascript declares a variable with function scope, so unlike in, say, C whereint i;
for (i = 0; i < 20; i++) {
// ...
}
printf("%d\n", i); // fine, i == 19
andfor (int i = 0; i < 20; i++) {
// ...
}
printf("%d\n", i); // error, i doesn't exist
are different because variable declarations have block scope, in Javascriptvar i;
for (i = 0; i < 20; i++) {
// ...
}
console.log(i); // fine, i == 19
andfor (var i = 0; i < 20; i++) {
// ...
}
console.log(i); // fine, i == 19
are the same.
Newer version of Javascript support a keyword "let" that declares variables with block scope, sofor (let i = 0; i < 20; i++) {
// ...
}
console.log(i) // ReferenceError: i is not defined
>>56937081
How is this going to throw an exception?
>>56936935
if(i % 15 === 0)
I dont know if it gets faster...
>>56934650
>tfw learning C for two weeks and am already better than 95% of job applicants.
You actually got me to cringe.
I've read some hardcore spaghetti and disgusting greentext but this is just pathetic, because it's obvious you actually believe it.
import sys
# being code
# end code
sys.exit()
>>56934650
You are almost like some sort of programming god.
We are so impressed I literally had to hold my face.
Tell us more about this feat, this achievement, this blessed zenith you have attained.
>>56936935
1. table lookup
2. appending to a variable could be faster
>>56934650
I just tried this FizzBuzz program. Is my code correct?#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
template<typename T>
using integral_iterator_base_t = std::iterator<std::random_access_iterator_tag, T, std::ptrdiff_t, T, T>;
template<typename T>
class integral_iterator_t : public integral_iterator_base_t<T>
{
using base_t = integral_iterator_base_t<T>;
typename base_t::value_type m_value;
public:
integral_iterator_t() {}
integral_iterator_t( decltype( m_value ) const& value ) : m_value{ value } {}
operator typename base_t::value_type const& () const { return m_value; }
operator typename base_t::value_type& () { return m_value; }
typename base_t::reference operator* () const { return *this; }
};
int main()
{
using uint_iterator_t = integral_iterator_t<unsigned>;
std::transform( uint_iterator_t{ 1 }, uint_iterator_t{ 35 }, std::ostream_iterator<std::string>{ std::cout, ", " },
[]( auto const& value )
{
static std::string lut[] = { {}, "Fizz", "Buzz", lut[ 1 ] + lut[ 2 ] };
lut[ 0 ] = std::to_string( value );
return lut[ !(value % 3) + (!(value % 5) << 1) ];
} );
}
>they're not objective oriented
watch this
class FizzBuzz{constructor(a,b,c){this.d=++a;this.e= + b
this.f=c}};FizzBuzz.prototype.fizzbuzz=function()
{console.log(Array.apply(null,new Array(this.d)).map((i,n)=>
{let c='';this.f.forEach((a,b)=>{switch(this.e){
case 1:/b/.test(n)&&(c+=a);default:(n%b)?c:
c+=a;break}});return(c)?c:n}).slice(1).join('\n'))}
var FizzBuzzer=new FizzBuzz(100,false,new Map(
[[3,'Fizz'],[5,'Buzz'],[7,'Woof']]));FizzBuzzer.fizzbuzz()
l=['']*100
for j,w in [(3,'Fizz'),(5,'Buzz')]:
for i in range(j,101,j):l[i-1] += w
for i in range(100):
if not l[i]:l[i]=str(i+1)
print ' '.join(l)
#include <string.h>
int main()
{
char *l = NULL;
realloc(l, strlen(l)-1);
}
#include <stdlib.h>
int main(){
register int sp asm ("sp");
sp = sp + realloc(sp, 10);
}
>>56940726
What a mess
Is this not a slightly better way to do it? Seems a bit ugly to first check if it has modulo zero with both 3 and 5, and then do it for each of them.def fizz_buzz():
for i in range(1, 101):
choice = ""
if i % 3 == 0:
choice += "Fizz"
if i % 5 == 0:
choice += "Buzz"
if len(choice) > 0:
print(choice)
else:
print(i)
#include <stdio.h>
#include <stdlib.h>
#define BEL_AIR 21
int main()
{
register int eax asm ("eax");
register int ebx asm ("ebx");
char * buff = malloc(BEL_AIR);
for(ebx = 1; ebx <= 100; ebx++){
snprintf(buff, BEL_AIR, "%d", ebx);
printf("%s\n", (ebx % 3 == 0 && ebx % 5 == 0) ? "fizzbuzz" : (ebx % 3 == 0) ? "fizz" : (ebx % 5 == 0) ? "buzz" : buff);
}
}
>>56938356
It's a meme.
>>56936888
Hi dan from collabvm
>>56940574
He isn't even wrong, though.
>>56941906
:ooo
>>56940574
Most cs majors don't know C very well. There's a reason you retards get made fun of.
Array.apply(null, Array(100)).map((x, i) => i + 1).forEach(i => {
if(i % 3 == 0 && i % 5 == 0) console.log(i, 'fizzbuzz')
else if(i % 3 == 0) console.log(i, 'fizz')
else if(i % 5 == 0) console.log(i, 'buzz')
else console.log(i)
})
did I get the job
if ( 1 == 2 ) { 2 = 1 }
#include <stdio.h>
int main() {
int *p;
for (int i = 0; i < 100; ++i) {
p = malloc(1);
printf("0x%x: ", p);
if ((int)p/10 % 3 && (int)p/10 & 5) {
p = 0;
*p = 0;
} else {
if ((int)p/10 % 3) {
printf("Segmentation\n");
} else if ((int)p/10 % 5) {
printf("fault\n");
} else {
printf("0x%x\n", p);
}
}
}
return 0;
}
Did I shitpost good, /g/?
>>56942282
>printf("0x%x: ", p);
GODDAMMIT that was for debugging, please disregard line
>>56935138
I OP had used "else if" then it would be useless, but it this case it is essential.
>>56940726
If you handed me this in a professional environment I would have you hanged.
>>56942341
Can you have coworkers or subordinates hanged? Is that just an American thing?
/* Copy an int MSB-first to the specified buffer */
void buf_intcpy(void *buf, unsigned val)
{
int i;
for (i = 0; i < 4; i++)
((unsigned char *) buf)[i] = val >> ((3 - i) << 3);
}
>>56940700
This is why i hate C++
>>56934650
Super duper unnecesito.for (I = 0; I < 101; I++)
{
((I % 3 == 0) && (I % 5 == 0)) ? printf("\nfizzbuzz") : continue;
I % 3 == 0 ? print("\nfizz") : continue;
I % 5 == 0 ? printf("\nbuzz") : continue;
printf("\n%d", I);
}
>>56942078
That's because there's not a super good reason to know C in this day and age.
Most CS majors take one or two courses that use it to learn Systems Programming and after that it's right back to the things that are actually in use in the industry. Namely ones with garbage collection.
>>56943857
everything was written in C or C++ you delusional fuck.
>>56943857
Garbage collection is unnecessary in C because you actually control what's being allocated dynamically.
>>56943857
t. Programmer
How does it feel to have low expectations of you?