[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Write a fizzbuzz and then write a formal proof of it's

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 179
Thread images: 12

Write a fizzbuzz and then write a formal proof of it's functionality.
>>
>>59816385
Bumping purely for MOAR
>>
>>59816385
tiny head fat body
>>
>>59816385

Fizzbuzz as mentioned in the original article is for 0 to 100 so the printf is enough to formally prove it
>>
for i in $input
if i % 3 = 0
echo fizz
elsif i % 5 = 0
echo buzz
elseif i % 13 = 0
echo fizzbuzz
end
end
>>
>>59816385
You forgot
else echo i
>>
>>59816385
Write a formal description of fizzbuzz or I am spreading a word about your incompetence.
>>
>>59816908
>elseif

you fucking fail, (unironically)

you can't use else if in fizz buzz dummy
>>
>>59816908
>i % 13

wut
>>
class FizzBuzzCommandlet extends Commandlet;

event int Main(string Parms)
{
local int i;
local string S;

while(i++ < 100)
{
S = "";
if(i % 3 == 0)
S $= "Fizz";
if(i % 5 == 0)
S $= "Buzz";
Log(Eval(S=="",i,S));
}
return 0;
}


>formal proof of its functionality
>mfw running the code is not enough to prove it works
>>
>>59817870
>>mfw running the code is not enough to prove it works
Formally it's not. lrn2math, retard
>>
>>59817405
it's called modulo look it up
>>
>>59817945
modulo?
>>
>>59817870
>mfw running the code is not enough to prove it works
This is why mathematics is important for comp sci majors.
You fucking codemonkey.
>>
serious question, can there be a formal proof of fizzbuzz
>>
>>59817145
Why? I've passed interviews with similar code.
>>
>>59818096
that code doesn't work properly
>>
>>59816908
>13
>elseif
>>
>>59818096
what the fuck? it doesn't work dipshit

you need multiple if statements, not if else

how the fuck are you going to do shit on 15???????/
15 is divisble by 3 AND 5 faggot
but with an if else it's going to say "yes" to 3 and then exit the fucking program
>>
>>59816385
who is

>she
>>
>>59818820
It works if you start with 15 instead of 3 or 5.
There's several other problems though.
>>
>>59818893
yea but you might as well just do if modulu 3 echo and if modulu 5 separate
I saw his 13 too
>>
>>59818860
a fat cow
>>
i%15==0?printf("FizzBuzz\n"):i%5==0?printf("Buzz\n"):i%3==0?printf("Fizz\n"):printf("%d\n", i);
>>
Haskellfags will have a field day with this.
>>
>>59819167
no haskell fags here, they don't exist anymore, as haskell is obsolete
plus, I doubt a haskell fag can into formal proof
>>
>>59819248
>plus, I doubt a haskell fag can into formal proof
Not sure if trolling... When you write code in Haskell, half of the formal proof is already done.
>>
>>59819270
nobody here uses haskell, stop talking nonsense
>>
>>59816385
It's just bait guys OP is sitting in his interview right now and can't answer. Don't help him.
>>
>>59816385
#.(loop for i from 1 to 100 do
(format t "~:[~:[~a~;Buzz~]~;Fizz~:[~;Buzz~]~]~%~@*" (zerop (mod i 3)) (zerop (mod i 5)) i))
>>
>>59819364
where do you learn format strings?
>>
>>59819585
http://www.lispworks.com/documentation/lw50/CLHS/Body/22_c.htm
>>
say"Fizz"x!($_%3)."Buzz"x!($_%5)||$_ for 1..100
>>
>>59818079
Why couldn't there be? Draw a circuit and it'll become pretty apparent that it works. I mean you could prove that there are integers that divide by 15, 5, and 3 evenly and some that don't (eg. Something that divides by 2, the lowest prime)
>>
>>59819690
give me an example proof, pls
>>
>>59819289
Read the first chapter of any lambda calculus book, pal.
>>
>>59819719
I've never done a formal proof before, only informal
>>
>>59819738
>says it can be done
>hasn't done one
>>
>>59819248
>I doubt a haskell fag can into formal proof
lowest quality b8 in this thread
>>
File: face.png (16KB, 378x366px) Image search: [Google]
face.png
16KB, 378x366px
>>59818922
Well you're right, turns out I'm retarded. But assuming that I put in 15, and did it first, then wouldn't it work fine? And why is everyone sperging about the elsif?
>>
>>59819759
I'm too brainlet to work out how to represent the truths of prime factorization in conjunction with modulo arithmetic in my head, sorry!
>>
>>59819802
no it wouldn't
why don't you try to fucking run your program and find out what it does?
>>
>>59819861
Surely you don't need to.
Wouldn't the % operator be verified in the spec of the language and then you'd just have to show that your code structure does what you want it to.
>>
File: 1474907149981.jpg (173KB, 1565x724px) Image search: [Google]
1474907149981.jpg
173KB, 1565x724px
Fizz Buzz
>>
>>59820114
holy shit
>>
>>59820114
Looks like a good beat. Post soundcould.
>>
>>59816385
fizzBuzz();
>>
File: Screenshot_20170409-223807.png (118KB, 1080x1920px) Image search: [Google]
Screenshot_20170409-223807.png
118KB, 1080x1920px
>>59820007
????
>>
>>59820610
that's unreal engine
>>
Rate plez
#!/bin/bash

