is the assembly to this fewer lines than the source? I looked at the assembly to this with -Os, and the answer is no, barely, the straight assembly is 134 lines while this is 112
for i in range(100): if i == 1: print 1 elif i == 2: print 2 elif i == 3: print "fizz" elif i == 4: print 4 elif i == 5: print "buzz" elif i == 6 print "fizz" elif i == 7 print 7...
Chase Myers
butt ugly GAS syntax .section .datafizz: .ascii "fizz\n"buzz: .ascii "buzz\n"fizzbuzz: .ascii "fizzbuzz\n"buf: .skip 20nl: .ascii "\n".section .text.global _start_start: mov $1, %r151: /* mod 15 */ mov %r15, %rax mov $15, %rbx xor %rdx, %rdx div %rbx cmp $0, %rdx jne 2f mov $4, %rax mov $1, %rbx mov $9, %rdx mov $fizzbuzz, %rcx int $0x80 jmp 6f2: /* mod 3 */ mov %r15, %rax mov $3, %rbx xor %rdx, %rdx div %rbx cmp $0, %rdx jne 3f mov $4, %rax mov $1, %rbx mov $5, %rdx mov $fizz, %rcx int $0x80 jmp 6f3: /* mod 5 */ mov %r15, %rax mov $5, %rbx xor %rdx, %rdx div %rbx cmp $0, %rdx jne 4f mov $4, %rax mov $1, %rbx mov $5, %rdx mov $buzz, %rcx int $0x80 jmp 6f4: /* number to buffer */ mov %r15, %rax mov $buf, %r14 add $20, %r145: dec %r14 mov $10, %rbx xor %rdx, %rdx div %rbx add $'0', %rdx mov %dl, (%r14) cmp $0, %rax jne 5b mov $4, %rax mov $1, %rbx mov $nl, %rdx sub %r14, %rdx inc %rdx mov %r14, %rcx int $0x80 6: /* jump to 1 if counter != 101 */ inc %r15 cmp $101, %r15 jne 1b /* exit */ mov $1, %rax mov $0, %rbx int $0x80 Save as fizzbuzz.S and compile with `as -o fizzbuzz.o fizzbuzz.S; ld -o fizzbuzz fizzbuzz.o`
Andrew Gutierrez
Your fizz-buzz violates KISS principle.
Owen Bennett
KISS principle is for Java pajeets who need interfaces and inheritance
Carson Mitchell
/** * Plays FizzBuzz up to an arbitrary high given integer. * FizzBuzz is a game where the goal is to count up to an integer * n while replacing the multiples of 3 with Fizz, the mutliples * of 5 with Buzz and the multiples of both 3 and 5 with * Fizzbuzz. It is a common entry-level problem for gaujing a software * engineer's expertise and methodological rigor. * @author Dinesh Ratrikasha * @version 1.0.0 * @since 2018-04-07 */public class FizzBuzz { /** * Checks whether an integer is a multiple of another. * @param n The integer to be tested * @param q The divisor to be tested * @return {@code true} if {@code n} is a multiple of {@code q}, {@code false} otherwise */ private static boolean isMultiple(final int n, final int q) { // The integer n is a multiple of q if and only if n = 0 (mod q) return n % q == 0; } /** * Prints the appropriate FizzBuzz message for a given integer. * @param n The number of the message */ private static void printFizzBuzzMessage(final int n) { // Since 3 and 5 are co-prime, (3 | n and 5 | n) iff 15 | n if (isMultiple(n, 15)) System.out.println("Fizzbuzz"); else if (isMultiple(n, 3)) System.out.println("Fizz"); else if (isMultiple(n, 5)) System.out.println("Buzz"); else System.out.println(n); } /** * Program starting point. * @param args Command-line arguments, expected to be of length 1 * @throws SecurityException if a call to {@link System#exit} fails (unlikely) */ public static void main(String[] args) { if (args.length == 1) { try { final int max = Integer.parseInt(args[0]); for (int i = 1; i
Yes we have. : fizz 3 mod 0= if ." fizz" -1 else 0 then ;: buzz 5 mod 0= if ." buzz" -1 else 0 then ;: else -rot or 0= if . then ;: fb 100 0 do i fizz i buzz i else cr loop ;
Alt: : fizz ( n -- ) drop ." Fizz" ;: buzz ( n -- ) drop ." Buzz" ;: fb ( n -- ) drop ." FizzBuzz" ;: vector create does> ( n -- ) over 15 mod cells + @ execute ;vector .fizzbuzz ' fb , ' . , ' . , ' fizz , ' . , ' buzz , ' fizz , ' . , ' . , ' fizz , ' buzz , ' . , ' fizz , ' . , ' . ,
Even if it somehow compiles and works, that still won't explain what that ayyyylmao-tier piece of syntax is supposed to represent
Gabriel Hughes
fucking bloat
Bentley Ward
It's declaring an array with the name main and a size of -1u. -1u is unsigned -1, or 4294967295. It's implicitly typed int, which means the array is 16 GB large on most architectures. The first element is set to 1, all the others are set to 0. All of that is dumped in the binary, so the file will be 16 GB+ and the compiler won't be very responsive. There's no main function, but because the symbol is called "main" the linker will accept it. The executable will be created but won't work.
Isaac Powell
I'd rather take a bloated program than a slow program.
Mason Cook
So I was in the right staying sceptical of actually attempting to compile it.
The suffix "u" makes the compiler read the integer as an unsigned integer. Because it is almost guaranteed that the computer uses two-complement to represent integers, signed -1 is equivalent to the maximum permitted unsigned integer, i.e. 1111 1111 1111 1111... So, he's creating an array of UINT_MAX which contains the number 1 everywhere.
Now, that's not the real trick he's doing. By creating an array called main, he tricks the linker into thinking the contained data is in fact the main() function. I saw this hack implemented by simply declaring a const char array that contained the bytes of a classic "hello, world!" program. Because they were declared as const, they were also executable (since memory cells are either writable or executable in modern computers). That way, it was effectively possible to write a C program without ever declaring a main() function.
Why it would work without declaring the type of the array, or the array as constant I do not know.
Mason Perry
FizzBuzz hardware edition:library IEEE;use IEEE.std_logic_1164.all;use IEEE.numeric_std.all;entity fizzbuzz is port (clk : in std_logic; fizz, buzz : out std_logic);end fizzbuzz;architecture behaviour of fizzbuzz is signal cnt : unsigned(6 downto 0) := "0000001"; signal cnt3, cnt5 : unsigned(2 downto 0) := "001";begin p1: process(clk) begin if rising_edge(clk) then cnt