fizzbuzz

FizzBuzz in assembly - segmentation fault

牧云@^-^@ 提交于 2019-12-20 08:00:44
问题 I am trying to write FizzBuzz in Assembly and I am seeing segmentation fault all the time. So far I have determined that it is not my printing routines (because I have removed their contents and the problem persists) and the error hides somewhere in the main function. I was getting this output when I run the program: fizzSegmentation fault Leading me to believe that it's not the problem with using division and looking up the remainders. But I could be wrong, I haven't done Assembly in two

Python Fizzbuzz problems with loop

不羁的心 提交于 2019-12-20 05:34:06
问题 I've searched for the answer for about an hour, and it seems most people have coded fizzbuzz a different way than myself. However, having tried everything to figure out why this simple code will not work I'm getting extremely frustrated. Can anyone point out the simple problem I'm sure I'm having? The code runs but it just returns the value 1. def fizzbuzz(intList): for n in intList: if n % 3 == 0 and n % 5 == 0: return n.replace(str(n),"Fizzbuzz") elif n % 3 == 0: return n.replace(str(n),

javascript fizzbuzz switch statement

倾然丶 夕夏残阳落幕 提交于 2019-12-19 18:29:08
问题 I'm currently taking the code academy course on Javascript and I'm stuck on the FizzBuzz task. I need to count from 1-20 and if the number is divisible by 3 print fizz, by 5 print buzz, by both print fizzbuzz, else just print the number. I was able to do it with if/ else if statements, but I wanted to try it with switch statements, and cannot get it. My console just logs the default and prints 1-20. Any suggestions? for (var x = 0; x<=20; x++){ switch(x){ case x%3==0: console.log("Fizz");

Codecademy FizzBuzz app, stuck on step 1

丶灬走出姿态 提交于 2019-12-18 07:13:06
问题 Here's my code for Codecamedy's FizzBuzz lesson var i; for ( i = 1; i > 20; i++ ) { "hello" if ( i % 3 === 0 ) { if ( i % 5 === 0 ) { "FizzBuzz"; } else { "Fizz"; } } else if ( i % 5 === 0 ) { "Buzz"; } else { i; } } I'm trying to first test whether or not the number (i) is divisible by 3. If it is, I then want to check whether it is also divisible by 5. If both conditions are true, I want it to say "FizzBuzz". If only the first condition is true, it should say "Fizz". Then, after determining

Writing FizzBuzz

牧云@^-^@ 提交于 2019-12-17 17:26:09
问题 Reading the coding horror, I just came across the FizzBuzz another time. The original post is here: Coding Horror: Why Can't Programmers.. Program? For those who do not know: FizzBuzz is a quite popular childrens game. Counting from 1 to 100, and every time a number is divisible by 3 calling "Fizz", every time a number is divisible by 5 calling "Buzz" and every time a number is divisible by 3 and 5, calling "FizzBuzz instead of the number But this time, I just started to code it down. It was

FizzBuzz program (details given) in Javascript

不羁的心 提交于 2019-12-17 15:47:33
问题 Can someone please correct this code of mine for FizzBuzz ? There seems to be a small mistake. This code below prints all the numbers instead of printing only numbers that are not divisible by 3 or 5. Write a program that prints the numbers from 1 to 100 . But for multiples of three, print "Fizz" instead of the number, and for the multiples of five, print "Buzz" . For numbers which are multiples of both three and five, print "FizzBuzz" . function isDivisible(numa, num) { if (numa % num == 0)

Why does this ruby use \u001 for 1 and how to change?

☆樱花仙子☆ 提交于 2019-12-11 07:49:18
问题 I've written the classic fizzbuzz code. The spec: describe "can determine fizzbuxx output for" do it "3" do expect(Fizzbuzz.nums(3)).to eq "123fizz" end end The code: class Fizzbuzz def self.nums(n) result="" (1..n).each do |inner| puts "inner #{inner}" result << inner if (inner % 3)==0 result << 'fizz' end if (inner % 5)==0 result << 'buzz' end end result end end Why am I getting \u001 ... instead of 1 ? Failures: 1) can determine fizzbuxx output for 3 Failure/Error: expect(Fizzbuzz.nums(3))

Fizzbuzz program in C

馋奶兔 提交于 2019-12-11 01:29:17
问题 Okay, this really isn't as much a fizzbuzz question as it is a C question. I wrote some simple code in C for printing out fizzbuzz as is required. #include <stdio.h> int main(void) { int n = 30; int i; for (i = 1; i<=n; i++) printf("%s\n", (i % 15) == 0 ? "fizzbuzz" : (i % 5) == 0 ? "buzz" : (i % 3) == 0 ? "fizz" : i); } Now, the last else statement obviously doesn't work since printf is accepting a string whereas 'i' is an int. My question is, is there any sort of cast that I can apply to

FizzBuzz Ruby one-liner

☆樱花仙子☆ 提交于 2019-12-08 18:28:53
问题 Rosettacode.org has this excellent one-line FizzBuzz solution in Ruby. 1.upto(100){|n|puts'FizzBuzz '[i=n**4%-15,i+13]||n} The trouble is, I don’t understand it. The part that puzzles me is the ”n to the power of 4 modulo -15”. Does anyone have an explanation or a reference to an explanation? I want to use this way of selecting substrings in other problems. For more information on FizzBuzz, see [https://rosettacode.org/wiki/FizzBuzz] 回答1: I don't know how they discovered to raise to the

Fizz Buzz in Ruby for dummies

▼魔方 西西 提交于 2019-12-06 10:17:08
问题 Spoiler alert: I am a true novice. Tasked with figuring out fizz buzz in ruby for a class and while I have found more than a few versions of code that solve the problem, my understanding is so rudimentary that I cannot figure out how these examples truly work. First question(refer to spoiler alert if you laugh out loud at this): How do i print out numbers one through 100 in Ruby? Second question: can 'if else" be used to solve this? My failed code is below(attachment has screen shot): puts(