F="Fizz"
B="Buzz"

fb () {
t=${F[$(($i % 3))]}
f=${B[$(($i % 5))]}
if [ -n "$t" -o -n "$f" ]; then
echo $t$f
else
return 1
fi
}

for i in `seq 1 100`; do
fb || echo $i
done
>>
>>59817145

You can use else if, but only if the first condition tests for i % 15. The remaining cases therefore test for divisibility by 3 and 5 respectfully.
>>
>>59820114
lmao what the fuck is this
>>
>>59820747
Honestly, I don't know why I wasted my time with people who can't even figure out how to install arch linux.
>>
def fizzbuzz(i):
return 'FizzBuzz' if i%5==0 and i%3==0 else ('Fizz' if i%3==0 else ('Buzz' if i%5==0 else i))

>>
>>59820740
:)
>>
File: b1-decker-savage.jpg (670KB, 1200x1036px) Image search: [Google]
b1-decker-savage.jpg
670KB, 1200x1036px
>>59820740
Get back in /cum/ schmuck
>>
>still no one has shown a proof for their fizzbuzz
>>
>>59821272
but they proved that it worked
>>
Does anyone here know coq? Sounds very interresding.
>>
>>59821318
Tell me about it?
>>
>>59821367
It's a formal verification framework for programs, I don't know much about it. There's a wikipedia page.
>>
>>59821318
/sci/ here, coq, agda, idris, etc.. are a special class of programming languages called theorem provers. They use dependent types (basically Haskell on steroids) and by abusing the compiler's type checker one is able to verify correctness of theorems (if your CS degree was worth anything this is the part where you recall that theorems = programs).

That said, I don't think you need dependent types to verify correctness of ordinary fizzbuzz. You could probably accomplish the same with Haskell.
>>
>>59821295
lolno
>>
>>59816385
Clever girl
>>
Can somebody coq a fizzbuzz?
>>
>>59821779
I'll cock your fizzbuzz
>>
>>59821894
*I'll cok and fizz in your buzz
>>
>it works
>prove that it works lol
The proof is only relevant if it breaks.
>>
for i in range(1, 101):
fzz = ''
if not i % 3:
fzz += 'fizz'
if not i % 5:
fzz += 'buzz'
print(fzz or i)

The proof writes itself. Also:
>checking 15 or 3 and 5 for divisibility
Fucking plebs, it's sick. If you have more than 2 divisibility checks, you're not a real programmer.
>>
>>59822017
>be told to implement an autopilot system for a plane.
>be told to prove that the implementation is correct.
Kek the proof is only relevant if the plane crashes.

Not only is that wrong but if it breaks it means the proof DOES NOT EXIST.
>>
>>59822242
this is why I use haskell
>>
patrician language coming through

with Ada.Text_IO;
use Ada.Text_IO;

