PRIME FIZZBUZZ EDITION
[ f(x) | x i don't understand
Don't call us, we'll call you
Last thread:
PRIME FIZZBUZZ EDITION
[ f(x) | x i don't understand
Don't call us, we'll call you
Last thread:
You forgot the "What are you working on Sup Forums? "
Here I'll do it for you.
What are you working on Sup Forums?
Guise look LOOK!
I can learn ALL of the C++ language watching this YT Tutroial!!!1
>print if x is prime and divisible by 3 5 or 15
>prime and divisible by
>prime
>divisible
#!/usr/bin/env sh
for i in $(seq 1 100); do
if [ $((i % 15)) -eq 0 ]; then
printf 'FizzBuzz '
elif [ $((i % 3)) -eq 0 ]; then
printf 'Fizz '
elif [ $((i % 5)) -eq 0 ]; then
printf 'Buzz '
else
printf '%s ' "$i"
fi
done
Am I doing it right?
>using namespace std;
dropped
Sixth for Python is the best
>he likes to write everything by hand
Try actually reading that code
>uses std
there's a reason it is called STD you know.
don't put a (using namespace _) in the global namespace
Λ means "and" you faglord.
No helping each other.
how did i do guys?
#include
int main()
{
int i = 1;
counter:
while (1)
{
printf("%d, ", i++);
if(i > 100) goto exit;
if(i % 3 == 0) goto fizzer;
if(i % 5 == 0) goto buzzer;
}
fizzer:
while (1)
{
printf("Fizz");
if(i++ % 5 == 0) goto buzzer;
printf(", ");
if(i > 100) goto exit;
if(i % 5 == 0) goto buzzer;
if(i % 5 && i % 3) goto counter;
}
buzzer:
while (1)
{
printf("Buzz, ");
if(++i > 100) goto exit;
if(i % 3 == 0) goto fizzer;
if(i % 5 && i % 3) goto counter;
}
exit:
return 0;
}
Please read the problem before attempting to solve it.
If by prime you mean isprime then you are correct, but if you do you should learn basic function naming, otherwise I will continue on the assumption that prime(n) returns the n-th prime, which will always evaluate to true (in most languages).
goto always triggers my autism.
Enterprise/10
What was the worst place that called you to work for them?
Mine was some "IT company" working with Microsoft Sharepoint, and people called themselves .NET developers.
Is there a sticky somewhere?
I'm learning C++
Watching thenewbostons tutorials, starting to lose me at video 45. Any complimentary literature?
> if [ $((i % 15)) -eq 0 ]; then
Not sure but I guess this isn't even needed. One could just append the buzz. Correct me if wrong.
magnificent
learning regex and shit desu
Ruby or Python? Can't decide but I want to try something more comfy than C.
>tfw this happens in your program
Sometimes I love it when this happens.
A good way to learn shortcuts, glitches also nice for databending when it happens to media processing.
>.gif
>doesn't move
It does move, they're just in gridlock.
Tqbh ruby is more of a structured language than python
there isn't even a switch/pattern match in python!
Sort of related: How to create such glitches?
Language doesn't matter.
If you're going to learn sed, read this:
grymoire.com
It's a god's gift.
also this: grymoire.com
prime(x) = x is prime
ty
easy, don't clear the drawing buffer.
Turn off compositing on your window manager or whatever. Don't ever update your buffer.
If you add in "liver health", this gif is a representation of my life.
>thinks gifs have to have more than one frame
This is a technology board, please leave.
>Don't ever update your buffer.
what ?
Video tutorials suck for learning a language desu
I recommend C++ Primer or any of Bjarne's books.
how to git gud
The image buffer.
You *have to update* the buffer, you just *don't clear* it so the old pixels remain as is.
>[1,100]
What does this part produce, OP? And in general what lang is that?
If only I knew T_T
Learn Haskell and reach satori
It's Haskell with list comprehension
Probably a range enumartor between [1, 100]. Just like range() generator in Python or D's range aggregator expression 1..100. And that's Haskell if I'm not mistaken.
WTF? This is definitely not Haskell, do actually look at it. Plus my problem is that in Haskell,[1,100] produces a list with two elements, in order 1 and 100. Are you OP? If so can you explain yourself?
Again, definitely not an enumerator in Haskell. So either it's not an enumerator or it's not Haskell.
a bit late but i use this for testing regex i dont know regexr.com
>basic substitute one word for another
>I'm learning regex guys!
I just looked it up out of curiosity and there are what seems to be ranges in Haskell.
>[1,100]
Why not [1...] senpai?
That site is great. Don't forget to check out the favorites or whatever they call it. People put up all kinds of neat stuff.
To add onto this, I'm not saying the OP is using ranges because those are indeed list comprehensions as you stated before so I stand corrected, I just wanted to point out that there are ranges in Haskell.
>I can't read haskell code
But, but, but...
Ok, agreed. Still my ongoing quest for wtf is this lang (must be a non-whitespacey ML now that I think about it), but thanks.
Right, why?
IT IS NOT HASKELL FFS read the thread
if you don't update the buffer, the image just froze, nothing happens. do you know what you are talking about ?
>language discussion
Why are you all faggots who don't write software? If you're interested in (existing) languages you're clearly only in it to write masturbatory code.
Right now C (alternatively a small subset of C++) is one of the only languages capable of writing actual software.
>What are you working on Sup Forums
An alternative implementation of a CMIS server to replace our Alfresco installtions which suck.
>the old sickly one lang to rule them all meme
Get the hell back in Mordor, 0/10
Isn't this what you're talking about?
I just took some glfw test code of mine, added an infinite loop before the rendering loop, and turned off my compositor.
#include
#include
#include
#include
#include
#include
#include
struct Rule
{
std::vector divs;
std::string word;
Rule(std::initializer_list divs, const std::string &word)
: divs{divs}
, word{word}
{
}
bool applies(uint32_t i) const
{
for(const auto &div: divs)
{
if((i % div) != 0)
return false;
}
return true;
}
};
struct Range
{
uint32_t from;
uint32_t to;
std::function cb;
Range(uint32_t from, uint32_t to, const std::function &cb)
: from{from}
, to{to}
, cb{cb}
{
}
void run()
{
for(decltype(from) i = from; i rules)
{
applied = false;
if(rule->applies(i))
{
fprintf(stdout, "%s\n", rule->word.c_str());
applied = true;
break;
}
}
if(!applied)
fprintf(stdout, "%d\n", i);
}}).run();
}
};
int main(int, const char **)
{
FizzBuzz f{};
f.add({3, 5}, "FizzBuzz");
f.add({3}, "Fizz");
f.add({5}, "Buzz");
f.run({1, 15});
return 0;
}
print_string:
pusha
mov ah, 0x0e
compare:
mov al, [bx]
cmp al, 0
je end
int 0x10
add bx, 0x1
jmp compare
end:
popa
ret
print_string:
pusha
mov ah, 0x0e
compare:
cmp bx, 0
je end
mov al, [bx]
int 0x10
add bx, 0x1
jmp compare
end:
popa
ret
Anyone know why the top one works but the bottom doesn't?
because they do different things
I'm a Ruby fan personally
How's my Ruby FizzBuzz guise?
(1..100).each do |i|
s = ""
s
How correct is this?
>pic related
Pretty correct. C is obsolete in this day and age and only used in legacy projects.
it's true
look at recent updates in language, they are becoming more ``functional"
soon it will be immutable by default and have more monads
iota(1, 21).map!(a => a.predSwitch!("a % b == 0")(15, "FizzBuzz", 3, "Fizz", 5, "Buzz", a.to!string)).writeln;
>smug Andrei Alexandrescu.jpg
>Tries to criticise C
>Brings up C++
wat?
The arguments against both are the same; tons of little gotchas that make the language a pain in the dick to work with.
C and C++ are completely different languages.
It makes absolutely no sense to lump them together.
Read what I wrote; specifically, both have many little things that can trip you up.
I'm not saying the languages are similar.
I'm saying they both have a particular annoying quality that is solved by higher-level languages.
>both have many little things that can trip you up
You can say that about literally ANY language. No language is perfect at anything.
>I'm saying they both have a particular annoying quality that is solved by higher-level languages.
Which comes with its own costs. Every high level language isn't even close to filling C's niche.
s = ""
vs
s = Array.new
?
not really true, but it's hard to do *good* code these days.
true
true
I'm not quite sure, but the zero terminated stuff is problematic in qutie a few situations
C++ is a world on its own
>anything
"everything" I mean
>the zero terminated stuff is problematic in qutie a few situations
such as?
Hey Sup Forums rate my string sort
string_length = None
def strlen( string ):
global string_length
if string_length == None:
string_length = 0
try:
string[ string_length ]
string_length += 1
except IndexError:
string_length -= 1
string_length_to_return = string_length
string_length = None
return string_length_to_return
return strlen( string )
It is too vague, and makes many claims without anything to back them up.
For example, but not limited to:
>C is anti-efficient
>Not cleaner than assembly
>"""Many""" gotchas and traps
>Not fast.
>Complains about a petty program entrypoint spec. Misuse the term "calling convention"
>Again, vague claims this time about C++
>Vague claims about his langage of choice (probably Go or Rust or D), attacks the community, and again vague claims about C++
That's a hell of a long post to basically say nothing.
He said git gud, not turn into a massive useless faggot.
Absolute trash
enterprise/10
def strlen( string, string_length=None ):
if string_length == None:
string_length = 0
try:
string[ string_length ]
string_length += 1
except IndexError:
string_length -= 1
string_length_to_return = string_length
string_length = None
return string_length_to_return
return strlen( string, string_length )
No need for the global.
>when the IRC starts speaking in Portuguese
Fuck.
I didn't want to talk about programming anyway.
Still absolute trash
Yes evidently.
I'd say this is Pajeet-tier but it's not C# or Java so at least you have that going for you
Well you wouldn't use Array.new because when you print that, it will print each element to a different line, and you want "FizzBuzz" on the same line.
You could use s = String.new but that's literally no different to s = ""
If you want to avoid either of those you could just do this:
(1..100).each do |i|
s = "#{'Fizz' if (i % 3 == 0)}#{'Buzz' if (i % 5 == 0)}"
puts (s.empty? ? i : s)
end
(defn string-length [s]
(cond (empty? s) 0
:else (+ 1 (string-length (rest s)))))
stringLength [] = 0
stringLength (x:xs) = 1 + stringLength xs
I don't know what to say.
Does Python have functional constructs? If so, implement it in those.
How many languages can we implement this in?
std::string::size_type strlen(const std::string &str, std::string::size_type n = -1)
{
if(n == -1)
n = 0;
n = n + 1;
try {
str.at(n);
} catch (std::out_of_range const &) {
return n - 1;
}
return strlen(str, n + 1);
}
By all means, please post about your shortcomings on this Chinese cartoon website, stranger.
Thought I'd take Lua for a spin.
>string sort
>strlen