procedure fizzbuzz is
subtype fizz is Integer with Dynamic_Predicate => fizz mod 3 = 0;
subtype buzz is Integer with Dynamic_Predicate => buzz mod 5 = 0;
begin
for i in 1..100 loop
put(i'Img & " ");
if(i in fizz) then
put("Fizz");
end if;
if(i in buzz) then
put("Buzz");
end if;
New_Line;
end loop;
end fizzbuzz;


when will hiroshima add Ada highlighting to /g/
>>
>>59820693
You tried so hard and got so far. But in the end, it doesn't even matter.
>>
>>59822383
What colouring does /g/ use?
>>
File: 1467519225835.png (401KB, 800x1138px) Image search: [Google]
1467519225835.png
401KB, 800x1138px
if some number is divisible by 3 : fizz
else if that number is divisible by 5 : buzz
else if both divisible by 3 and 5 : fizz buzz
otherwise : do nothing and increment that number
>>
package main

import "fmt"

func getFizzBuzzText(number int) string {
if number%3 == 0 && number%5 == 0 {
return "FizzBuzz"
}
if number%3 == 0 {
return "Fizz"
}
if number%5 == 0 {
return "Buzz"
}
return fmt.Sprintf("%d", number)
}

func fizzBuzzService(in <-chan int) <-chan string {
out := make(chan string)
go func() {
defer close(out)
for {
number, ok := <-in
if !ok {
return
}
out <- getFizzBuzzText(number)
}
}()
return out
}

func main() {
in := make(chan int)
go func() {
defer close(in)
for i := 1; i < 101; i++ {
in <- i
}
}()

for text := range fizzBuzzService(in) {
fmt.Println(text)
}
}
>>
>>59822544
otherwise : print number
>>
>>59816385
for x in range(1,101):print(x%3==0)*"Fizz"+(x%5==0)*"Buzz"or x


\documentclass{article}
\usepackage{amsmath}
\begin{document}

\title{Formal FizzBuzz Proof}
\author{Landon J. Powell}
\maketitle

$$
A = [1, 2, "Fizz", 4, "Buzz", ..., 98, "Fizz", "Buzz"]
$$

$$
f(x) = \left\{
\begin{array}{ll}
"FizzBuzz" & \quad x \bmod 15 = 0 \\
"Fizz" & \quad x \bmod 3 = 0 \\
"Buzz" & \quad x \bmod 5 = 0 \\
x
\end{array}
\right.
$$

$$
B = f(i) \text{ for } i = 1, ..., 100
$$

$$
B = A
$$

\end{document}


I can barely remember my piecewise functions.
>>
>>59822544
That is not a formal proof. Even if it was, that isn't FizzBuzz.
>>
>>59822383
Are those dependent types?
>>
>>59818054
>Anon can you write us a program.
Sure thing! Let me just create a formal proof of it first.
>>
>>59821531
Except it works retard. Most jobs don't even require proofs just testing to sigma X to show it works suffiently. On another note in a pure math fashion fizzbuzz would fall short with its 2^31-1 limit.
>>
>>59822910
>would fall short with its 2^31-1 limit.
>pure math
>>
>>59822910
>On another note in a pure math fashion fizzbuzz would fall short with its 2^31-1 limit.
You are clearly brain damaged.

1. In pure math one does not care about the physical world and limitations like that do not matter at all.
2. In a proof one would state a precondition that the numbers given must fall within that range. Alternatively one may allow for larger numbers by properly implementing bignum functionality together with a fast bignum modular division. Such an implementation would likely not only call for a proof of correctness but also a proof of runtime efficiency (as the code would need to be more complicated to handle this sort of thing).

Just because your "jobs" don't require proofs doesn't mean that when asked for a proof it is appropriate to say "but my mommy told me I don't need them most of the time".

Tests are literally placebos and test driven development is garbage for brainlet codemonkeys who are barely even allowed behind a keyboard (inb4 b-b-but that means most software developers are brainlet codemonkeys).

You cannot sufficiently argue that it works unless you can prove it.
>>
>>59822993
(1) is reasonable
(2) turbo autism
>>
int main() {

int i;
for (i=0; i<=100; i++) {
if (i%3==0 && i%5==0) {
printf("FizzBuzz\n");
} else if (i%3==0) {
printf("Fizz\n");
} else if (i%5==0) {
printf("Buzz\n");
} else {
printf("%d\n", i);
}
}

}
>>
>>59822791
In principle yes
The number i is part of the subtypes if it fits the predicate condition i mod 3 = 0 for example
>>
Isn't a correct code a proof in itself? You just 'constructed' the proof.
>>
File: file.png (101KB, 1960x1120px) Image search: [Google]
file.png
101KB, 1960x1120px
>>59816385
SImple
>>
File: fizzbuzz.gif (251KB, 1265x763px) Image search: [Google]
fizzbuzz.gif
251KB, 1265x763px
>>59816385
>>>59823424
>>
>>59823378
Do it faggot.
>>
>>59821524
>You could probably accomplish the same with Haskell.
In Haskell every type is inhabited so I wouldn't trust any """proof """ that comes out of it.
>>
>>59822791
Nope.

>>59823260
>In principle yes
No.
>>
fizzbuzz n | n > 2 = fizzbuzzer [[x] | x <- [n, n-1..1]] []
| otherwise = ["Nobody gives a flying fuck about numbers smaller than 3."]

fizzbuzzer [] ys = ys
fizzbuzzer (x:xs) ys | head x `mod` 3 == 0 && head x `mod` 5 == 0 = fizzbuzzer xs ("fizzbuzz":ys)
| head x `mod` 3 == 0 = fizzbuzzer xs ("fizz":ys)
| head x `mod` 5 == 0 = fizzbuzzer xs ("buzz":ys)
| otherwise = fizzbuzzer xs (show (head x):ys)


I'll consider making a proof.
>>
>>59827467
Why didn't I at least use
fizzbuzzer ([x]:xs) ys

instead?
>>
>>59822875
I hope you'll never work on anything related to self driving vehicles, nor traffic management system.
>>
>>59827631
Would they even hire someone of his kind?
>>
File: 1460027108179.png (29KB, 300x300px) Image search: [Google]
1460027108179.png
29KB, 300x300px
What properties of fizzbuzz would one have to prove to consider that a formal proof of fizzbuzz?
>>
>>59818054
>>59817932

You fucking idiot, FizzButt is defined in [0, 100]. printf is sufficient for a proof (exhaustion).
>>
>>59827721
1 - Does it terminate
2 - Is it correct (is it doing the thing it's meant for)
>>
>>59820114
is this some stupid MDE thing? fucking kill you're self
>>
>>59827799
>thinks a proof can be accomplished with printf and not mathematical argument.

lmao
>>
>>59827836
Are your parents brother and sister?
you don't *need* formal construct for exhaustion.

Are you seriously using induction just to prove something that has a finite domain? Hope you're not doing math o something related
>>
>>59827894
>induction is the only form of proof
Nigga u dumb as hell
>>
>>59827919
I never said induction is your only tool
Learn to reading comprehension, please.
I'll wait you proof that does not use induction then.
>>
>write a formal proof of it's functionality
>it is functionality
No. I don't take orders from illiterates.
>>
>>59828050

OP wrote:
> Write a fizzbuzz and then write a formal proof of it's functionality.
You got :
>>59816908
>>59817870
>>59819121
>>59819364
>>59819650
>>59820114
>>59820693
>>59820740
>>59820797
>>59822076
... and no proof was given.

> Learn to reading comprehension, please.
I think this applies to everybody who posted code in this thread.
>>
>>59816385
how serious is fizzbuzz? Ive done a few alright fizzbuzz's in different languages without to much of a hassle still classing myself as a total noob. Seems like a basic test just to see if youre totally bullshitting or not. amirite?
>>
>>59828209
FizzBuzz is an essential concept of programming, and more widely computer science. It has been originally formulated by John von Neumann in 1954 and remained a singularity until Donald Knuth proposed a solution in his first volume of "The Art of Programming". It's generally a notion only post graduate students can handle without struggling. I guess you are a genious.
>>
>>59828307
come on now, is it really something a employer would ask you to do in an interview? genuinly curious
>>
>>59828364
They might but it's not asked much anymore since everyone knows about it. And yes it's considered easy by most programmers. Just a bullshitter test.
>>
>>59828364
Dunno. I've made interviewee transpose a matrix or stuff like that. FizzBuzz is very simple. However it might be interesting because of the multiple choices you have to handle the different cases.
>>
>>59828307
I remember when it was solved, media were all over it and everyone were excited.
>>
>>59827467
>>59827578
I'm too stupid to make a formal proof. I can do the base case together with an incomplete induction case though.
For every n>2 e N

Basis: n = 3
[[3],[2],[1]] []
[[2],[1]] "fizz":[]
[[1]] "2":"fizz":[]
[] "1":"2":"fizz":[]
["1","2","fizz"]

Induction (not sure how to differentiate fizz and the like from the numbers, or if I even need to):
For arbitrary n, assume:
[[x1], [x2], ... , [xn]] [] = [] "x1":"x2":...:"xn":[]

For n+1:
[[x1], [x2], ... , [xn], [xn+1]] [] = [] "x1":"x2":...:"xn":"xn+1":[]
>>
>>59828676
Uh, small correction:
For arbitrary n, assume:
[[xn], [x(n-1)], ... , [x(n-(n-1))]] [] = [] "x1":"x2":...:"xn":[]

For n+1:
[[x(n+1)], [xn], [x(n-1)] ... , [x(n-(n-1))]] [] = [] "x1":"x2":...:"xn":"xn+1":[]
>>
for (( i=1;i<1000;i++ ))
do if ! (( i%3 )) && ! (( i%5 ))
then echo fizz buzz
elif ! (( i%3 ))
then echo fizz
elif ! (( i%5 ))
then echo buzz
else echo $i
fi
done
>>
>>59828676
>>59828766

What are you trying to share with us ? What is "[ ]" ? Is that a brainfuck subset ? Kindly asking.
>>
>>59828814
It's a list.
>>
>>59816385
global _start

section .data
fizz db "Fizz"
buzz db "Buzz"
a dd 3
b dd 5
c dd 10

section .bss
sb resb 800

section .text
_start:
mov ebx, 1
lea edi, [sb]
.l:
mov ecx, 1

mov eax, ebx
xor edx, edx
div dword [a]
test edx, edx
jnz .c1

lea esi, [fizz]
mov ecx, 4
rep movsb
.c1:
mov eax, ebx
xor edx, edx
div dword [b]
test edx, edx
jnz .c2

lea esi, [buzz]
mov ecx, 4
rep movsb
.c2:
test cl, cl
jz .b

mov eax, ebx
mov rbp, rsp
.l1:
xor edx, edx
div dword [c]
add dx, '0'
push dx
test eax, eax
jnz .l1
.l2:
pop ax
stosb
cmp rbp, rsp
jne .l2

.b:
mov eax, 10
stosb

inc ebx
cmp ebx, 100
jbe .l

sub edi, sb
mov rdx, rdi
lea rsi, [sb]
mov rdi, 1
mov rax, 1
syscall

mov rax, 60
xor rdi, rdi
syscall
>>
>>59816385

>write a formal proof of it's functionality.
gonna need a formal definition of what it means to fizzbuzz then b0ss
>>
>>59829144
>div dword [a]
use shift and subtract instead, anon
>>
>>59829160
well done. I was beginning to doubt /g/'s knowlege of low level programming
>>
i;main(){for(;i++<=99;printf("%s%s%.d\n",i%3?"":"Fizz",i%5?"":"Buzz",(i%3&&i%5)*i));}
>>
 
#include <u.h>
#include <libc.h>

void
main(int argc, char *argv[])
{
for( int n=0; n <= 100; n++ ) {
if( ! ( n % 3 == 0 || n % 5 == 0 ))
print("%d", n);

if( n % 3 == 0 )
print("Fizz");
if( n % 5 == 0 )
print("Buzz");

print("\n");
}
exits(0);
}
>>
>>59819248
>no haskell fags here
>>59827467
>>
>>59827631
You have no idea how business works.
The job goes to the applicant willing to work for the least.
>>
File: ao1PdXw_700b_v1.jpg (82KB, 529x1024px) Image search: [Google]
ao1PdXw_700b_v1.jpg
82KB, 529x1024px
>>59816385
Get on my level, plebs:

https://pastebin.com/X4jzhmfK

(too long to paste here, unfortunately)
>>
take that shit to Reddit, why has /g/ been inundated with this shit for like the past week?

you faggots didn't pay attention in class for the last 4 years or something?

RREEEEEEEEEE
>>
>>59829995
>int main
>no return

You're fired.
>>
; Print a list of numbers from 1 to 100
; - if a number is divisible by 3, replace it with fizz
; - if a number is divisible by 5, replace it with buzz
; - if a number is divisible by both, replace it with fizzbuzz
(define fizzbuzz
(lambda ()
(letrec ((fizzbuzzer
(lambda (n acc)
(if (<= n 0) acc
(let ((fizz (remainder n 3))
(buzz (remainder n 5)))
(cond ((and (= fizz 0) (= buzz 0))
(fizzbuzzer (- n 1) (make-pair "fizzbuzz" acc)))
((= fizz 0)
(fizzbuzzer (- n 1) (make-pair "fizz" acc)))
((= buzz 0)
(fizzbuzzer (- n 1) (make-pair "buzz" acc)))
(else
(fizzbuzzer (- n 1) (make-pair (number->string n)
acc))))))))
(string-appendWith
(lambda (x)
(lambda (s1 s2)
(string-append s1 x s2)))))
(write-string (fold "" (string-appendWith "\n") (fizzbuzzer 100 empty))))))

How about we do parentheses surfing with Racket?
>>
>>59827631
Formal proofs are no guarantee against traffic accidents.
If you get your initial assumptions wrong your proof will still be correct and affirm them, but if what you actually needed was 0.1 second delay instead if 0.3 you're screwed.
>>
came here from /wdg/. What's the hassle?
<!DOCTYPE html> 

<html>
<head>
<title>Fizzbuzz</title>
<meta charset="utf-8">
</head>

<body>
<h1>Fizzbuzz</h1>
<p id="output"></p>
<script>
var output = "";
for(i=1;i<101;i++) {
var fizz = i % 3;
var buzz = i % 5;
if(fizz == 0 && buzz == 0) {
output += "fizzbuzz<br/>";
} else if (fizz == 0) {
output += "fizz<br/>";
} else if (buzz == 0) {
output += "buzz<br/>";
} else {
output += i + "<br/>";
}
}
document.getElementById("output").innerHTML = output;
</script>
</body>
</html>
>>
>>59829160
Don't you mean multiplication and add/shift?
>>
File: Freeman-1121679543.jpg (46KB, 450x396px) Image search: [Google]
Freeman-1121679543.jpg
46KB, 450x396px
>>59820114
do it in LabVIEW next time.

>>59830021
>2020-3
>not understanding template metaprogramming
>shiggy
>>
>>59829995
you might be held against your will and commited to the nearest mental institution for treatment of extreme autism by submitting that
>>
>>59830003
>Doing real computer science is reddit
>>
>>59829995
That's not a formal proof, redditor.
>>
>>59828107
the proof of the pudding is in the eating
>>
>>59830702
>>>/r/ibbit
>>
>>59830712
What?
>>
>>59816908
i hate retards like you
because i get retards like you in projects
>>
>>59830717
Your kind should fuck off to that """"website"""" as you like to call it.
>>
>>59829867
Maybe if you're working in a shit country, fucking faggot.
Are you a mericlap?
>>
>>59830788
why?
>>
>>59830813
Because I am God on this Earth.
>>
>>59830861
That's a very Reddit thing to say
>>
>>59830878
I feel pity for you being such a useless plebeian.
>>
>>59822486
C maybe i dont know stop asking shit questions
>>
>>59831174
How many i need wait answers, kid ???
>>
>>59831358
stop complaining i had to think for a while cant just go around responding to anyone, baka
>>
>>59820114
Lo and behold
>>
for (var n = 1; n <= 100; n++) {
var output = "";
if (!(n % 3))
output += "Fizz";
if (!(n % 5))
output += "Buzz";
console.log(output || n);
}
>>
>>59832126

>console.log(output || n);
I like it.
>>
>>59816385
fizzbuzz doesn't halt how can you formally prove anything?
>>
>>59832182
>I don't know what induction is
>>
>>59832182
>fizzbuzz doesn't halt
>>
>>59832975
fizzbuzz n | n `mod` 3 == 0 && n `mod` 5 == 0 = fizzbuzz (n+1)
| n `mod` 3 == 0 = fizzbuzz (n+1)
| n `mod` 5 == 0 = fizzbuzz (n+1)
| otherwise = fizzbuzz (n+1)

Not sure how to print this though.
>>
def main():
for i in range(1,101):
if i% 3 == 0 or i% 5 == 0:
if i % 3 == 0:
print("Fizz",end='')
if i % 5 == 0:
print("Buzz",end='')
print('')
else:
print(i)
main()


is this what i'm supposed to do
>>
>>59833528
Where's your formal proof of your code?
>>
>>59833589
direct proof
assume i is a rational number
3i will return Fizz, 5i will return buzz, 15i will return FizzBuzz
if i% 3 == 0 print Fizz hyp
3i % 3 == 0 algebra

if i%5 == 0 print Buzz byp
5i % 5 == 0 algebra

if i % 5 == 0 and i % 3 == 0 print FizzBuzz hyp
15i % 5 == 0 algebra
13i % 3 == 0 algebra

therefore i suck and am getting a c in discrete structures
>>
>>59817870
>Commandlets, when will they learn?
>>
>>59833672
correction: line 13 should read
3i % 3 == 0 algebra
>>
>>59828107
Just admit that OP fucking goofed and then ask for a version with proof for any max integer.
>>
>>59833672
Is this the right answer?
>>
an avantgarde fizzbuzz
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<Integer> numbers = new ArrayList<>();

while (true) {

System.out.println("Enter a multiple of 3 or 5, type 0 to quit and check array");

int input = sc.nextInt();

if (input == 0) {
break;
} else if (input % 3 == 0 && input % 5 == 0) {
System.out.println("FizzledBuzzlet");
} else if (input % 3 == 0) {
System.out.println("Fizzled");
} else if (input % 5 == 0) {
System.out.println("Buzzlet");
} else if (input % 3 != 0 && input % 5 != 0) {
System.out.println(input + " is not a multiple of 3 or 5");
}
numbers.add(input);
}
System.out.println((numbers));
}
}
>>
>>59828050
Use a loop invariant and a bound function, dumbass.

I'm not going to post a proof because I literally only came into this thread because I'm a /sci/lon whose curious if any /g/aywads actually know how to do computer science.
>>
>>59835865
computer science theory is stoopit, i only need to know how to be code monkey.
>>
>>59820114
What is this?
>>
>>59835865
Did anyone succeed?
>>
>>59816385
for(int i =0;i<length; i++)
{
printf( (i%3==0) ? "fizz" : (i%5==0) ? "buzz" : (i%15==0) ? "fizzbuzz" : "");
}
>>
>>59835962
fuck I should start with % 15
>>
Programming is so natural to me that trying to formalize a really simple algorythm is insane. It's like trying to prove the grammar of a phrase in my mother tongue. I guess I need to tartar my Qatar more with Floyd–Hoare logic.
>>
>>59816385
int n = 100;

for(int i = 1; i<=n; i++){

if((i%5 == 0) && (i%3 == 0)){

System.out.println("**FizzBuzz**");

}

else if(i%5 == 0){

System.out.println("**Buzz**");

}

else if(i%3 == 0){

System.out.println("**Fizz**");

}

else{

System.out.println(i);

}

}
>>
>not letting the user decide the divisors, the string outputs OR even the upper limit
>>
File: welcome to boost.png (404KB, 1004x1000px) Image search: [Google]
welcome to boost.png
404KB, 1004x1000px
>>59829995
Reminds me of this
>>
>>59835936
lolno

>>59836100
lol, wrong. The proof structure is standard and a small list of properties need to be satisfied. With a simple problem like this they can be satisfied with almost no effort but that makes this sort of thing easier to do, not harder.
>>
>>59836778
>lolno
Nobody even coming close? Is /g/ really this useless?
>>
If you can write a program that produces the expected output given the required input then why the fuck would you need a proof?
That's like saying "Hammer a nail into the wood and then prove the hammer works"
>>
>>59833672
Sorry anon but either you haven't learned how to prove correctness of a program or you're incredibly bad at it. Also, the rationals include negative numbers.

>>59832182
You can use induction for stuff like that. That said if you're writing a fizzbuzz program that takes a 'last number' as input then you would use a loop invariant instead of induction.

>>59836841
Your mathematical proof of correctness doesn't just prove it is correct but defines when exactly it is correct. That is to say that it takes side effects into account, defines preconditions/postconditions (including state), and does other shit. Without a proof it's possible that the code may work in some context or with some values but fail unexpectedly in other situations.

Not needing a proof because you're so convinced that your code works is like refusing to look through Galileo's telescope because you are completely convinced that the Earth is the center of the solar system. It's the worst place to be philosophically.

>>59830054
While your assessment is correct, it is not sufficient to discard the necessity of proofs. If anything it reaffirms them and places an emphasis on having proper preconditions.

>>59829153
This is not a proof but it is definitely the correct thing to do in any such scenario.

>>59836815
No, no one is coming close, which is actually very surprising to me as I expected this was a pretty standard requirement for CS degrees. Of course it's also possible that /g/ just has a bunch of dropouts and consumer whores instead of CS graduates.
Thread posts: 179
Thread images: 12


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.