Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.advocacy > #425480 > unrolled thread
| Started by | fr314159@gmail.com |
|---|---|
| First post | 2017-08-02 11:14 -0700 |
| Last post | 2017-08-06 22:37 -0700 |
| Articles | 20 on this page of 83 — 14 participants |
Back to article view | Back to comp.os.linux.advocacy
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: FizzBuzz: an Interview Question ( for programmers ). fr314159@gmail.com - 2017-08-02 11:14 -0700
Re: FizzBuzz: an Interview Question ( for programmers ). owl <owl@rooftop.invalid> - 2017-08-02 20:19 +0000
Re: FizzBuzz: an Interview Question ( for programmers ). owl <owl@rooftop.invalid> - 2017-08-02 21:06 +0000
Re: FizzBuzz: an Interview Question ( for programmers ). Melzzzzz <Melzzzzz@zzzzz.com> - 2017-08-02 21:37 +0000
Re: FizzBuzz: an Interview Question ( for programmers ). owl <owl@rooftop.invalid> - 2017-08-03 01:46 +0000
Re: FizzBuzz: an Interview Question ( for programmers ). Melzzzzz <Melzzzzz@zzzzz.com> - 2017-08-03 04:32 +0000
Re: FizzBuzz: an Interview Question ( for programmers ). owl <owl@rooftop.invalid> - 2017-08-03 05:01 +0000
Re: FizzBuzz: an Interview Question ( for programmers ). Melzzzzz <Melzzzzz@zzzzz.com> - 2017-08-03 05:06 +0000
Re: FizzBuzz: an Interview Question ( for programmers ). owl <owl@rooftop.invalid> - 2017-08-03 05:15 +0000
Re: FizzBuzz: an Interview Question ( for programmers ). Melzzzzz <Melzzzzz@zzzzz.com> - 2017-08-04 05:02 +0000
Re: FizzBuzz: an Interview Question ( for programmers ). owl <owl@rooftop.invalid> - 2017-08-04 13:52 +0000
Re: FizzBuzz: an Interview Question ( for programmers ). Melzzzzz <Melzzzzz@zzzzz.com> - 2017-08-04 14:00 +0000
Re: FizzBuzz: an Interview Question ( for programmers ). Marek Novotny <marek.novotny@marspolar.com> - 2017-08-04 12:56 -0500
Re: FizzBuzz: an Interview Question ( for programmers ). Steve Carroll <fretwizzer@gmail.com> - 2017-08-04 11:03 -0700
Re: FizzBuzz: an Interview Question ( for programmers ). Melzzzzz <Melzzzzz@zzzzz.com> - 2017-08-04 18:05 +0000
Re: FizzBuzz: an Interview Question ( for programmers ). Steve Carroll <fretwizzer@gmail.com> - 2017-08-04 11:08 -0700
Re: FizzBuzz: an Interview Question ( for programmers ). Snit <usenet@gallopinginsanity.com> - 2017-08-04 11:23 -0700
Re: Marek Novotny is a command line jockey. Marek Novotny <marek.novotny@marspolar.com> - 2017-08-04 14:24 -0500
Re: Marek Novotny is a command line jockey. Snit <usenet@gallopinginsanity.com> - 2017-08-04 12:45 -0700
Re: This is better, no ? Marek Novotny <marek.novotny@marspolar.com> - 2017-08-04 15:24 -0500
Re: Marek Novotny is a command line jockey. Snit <usenet@gallopinginsanity.com> - 2017-08-04 12:38 -0700
Re: My code is twice as fast as Owl's. owl <owl@rooftop.invalid> - 2017-08-03 03:12 +0000
Re: FizzBuzz: an Interview Question ( for programmers ). "F. Russell" <fr@random.info> - 2017-08-02 23:04 +0000
Re: FizzBuzz: an Interview Question ( for programmers ). "F. Russell" <fr@random.info> - 2017-08-02 23:25 +0000
Re: FizzBuzz: an Interview Question ( for programmers ). owl <owl@rooftop.invalid> - 2017-08-03 01:50 +0000
Re: Fabian's code is always slower. owl <owl@rooftop.invalid> - 2017-08-03 04:41 +0000
Re: Fabian's code is always slower. owl <owl@rooftop.invalid> - 2017-08-03 05:17 +0000
Re: What's easier to read/maintain ? owl <owl@rooftop.invalid> - 2017-08-03 05:57 +0000
Re: Fabian's code is always slower. fr314159@gmail.com - 2017-08-03 08:21 -0700
Re: Fabian's code is always slower. Steve Carroll <fretwizzer@gmail.com> - 2017-08-03 09:24 -0700
Re: Fabian's code is always slower. owl <owl@rooftop.invalid> - 2017-08-03 18:41 +0000
Re: FizzBuzz: an Interview Question ( for programmers ). Snit <usenet@gallopinginsanity.com> - 2017-08-03 13:49 -0700
Re: 4 lines, 4 states. Snit <usenet@gallopinginsanity.com> - 2017-08-03 22:11 -0700
Re: 4 lines, 4 states. Snit <usenet@gallopinginsanity.com> - 2017-08-03 22:47 -0700
Re: 4 lines, 4 states. Snit <usenet@gallopinginsanity.com> - 2017-08-03 22:52 -0700
Re: Mozilla ThunderBird. Steve Carroll <fretwizzer@gmail.com> - 2017-08-04 08:54 -0700
Re: Mozilla ThunderBird. Snit <usenet@gallopinginsanity.com> - 2017-08-04 10:43 -0700
Re: FizzBuzz is a trick question. Snit <usenet@gallopinginsanity.com> - 2017-08-04 11:47 -0700
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. Snit <usenet@gallopinginsanity.com> - 2017-08-04 12:51 -0700
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. fr314159@gmail.com - 2017-08-04 12:57 -0700
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. Steve Carroll <fretwizzer@gmail.com> - 2017-08-04 13:02 -0700
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. Melzzzzz <Melzzzzz@zzzzz.com> - 2017-08-04 20:02 +0000
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. Steve Carroll <fretwizzer@gmail.com> - 2017-08-04 13:11 -0700
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. Melzzzzz <Melzzzzz@zzzzz.com> - 2017-08-04 20:17 +0000
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. Steve Carroll <fretwizzer@gmail.com> - 2017-08-04 13:42 -0700
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. "F. Russell" <fr@random.info> - 2017-08-04 23:06 +0000
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. Melzzzzz <Melzzzzz@zzzzz.com> - 2017-08-04 23:32 +0000
Re: I'm the best c coder here. Snit <usenet@gallopinginsanity.com> - 2017-08-04 14:03 -0700
Re: I'm the best c coder here. "F. Russell" <fr@random.info> - 2017-08-04 23:15 +0000
Re: I'm the best c coder here. benj <benj@nobody.net> - 2017-08-04 19:35 -0400
Re: I'm the best c coder here. "F. Russell" <fr@random.info> - 2017-08-05 16:08 +0000
Re: Fabian seldom writes code, much less test it. owl <owl@rooftop.invalid> - 2017-08-05 03:09 +0000
Re: 2 lines, 2^2 states, easily modified to 3^2 states. owl <owl@rooftop.invalid> - 2017-08-05 05:42 +0000
Re: Who'd use "x++", in a loop, to find FizzBuzzGoozKaaz ? owl <owl@rooftop.invalid> - 2017-08-05 07:30 +0000
Re: 2 lines, 2^2 states, easily modified to 3^2 states. Marek Novotny <marek.novotny@marspolar.com> - 2017-08-05 10:19 -0500
Re: 2 lines, 2^2 states, easily modified to 3^2 states. Steve Carroll <fretwizzer@gmail.com> - 2017-08-05 10:13 -0700
Re: 2 lines, 2^2 states, easily modified to 3^2 states. owl <owl@rooftop.invalid> - 2017-08-05 17:33 +0000
Re: Fabian seldom writes code, much less test it. Marek Novotny <marek.novotny@marspolar.com> - 2017-08-04 22:24 -0500
Re: Fabian seldom writes code, much less test it. "F. Russell" <fr@random.info> - 2017-08-05 13:37 +0000
Re: Fabian seldom writes code, much less test it. "F. Russell" <fr@random.info> - 2017-08-05 14:25 +0000
Re: I'm the best c coder here. owl <owl@rooftop.invalid> - 2017-08-05 03:22 +0000
Re: I'm the best c coder here. Marek Novotny <marek.novotny@marspolar.com> - 2017-08-04 22:35 -0500
Re: I'm the best c coder here. owl <owl@rooftop.invalid> - 2017-08-05 04:08 +0000
Re: I reduced Owl's 43 lines to 5. owl <owl@rooftop.invalid> - 2017-08-05 07:25 +0000
Re: Owl's FizBuzGozKaz branches 5 times more often. owl <owl@rooftop.invalid> - 2017-08-05 15:40 +0000
Re: I'm _still_ the best c coder here. owl <owl@rooftop.invalid> - 2017-08-05 06:12 +0000
Re: I'm _still_ the best c coder here. moroney@world.std.spaamtrap.com (Michael Moroney) - 2017-08-05 22:16 +0000
Re: I increment things at the _start_ of a loop. Steve Carroll <fretwizzer@gmail.com> - 2017-08-06 11:04 -0700
Re: I increment things at the _start_ of a loop. moroney@world.std.spaamtrap.com (Michael Moroney) - 2017-08-07 03:24 +0000
Re: I increment things at the _start_ of a loop. Snit <usenet@gallopinginsanity.com> - 2017-08-06 20:35 -0700
Re: "while ( x++ < 100 )" isn't "obscure". moroney@world.std.spaamtrap.com (Michael Moroney) - 2017-08-07 04:59 +0000
Re: I'm the best c coder here. chrisv <chrisv@nospam.invalid> - 2017-08-07 06:59 -0500
Re: I'm the best c coder here. Steve Carroll <fretwizzer@gmail.com> - 2017-08-08 10:23 -0700
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. DFS <nospam@dfs.com> - 2017-08-04 17:56 -0400
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. "F. Russell" <fr@random.info> - 2017-08-04 23:04 +0000
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. Snit <usenet@gallopinginsanity.com> - 2017-08-04 16:09 -0700
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. fellatiohornblower@renlott.org - 2017-08-04 20:13 -0400
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. "F. Russell" <fr@random.info> - 2017-08-05 13:50 +0000
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. "F. Russell" <fr@random.info> - 2017-08-05 15:23 +0000
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. Snit <usenet@gallopinginsanity.com> - 2017-08-05 10:06 -0700
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. Doomsdrzej <.m@nsn.s> - 2017-08-05 11:52 -0400
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. Snit <usenet@gallopinginsanity.com> - 2017-08-05 09:55 -0700
Re: Fabian's code is always slower. Takuya Saitoh <taka0038@gmail.com> - 2017-08-06 22:37 -0700
Page 1 of 5 [1] 2 3 4 5 Next page →
| From | fr314159@gmail.com |
|---|---|
| Date | 2017-08-02 11:14 -0700 |
| Subject | Re: FizzBuzz: an Interview Question ( for programmers ). |
| Message-ID | <bb3c1e91-a8cd-43b5-9ba5-50876521a946@googlegroups.com> |
On Wednesday, August 2, 2017 at 12:17:08 PM UTC-4, Jeff-Relf.Me wrote: > > My answer: > Ha, ha, ha, ha! All the hundreds of programs on Rosetta Code use the division operation (of some kind). Division is computationally expensive. Write the answer without using division of any kind -- and no pre-computed lookup tables either.
[toc] | [next] | [standalone]
| From | owl <owl@rooftop.invalid> |
|---|---|
| Date | 2017-08-02 20:19 +0000 |
| Message-ID | <szb03a.buu4@rooftop.invalid> |
| In reply to | #425480 |
fr314159@gmail.com wrote:
> On Wednesday, August 2, 2017 at 12:17:08 PM UTC-4, Jeff-Relf.Me wrote:
>
>>
>> My answer:
>>
>
> Ha, ha, ha, ha! All the hundreds of programs on Rosetta Code
> use the division operation (of some kind).
>
> Division is computationally expensive.
>
> Write the answer without using division of any kind -- and no
> pre-computed lookup tables either.
>
#include <stdio.h>
#define MAX 100
#define FOO 3
#define BAR 5
void blah(int x){printf("%d\n",x);};
void fizz(int x){printf("Fizz\n");};
void buzz(int x){printf("Buzz\n");};
void fizzbuzz(int x){printf("FizzBuzz\n");};
int main(int argc, char *argv[])
{
void (*f[])(int)={blah,fizz,buzz,fizzbuzz};
int i=0,j=0,v=0;
for(i=1;i<=MAX;i++)
{
for(j=FOO;j<=i;j+=FOO)
{
if(j==i){v+=1;}
}
for(j=BAR;j<=i;j+=BAR)
{
if(j==i){v+=2;}
}
f[v](i);
v=0;
}
return 0;
}
[toc] | [prev] | [next] | [standalone]
| From | owl <owl@rooftop.invalid> |
|---|---|
| Date | 2017-08-02 21:06 +0000 |
| Message-ID | <szb030aba.j3h@rooftop.invalid> |
| In reply to | #425491 |
owl <owl@rooftop.invalid> wrote:
> fr314159@gmail.com wrote:
>> On Wednesday, August 2, 2017 at 12:17:08 PM UTC-4, Jeff-Relf.Me wrote:
>>
>>>
>>> My answer:
>>>
>>
>> Ha, ha, ha, ha! All the hundreds of programs on Rosetta Code
>> use the division operation (of some kind).
>>
>> Division is computationally expensive.
>>
>> Write the answer without using division of any kind -- and no
>> pre-computed lookup tables either.
>>
>
> #include <stdio.h>
>
> #define MAX 100
> #define FOO 3
> #define BAR 5
>
> void blah(int x){printf("%d\n",x);};
> void fizz(int x){printf("Fizz\n");};
> void buzz(int x){printf("Buzz\n");};
> void fizzbuzz(int x){printf("FizzBuzz\n");};
>
> int main(int argc, char *argv[])
> {
> void (*f[])(int)={blah,fizz,buzz,fizzbuzz};
> int i=0,j=0,v=0;
> for(i=1;i<=MAX;i++)
> {
> for(j=FOO;j<=i;j+=FOO)
> {
> if(j==i){v+=1;}
> }
> for(j=BAR;j<=i;j+=BAR)
> {
> if(j==i){v+=2;}
> }
> f[v](i);
> v=0;
> }
> return 0;
> }
>
Let's make that:
int i=0,j=FOO,k=BAR,v=0;
for(i=1;i<=MAX;i++)
{
for(;j<=i;j+=FOO)
{
if(j==i){v+=1;}
}
for(;k<=i;k+=BAR)
{
if(k==i){v+=2;}
}
Then with MAX set to 100000:
anon@lowtide:~/code/fizzbuzz$ time ./fb >fbout
real 0m8.880s
user 0m8.868s
sys 0m0.004s
anon@lowtide:~/code/fizzbuzz$ time ./ff >ffout
real 0m0.020s
user 0m0.012s
sys 0m0.004s
anon@lowtide:~/code/fizzbuzz$ diff fbout ffout
anon@lowtide:~/code/fizzbuzz$
[toc] | [prev] | [next] | [standalone]
| From | Melzzzzz <Melzzzzz@zzzzz.com> |
|---|---|
| Date | 2017-08-02 21:37 +0000 |
| Message-ID | <oltglt$ff1$1@news.albasani.net> |
| In reply to | #425491 |
On 2017-08-02, owl <owl@rooftop.invalid> wrote:
> fr314159@gmail.com wrote:
>> On Wednesday, August 2, 2017 at 12:17:08 PM UTC-4, Jeff-Relf.Me wrote:
>>
>>>
>>> My answer:
>>>
>>
>> Ha, ha, ha, ha! All the hundreds of programs on Rosetta Code
>> use the division operation (of some kind).
>>
>> Division is computationally expensive.
>>
>> Write the answer without using division of any kind -- and no
>> pre-computed lookup tables either.
>>
>
> #include <stdio.h>
>
> #define MAX 100
> #define FOO 3
> #define BAR 5
>
> void blah(int x){printf("%d\n",x);};
> void fizz(int x){printf("Fizz\n");};
> void buzz(int x){printf("Buzz\n");};
> void fizzbuzz(int x){printf("FizzBuzz\n");};
>
> int main(int argc, char *argv[])
> {
> void (*f[])(int)={blah,fizz,buzz,fizzbuzz};
> int i=0,j=0,v=0;
> for(i=1;i<=MAX;i++)
> {
> for(j=FOO;j<=i;j+=FOO)
> {
> if(j==i){v+=1;}
> }
> for(j=BAR;j<=i;j+=BAR)
> {
> if(j==i){v+=2;}
> }
> f[v](i);
> v=0;
> }
> return 0;
> }
>
Here is mine (fasm on Linux)
~/.../examples/tasks >>> cat fizzbuzz.asm
format elf64 executable 3
include 'import64.inc'
interpreter '/lib64/ld-linux-x86-64.so.2'
needed 'libc.so.6'
import exit,printf
segment executable
entry $
xor ebx,ebx
.L0:
vpmovzxdq ymm0,[arr+ebx] ; zero extend to quad word
vpmuludq ymm1,ymm0,yword[cnst3] ; division by multiply and shift
vpsrlq ymm2,ymm1,33
vpmuludq ymm3,ymm2,yword[three] ; multiply
vpcmpeqd ymm4,ymm0,ymm3 ; see difference
vpaddd ymm4,ymm0,ymm4 ; add resulting mask which is -1 if equal
vpshufb ymm4,ymm4,yword[smask] ; mov dwords in right place
vpermq ymm4,ymm4,1000b ; mov 4 dwords in place
vpmuludq ymm1,ymm0,yword[cnst5]
vpsrlq ymm2,ymm1,34
vpmuludq ymm3,ymm2,yword[five]
vpcmpeqd ymm5,ymm0,ymm3
vpaddd ymm5,ymm5,ymm5 ; make that in -2
vpshufb ymm5,ymm5,yword[smask]
vpermq ymm5,ymm5,1000b
vpaddd ymm4,ymm5,ymm4 ; if both matches then -3 would be added
vmovdqa [arr+ebx],xmm4
add ebx,16
cmp ebx,100*4
jl .L0
xor ebx,ebx
.L1:
mov r8,fizzbuzz
mov r9,fizz
mov r10,buzz
mov edx,[arr+rbx*4]
lea esi,[rbx+1]
mov rdi,fmt
sub esi,edx
cmp esi,3 ; if difference is 3 then both matches
cmove rdi,r8
cmp esi,2 ; buzz matches
cmove rdi,r10
cmp esi,1 ; fizz matches
cmove rdi,r9
lea rsi,[rbx+1]
xor eax,eax
call [printf]
inc ebx
cmp ebx,100
jl .L1
xor edi,edi
.exit:
call [exit]
segment writeable
align 16
arr: times 100 dd % ; initialize 1..100
align 32
cnst3 dq 4 dup(2863311531) ; required shift 33
three dq 4 dup(3)
cnst5 dq 4 dup(3435973837) ; required shift 34
five dq 4 dup(5)
smask db 0,1,2,3
db 8,9,10,11
times 4 db -128
times 4 db -128
db 0,1,2,3
db 8,9,10,11
times 4 db -128
times 4 db -128
fmt db '%4d %d',0xa,0
fizz db '%4d fizz',0xa,0
buzz db '%4d buzz',0xa,0
fizzbuzz db '%4d fizzbuzz',0xa,0
~/.../examples/tasks >>> fasm fizzbuzz.asm
flat assembler version 1.71.64 (16384 kilobytes memory)
3 passes, 1546 bytes.
~/.../examples/tasks >>> ./fizzbuzz
1 1
2 2
3 fizz
4 4
5 buzz
6 fizz
7 7
8 8
9 fizz
10 buzz
11 11
12 fizz
13 13
14 14
15 fizzbuzz
16 16
17 17
18 fizz
19 19
20 buzz
21 fizz
22 22
23 23
24 fizz
25 buzz
26 26
27 fizz
28 28
29 29
30 fizzbuzz
31 31
32 32
33 fizz
34 34
35 buzz
36 fizz
37 37
38 38
39 fizz
40 buzz
41 41
42 fizz
43 43
44 44
45 fizzbuzz
46 46
47 47
48 fizz
49 49
50 buzz
51 fizz
52 52
53 53
54 fizz
55 buzz
56 56
57 fizz
58 58
59 59
60 fizzbuzz
61 61
62 62
63 fizz
64 64
65 buzz
66 fizz
67 67
68 68
69 fizz
70 buzz
71 71
72 fizz
73 73
74 74
75 fizzbuzz
76 76
77 77
78 fizz
79 79
80 buzz
81 fizz
82 82
83 83
84 fizz
85 buzz
86 86
87 fizz
88 88
89 89
90 fizzbuzz
91 91
92 92
93 fizz
94 94
95 buzz
96 fizz
97 97
98 98
99 fizz
100 buzz
--
press any key to continue or any other to quit...
[toc] | [prev] | [next] | [standalone]
| From | owl <owl@rooftop.invalid> |
|---|---|
| Date | 2017-08-03 01:46 +0000 |
| Message-ID | <avzv003a.bhu@rooftop.invalid> |
| In reply to | #425493 |
Melzzzzz <Melzzzzz@zzzzz.com> wrote: > > Here is mine (fasm on Linux) > ~/.../examples/tasks >>> cat fizzbuzz.asm > format elf64 executable 3 > include 'import64.inc' > anon@lowtide:~/fasm/fasm$ ./fasm.x64 fizzbuzz.asm flat assembler version 1.71.64 (16384 kilobytes memory, x64) fizzbuzz.asm [2]: include 'import64.inc' error: file not found. anon@lowtide:~/fasm/fasm$ Where to put that? I tried /usr/include. No joy.
[toc] | [prev] | [next] | [standalone]
| From | Melzzzzz <Melzzzzz@zzzzz.com> |
|---|---|
| Date | 2017-08-03 04:32 +0000 |
| Message-ID | <olu908$qj7$1@news.albasani.net> |
| In reply to | #425518 |
On 2017-08-03, owl <owl@rooftop.invalid> wrote: > Melzzzzz <Melzzzzz@zzzzz.com> wrote: >> >> Here is mine (fasm on Linux) >> ~/.../examples/tasks >>> cat fizzbuzz.asm >> format elf64 executable 3 >> include 'import64.inc' >> > > anon@lowtide:~/fasm/fasm$ ./fasm.x64 fizzbuzz.asm > flat assembler version 1.71.64 (16384 kilobytes memory, x64) > fizzbuzz.asm [2]: > include 'import64.inc' > error: file not found. > anon@lowtide:~/fasm/fasm$ > > Where to put that? I tried /usr/include. > No joy. > Put it in current dir ;p -- press any key to continue or any other to quit...
[toc] | [prev] | [next] | [standalone]
| From | owl <owl@rooftop.invalid> |
|---|---|
| Date | 2017-08-03 05:01 +0000 |
| Message-ID | <szbdwo.wa33@rooftop.invalid> |
| In reply to | #425556 |
Melzzzzz <Melzzzzz@zzzzz.com> wrote: > On 2017-08-03, owl <owl@rooftop.invalid> wrote: >> Melzzzzz <Melzzzzz@zzzzz.com> wrote: >>> >>> Here is mine (fasm on Linux) >>> ~/.../examples/tasks >>> cat fizzbuzz.asm >>> format elf64 executable 3 >>> include 'import64.inc' >>> >> >> anon@lowtide:~/fasm/fasm$ ./fasm.x64 fizzbuzz.asm >> flat assembler version 1.71.64 (16384 kilobytes memory, x64) >> fizzbuzz.asm [2]: >> include 'import64.inc' >> error: file not found. >> anon@lowtide:~/fasm/fasm$ >> >> Where to put that? I tried /usr/include. >> No joy. >> > Put it in current dir ;p > That works (needed elf.inc there too), but I get an "Illegal instruction" error. Can't debug fasm code with gdb apparently.
[toc] | [prev] | [next] | [standalone]
| From | Melzzzzz <Melzzzzz@zzzzz.com> |
|---|---|
| Date | 2017-08-03 05:06 +0000 |
| Message-ID | <olub0m$qj7$3@news.albasani.net> |
| In reply to | #425563 |
On 2017-08-03, owl <owl@rooftop.invalid> wrote: > Melzzzzz <Melzzzzz@zzzzz.com> wrote: >> On 2017-08-03, owl <owl@rooftop.invalid> wrote: >>> Melzzzzz <Melzzzzz@zzzzz.com> wrote: >>>> >>>> Here is mine (fasm on Linux) >>>> ~/.../examples/tasks >>> cat fizzbuzz.asm >>>> format elf64 executable 3 >>>> include 'import64.inc' >>>> >>> >>> anon@lowtide:~/fasm/fasm$ ./fasm.x64 fizzbuzz.asm >>> flat assembler version 1.71.64 (16384 kilobytes memory, x64) >>> fizzbuzz.asm [2]: >>> include 'import64.inc' >>> error: file not found. >>> anon@lowtide:~/fasm/fasm$ >>> >>> Where to put that? I tried /usr/include. >>> No joy. >>> >> Put it in current dir ;p >> > > That works (needed elf.inc there too), but I get an "Illegal instruction" > error. Can't debug fasm code with gdb apparently. > You don't have AVX2 unfortunately, I am afraid. -- press any key to continue or any other to quit...
[toc] | [prev] | [next] | [standalone]
| From | owl <owl@rooftop.invalid> |
|---|---|
| Date | 2017-08-03 05:15 +0000 |
| Message-ID | <xbabfa3.arr@rooftop.invalid> |
| In reply to | #425566 |
Melzzzzz <Melzzzzz@zzzzz.com> wrote: > On 2017-08-03, owl <owl@rooftop.invalid> wrote: >> Melzzzzz <Melzzzzz@zzzzz.com> wrote: >>> On 2017-08-03, owl <owl@rooftop.invalid> wrote: >>>> Melzzzzz <Melzzzzz@zzzzz.com> wrote: >>>>> >>>>> Here is mine (fasm on Linux) >>>>> ~/.../examples/tasks >>> cat fizzbuzz.asm >>>>> format elf64 executable 3 >>>>> include 'import64.inc' >>>>> >>>> >>>> anon@lowtide:~/fasm/fasm$ ./fasm.x64 fizzbuzz.asm >>>> flat assembler version 1.71.64 (16384 kilobytes memory, x64) >>>> fizzbuzz.asm [2]: >>>> include 'import64.inc' >>>> error: file not found. >>>> anon@lowtide:~/fasm/fasm$ >>>> >>>> Where to put that? I tried /usr/include. >>>> No joy. >>>> >>> Put it in current dir ;p >>> >> >> That works (needed elf.inc there too), but I get an "Illegal instruction" >> error. Can't debug fasm code with gdb apparently. >> > > You don't have AVX2 unfortunately, I am afraid. > Apparently not. :( anon@lowtide:~/code/fizzbuzz$ grep -o avx /proc/cpuinfo avx avx avx avx avx avx avx avx anon@lowtide:~/code/fizzbuzz$
[toc] | [prev] | [next] | [standalone]
| From | Melzzzzz <Melzzzzz@zzzzz.com> |
|---|---|
| Date | 2017-08-04 05:02 +0000 |
| Message-ID | <om0v5l$ko9$1@news.albasani.net> |
| In reply to | #425570 |
On 2017-08-03, owl <owl@rooftop.invalid> wrote:
> Melzzzzz <Melzzzzz@zzzzz.com> wrote:
>> On 2017-08-03, owl <owl@rooftop.invalid> wrote:
>>> Melzzzzz <Melzzzzz@zzzzz.com> wrote:
>>>> On 2017-08-03, owl <owl@rooftop.invalid> wrote:
>>>>> Melzzzzz <Melzzzzz@zzzzz.com> wrote:
>>>>>>
>>>>>> Here is mine (fasm on Linux)
>>>>>> ~/.../examples/tasks >>> cat fizzbuzz.asm
>>>>>> format elf64 executable 3
>>>>>> include 'import64.inc'
>>>>>>
>>>>>
>>>>> anon@lowtide:~/fasm/fasm$ ./fasm.x64 fizzbuzz.asm
>>>>> flat assembler version 1.71.64 (16384 kilobytes memory, x64)
>>>>> fizzbuzz.asm [2]:
>>>>> include 'import64.inc'
>>>>> error: file not found.
>>>>> anon@lowtide:~/fasm/fasm$
>>>>>
>>>>> Where to put that? I tried /usr/include.
>>>>> No joy.
>>>>>
>>>> Put it in current dir ;p
>>>>
>>>
>>> That works (needed elf.inc there too), but I get an "Illegal instruction"
>>> error. Can't debug fasm code with gdb apparently.
>>>
>>
>> You don't have AVX2 unfortunately, I am afraid.
>>
>
> Apparently not. :(
> anon@lowtide:~/code/fizzbuzz$ grep -o avx /proc/cpuinfo
> avx
> avx
> avx
> avx
> avx
> avx
> avx
> avx
> anon@lowtide:~/code/fizzbuzz$
>
Here is AVX version try this, does two calculations at time (it would be no problem to make it pure sse):
format elf64 executable 3
include 'import64.inc'
interpreter '/lib64/ld-linux-x86-64.so.2'
needed 'libc.so.6'
import exit,printf
segment executable
entry $
xor ebx,ebx
.L0:
vpmovzxdq xmm0,[arr+ebx] ; zero extend to quad word
vpmuludq xmm1,xmm0,xword[cnst3] ; division by multiply and shift
vpsrlq xmm2,xmm1,33
vpmuludq xmm3,xmm2,xword[three] ; multiply
vpcmpeqd xmm4,xmm0,xmm3 ; see difference
vpaddd xmm4,xmm0,xmm4 ; add resulting mask which is -1 if equal
vpshufb xmm4,xmm4,xword[smask] ; mov dwords in right place
vpmuludq xmm1,xmm0,xword[cnst5]
vpsrlq xmm2,xmm1,34
vpmuludq xmm3,xmm2,xword[five]
vpcmpeqd xmm5,xmm0,xmm3
vpaddd xmm5,xmm5,xmm5 ; make that in -2
vpshufb xmm5,xmm5,xword[smask]
vpaddd xmm4,xmm5,xmm4 ; if both matches then -3 would be added
vmovq [arr+ebx],xmm4
add ebx,8
cmp ebx,100*4
jl .L0
xor ebx,ebx
.L1:
mov r8,fizzbuzz
mov r9,fizz
mov r10,buzz
mov edx,[arr+rbx*4]
lea esi,[rbx+1]
mov rdi,fmt
sub esi,edx
cmp esi,3 ; if difference is 3 then both matches
cmove rdi,r8
cmp esi,2 ; buzz matches
cmove rdi,r10
cmp esi,1 ; fizz matches
cmove rdi,r9
lea rsi,[rbx+1]
xor eax,eax
call [printf]
inc ebx
cmp ebx,100
jl .L1
xor edi,edi
.exit:
call [exit]
segment writeable
align 16
arr: times 100 dd % ; initialize 1..100
align 32
cnst3 dq 2 dup(2863311531) ; required shift 33
three dq 2 dup(3)
cnst5 dq 2 dup(3435973837) ; required shift 34
five dq 2 dup(5)
smask db 0,1,2,3
db 8,9,10,11
times 4 db -128
times 4 db -128
fmt db '%4d %d',0xa,0
fizz db '%4d fizz',0xa,0
buzz db '%4d buzz',0xa,0
fizzbuzz db '%4d fizzbuzz',0xa,0
--
press any key to continue or any other to quit...
[toc] | [prev] | [next] | [standalone]
| From | owl <owl@rooftop.invalid> |
|---|---|
| Date | 2017-08-04 13:52 +0000 |
| Message-ID | <xzb33a0ab.u33@rooftop.invalid> |
| In reply to | #425702 |
Melzzzzz <Melzzzzz@zzzzz.com> wrote: > On 2017-08-03, owl <owl@rooftop.invalid> wrote: >> Melzzzzz <Melzzzzz@zzzzz.com> wrote: >>> On 2017-08-03, owl <owl@rooftop.invalid> wrote: >>>> Melzzzzz <Melzzzzz@zzzzz.com> wrote: >>>>> On 2017-08-03, owl <owl@rooftop.invalid> wrote: >>>>>> Melzzzzz <Melzzzzz@zzzzz.com> wrote: >>>>>>> >>>>>>> Here is mine (fasm on Linux) >>>>>>> ~/.../examples/tasks >>> cat fizzbuzz.asm >>>>>>> format elf64 executable 3 >>>>>>> include 'import64.inc' >>>>>>> >>>>>> >>>>>> anon@lowtide:~/fasm/fasm$ ./fasm.x64 fizzbuzz.asm >>>>>> flat assembler version 1.71.64 (16384 kilobytes memory, x64) >>>>>> fizzbuzz.asm [2]: >>>>>> include 'import64.inc' >>>>>> error: file not found. >>>>>> anon@lowtide:~/fasm/fasm$ >>>>>> >>>>>> Where to put that? I tried /usr/include. >>>>>> No joy. >>>>>> >>>>> Put it in current dir ;p >>>>> >>>> >>>> That works (needed elf.inc there too), but I get an "Illegal instruction" >>>> error. Can't debug fasm code with gdb apparently. >>>> >>> >>> You don't have AVX2 unfortunately, I am afraid. >>> >> >> Apparently not. :( >> anon@lowtide:~/code/fizzbuzz$ grep -o avx /proc/cpuinfo >> avx >> avx >> avx >> avx >> avx >> avx >> avx >> avx >> anon@lowtide:~/code/fizzbuzz$ >> > Here is AVX version try this, does two calculations at time (it would be no problem to make it pure sse): > format elf64 executable 3 > include 'import64.inc' > > interpreter '/lib64/ld-linux-x86-64.so.2' > needed 'libc.so.6' > import exit,printf > > segment executable > entry $ > xor ebx,ebx > .L0: > vpmovzxdq xmm0,[arr+ebx] ; zero extend to quad word > vpmuludq xmm1,xmm0,xword[cnst3] ; division by multiply and shift > vpsrlq xmm2,xmm1,33 > vpmuludq xmm3,xmm2,xword[three] ; multiply > vpcmpeqd xmm4,xmm0,xmm3 ; see difference > vpaddd xmm4,xmm0,xmm4 ; add resulting mask which is -1 if equal > vpshufb xmm4,xmm4,xword[smask] ; mov dwords in right place > > vpmuludq xmm1,xmm0,xword[cnst5] > vpsrlq xmm2,xmm1,34 > vpmuludq xmm3,xmm2,xword[five] > vpcmpeqd xmm5,xmm0,xmm3 > vpaddd xmm5,xmm5,xmm5 ; make that in -2 > vpshufb xmm5,xmm5,xword[smask] > > vpaddd xmm4,xmm5,xmm4 ; if both matches then -3 would be added > > vmovq [arr+ebx],xmm4 > add ebx,8 > cmp ebx,100*4 > jl .L0 > xor ebx,ebx > .L1: > mov r8,fizzbuzz > mov r9,fizz > mov r10,buzz > mov edx,[arr+rbx*4] > lea esi,[rbx+1] > mov rdi,fmt > sub esi,edx > cmp esi,3 ; if difference is 3 then both matches > cmove rdi,r8 > cmp esi,2 ; buzz matches > cmove rdi,r10 > cmp esi,1 ; fizz matches > cmove rdi,r9 > lea rsi,[rbx+1] > xor eax,eax > call [printf] > inc ebx > cmp ebx,100 > jl .L1 > xor edi,edi > .exit: > call [exit] > > segment writeable > align 16 > arr: times 100 dd % ; initialize 1..100 > align 32 > cnst3 dq 2 dup(2863311531) ; required shift 33 > three dq 2 dup(3) > cnst5 dq 2 dup(3435973837) ; required shift 34 > five dq 2 dup(5) > smask db 0,1,2,3 > db 8,9,10,11 > times 4 db -128 > times 4 db -128 > > fmt db '%4d %d',0xa,0 > fizz db '%4d fizz',0xa,0 > buzz db '%4d buzz',0xa,0 > fizzbuzz db '%4d fizzbuzz',0xa,0 > > I modified your code a bit to run to 100,000 and print format same across all tests: anon@lowtide:~/fasm/fasm$ time ./owl >owlout real 0m0.024s user 0m0.016s sys 0m0.004s anon@lowtide:~/fasm/fasm$ time ./relf >relfout real 0m0.025s user 0m0.020s sys 0m0.004s anon@lowtide:~/fasm/fasm$ time ./melz >melzout real 0m0.026s user 0m0.020s sys 0m0.004s anon@lowtide:~/fasm/fasm$ wc -l owlout relfout melzout 100000 owlout 100000 relfout 100000 melzout 300000 total anon@lowtide:~/fasm/fasm$ diff --from-file owlout relfout melzout anon@lowtide:~/fasm/fasm$ tail owlout 99991 99992 Fiz 99994 Buz Fiz 99997 99998 Fiz Buz anon@lowtide:~/fasm/fasm$ tail relfout 99991 99992 Fiz 99994 Buz Fiz 99997 99998 Fiz Buz anon@lowtide:~/fasm/fasm$ tail melzout 99991 99992 Fiz 99994 Buz Fiz 99997 99998 Fiz Buz anon@lowtide:~/fasm/fasm$ Some more runs: anon@lowtide:~/fasm/fasm$ time ./owl >owlout real 0m0.024s user 0m0.020s sys 0m0.000s anon@lowtide:~/fasm/fasm$ time ./relf >relfout real 0m0.026s user 0m0.016s sys 0m0.008s anon@lowtide:~/fasm/fasm$ time ./melz >melzout real 0m0.027s user 0m0.028s sys 0m0.000s anon@lowtide:~/fasm/fasm$ time ./owl >owlout real 0m0.024s user 0m0.020s sys 0m0.000s anon@lowtide:~/fasm/fasm$ time ./relf >relfout real 0m0.026s user 0m0.024s sys 0m0.000s anon@lowtide:~/fasm/fasm$ time ./melz >melzout real 0m0.026s user 0m0.024s sys 0m0.000s anon@lowtide:~/fasm/fasm$ anon@lowtide:~/fasm/fasm$ time ./owl >owlout real 0m0.024s user 0m0.020s sys 0m0.000s anon@lowtide:~/fasm/fasm$ time ./relf >relfout real 0m0.026s user 0m0.024s sys 0m0.000s anon@lowtide:~/fasm/fasm$ time ./melz >melzout real 0m0.027s user 0m0.024s sys 0m0.000s anon@lowtide:~/fasm/fasm$
[toc] | [prev] | [next] | [standalone]
| From | Melzzzzz <Melzzzzz@zzzzz.com> |
|---|---|
| Date | 2017-08-04 14:00 +0000 |
| Message-ID | <om1ulk$eo8$3@news.albasani.net> |
| In reply to | #425709 |
On 2017-08-04, owl <owl@rooftop.invalid> wrote: > Melzzzzz <Melzzzzz@zzzzz.com> wrote: >> On 2017-08-03, owl <owl@rooftop.invalid> wrote: >>> Melzzzzz <Melzzzzz@zzzzz.com> wrote: >>>> On 2017-08-03, owl <owl@rooftop.invalid> wrote: >>>>> Melzzzzz <Melzzzzz@zzzzz.com> wrote: >>>>>> On 2017-08-03, owl <owl@rooftop.invalid> wrote: >>>>>>> Melzzzzz <Melzzzzz@zzzzz.com> wrote: >>>>>>>> >>>>>>>> Here is mine (fasm on Linux) >>>>>>>> ~/.../examples/tasks >>> cat fizzbuzz.asm >>>>>>>> format elf64 executable 3 >>>>>>>> include 'import64.inc' >>>>>>>> >>>>>>> >>>>>>> anon@lowtide:~/fasm/fasm$ ./fasm.x64 fizzbuzz.asm >>>>>>> flat assembler version 1.71.64 (16384 kilobytes memory, x64) >>>>>>> fizzbuzz.asm [2]: >>>>>>> include 'import64.inc' >>>>>>> error: file not found. >>>>>>> anon@lowtide:~/fasm/fasm$ >>>>>>> >>>>>>> Where to put that? I tried /usr/include. >>>>>>> No joy. >>>>>>> >>>>>> Put it in current dir ;p >>>>>> >>>>> >>>>> That works (needed elf.inc there too), but I get an "Illegal instruction" >>>>> error. Can't debug fasm code with gdb apparently. >>>>> >>>> >>>> You don't have AVX2 unfortunately, I am afraid. >>>> >>> >>> Apparently not. :( >>> anon@lowtide:~/code/fizzbuzz$ grep -o avx /proc/cpuinfo >>> avx >>> avx >>> avx >>> avx >>> avx >>> avx >>> avx >>> avx >>> anon@lowtide:~/code/fizzbuzz$ >>> >> Here is AVX version try this, does two calculations at time (it would be no problem to make it pure sse): >> format elf64 executable 3 >> include 'import64.inc' >> >> interpreter '/lib64/ld-linux-x86-64.so.2' >> needed 'libc.so.6' >> import exit,printf >> >> segment executable >> entry $ >> xor ebx,ebx >> .L0: >> vpmovzxdq xmm0,[arr+ebx] ; zero extend to quad word >> vpmuludq xmm1,xmm0,xword[cnst3] ; division by multiply and shift >> vpsrlq xmm2,xmm1,33 >> vpmuludq xmm3,xmm2,xword[three] ; multiply >> vpcmpeqd xmm4,xmm0,xmm3 ; see difference >> vpaddd xmm4,xmm0,xmm4 ; add resulting mask which is -1 if equal >> vpshufb xmm4,xmm4,xword[smask] ; mov dwords in right place >> >> vpmuludq xmm1,xmm0,xword[cnst5] >> vpsrlq xmm2,xmm1,34 >> vpmuludq xmm3,xmm2,xword[five] >> vpcmpeqd xmm5,xmm0,xmm3 >> vpaddd xmm5,xmm5,xmm5 ; make that in -2 >> vpshufb xmm5,xmm5,xword[smask] >> >> vpaddd xmm4,xmm5,xmm4 ; if both matches then -3 would be added >> >> vmovq [arr+ebx],xmm4 >> add ebx,8 >> cmp ebx,100*4 >> jl .L0 >> xor ebx,ebx >> .L1: >> mov r8,fizzbuzz >> mov r9,fizz >> mov r10,buzz >> mov edx,[arr+rbx*4] >> lea esi,[rbx+1] >> mov rdi,fmt >> sub esi,edx >> cmp esi,3 ; if difference is 3 then both matches >> cmove rdi,r8 >> cmp esi,2 ; buzz matches >> cmove rdi,r10 >> cmp esi,1 ; fizz matches >> cmove rdi,r9 >> lea rsi,[rbx+1] >> xor eax,eax >> call [printf] >> inc ebx >> cmp ebx,100 >> jl .L1 >> xor edi,edi >> .exit: >> call [exit] >> >> segment writeable >> align 16 >> arr: times 100 dd % ; initialize 1..100 >> align 32 >> cnst3 dq 2 dup(2863311531) ; required shift 33 >> three dq 2 dup(3) >> cnst5 dq 2 dup(3435973837) ; required shift 34 >> five dq 2 dup(5) >> smask db 0,1,2,3 >> db 8,9,10,11 >> times 4 db -128 >> times 4 db -128 >> >> fmt db '%4d %d',0xa,0 >> fizz db '%4d fizz',0xa,0 >> buzz db '%4d buzz',0xa,0 >> fizzbuzz db '%4d fizzbuzz',0xa,0 >> >> > > I modified your code a bit to run to 100,000 and print format > same across all tests: > > anon@lowtide:~/fasm/fasm$ time ./owl >owlout > > real 0m0.024s > user 0m0.016s > sys 0m0.004s > anon@lowtide:~/fasm/fasm$ time ./relf >relfout > > real 0m0.025s > user 0m0.020s > sys 0m0.004s > anon@lowtide:~/fasm/fasm$ time ./melz >melzout > > real 0m0.026s > user 0m0.020s > sys 0m0.004s Heh, seems that printing takes most of execution time :P -- press any key to continue or any other to quit...
[toc] | [prev] | [next] | [standalone]
| From | Marek Novotny <marek.novotny@marspolar.com> |
|---|---|
| Date | 2017-08-04 12:56 -0500 |
| Message-ID | <H46dnWTpbbjZKBnEnZ2dnUU7-VednZ2d@giganews.com> |
| In reply to | #425709 |
On 2017-08-04, owl <owl@rooftop.invalid> wrote: > anon@lowtide:~/fasm/fasm$ tail melzout > 99991 > 99992 > Fiz > 99994 > Buz > Fiz > 99997 > 99998 > Fiz > Buz Playing with FizzBuzz in the bash shell. #!/bin/bash let x=1 while (( x <= 100 )) do ((x % 3 == 0 && x % 5 != 0)) && echo $x Fizz ((x % 3 != 0 && x % 5 == 0)) && echo $x Buzz ((x % 3 == 0 && x % 5 == 0)) && echo $x FizzBuzz ((x % 3 != 0 && x % 5 != 0)) && echo $x ((x++)) done -- Marek Novotny https://github.com/marek-novotny
[toc] | [prev] | [next] | [standalone]
| From | Steve Carroll <fretwizzer@gmail.com> |
|---|---|
| Date | 2017-08-04 11:03 -0700 |
| Message-ID | <8bb984e0-6775-44e3-a1bb-a47fd09b5526@googlegroups.com> |
| In reply to | #425737 |
On Friday, August 4, 2017 at 11:56:28 AM UTC-6, Marek Novotny wrote: > On 2017-08-04, owl <owl@rooftop.invalid> wrote: > > anon@lowtide:~/fasm/fasm$ tail melzout > > 99991 > > 99992 > > Fiz > > 99994 > > Buz > > Fiz > > 99997 > > 99998 > > Fiz > > Buz > > Playing with FizzBuzz in the bash shell. > > #!/bin/bash > > let x=1 > while (( x <= 100 )) > do > ((x % 3 == 0 && x % 5 != 0)) && echo $x Fizz > ((x % 3 != 0 && x % 5 == 0)) && echo $x Buzz > ((x % 3 == 0 && x % 5 == 0)) && echo $x FizzBuzz > ((x % 3 != 0 && x % 5 != 0)) && echo $x > ((x++)) > done Cool... but can any of you guys go: for(i=0;i<1e2;console.log((++i%3?"":"Fizz")+(i%5?"":"Buzz")||i)); I chuckle a bit every time it see that idea ;)
[toc] | [prev] | [next] | [standalone]
| From | Melzzzzz <Melzzzzz@zzzzz.com> |
|---|---|
| Date | 2017-08-04 18:05 +0000 |
| Message-ID | <om2d21$bb2$2@news.albasani.net> |
| In reply to | #425739 |
On 2017-08-04, Steve Carroll <fretwizzer@gmail.com> wrote: > On Friday, August 4, 2017 at 11:56:28 AM UTC-6, Marek Novotny wrote: >> On 2017-08-04, owl <owl@rooftop.invalid> wrote: >> > anon@lowtide:~/fasm/fasm$ tail melzout >> > 99991 >> > 99992 >> > Fiz >> > 99994 >> > Buz >> > Fiz >> > 99997 >> > 99998 >> > Fiz >> > Buz >> >> Playing with FizzBuzz in the bash shell. >> >> #!/bin/bash >> >> let x=1 >> while (( x <= 100 )) >> do >> ((x % 3 == 0 && x % 5 != 0)) && echo $x Fizz >> ((x % 3 != 0 && x % 5 == 0)) && echo $x Buzz >> ((x % 3 == 0 && x % 5 == 0)) && echo $x FizzBuzz >> ((x % 3 != 0 && x % 5 != 0)) && echo $x >> ((x++)) >> done > > Cool... but can any of you guys go: > > for(i=0;i<1e2;console.log((++i%3?"":"Fizz")+(i%5?"":"Buzz")||i)); > > I chuckle a bit every time it see that idea ;) console.log ;) > -- press any key to continue or any other to quit...
[toc] | [prev] | [next] | [standalone]
| From | Steve Carroll <fretwizzer@gmail.com> |
|---|---|
| Date | 2017-08-04 11:08 -0700 |
| Message-ID | <0135c283-508b-45f7-b92a-a58e48f9b10e@googlegroups.com> |
| In reply to | #425740 |
On Friday, August 4, 2017 at 12:05:55 PM UTC-6, Melzzzzz wrote: > On 2017-08-04, Steve Carroll <fretwizzer@gmail.com> wrote: > > On Friday, August 4, 2017 at 11:56:28 AM UTC-6, Marek Novotny wrote: > >> On 2017-08-04, owl <owl@rooftop.invalid> wrote: > >> > anon@lowtide:~/fasm/fasm$ tail melzout > >> > 99991 > >> > 99992 > >> > Fiz > >> > 99994 > >> > Buz > >> > Fiz > >> > 99997 > >> > 99998 > >> > Fiz > >> > Buz > >> > >> Playing with FizzBuzz in the bash shell. > >> > >> #!/bin/bash > >> > >> let x=1 > >> while (( x <= 100 )) > >> do > >> ((x % 3 == 0 && x % 5 != 0)) && echo $x Fizz > >> ((x % 3 != 0 && x % 5 == 0)) && echo $x Buzz > >> ((x % 3 == 0 && x % 5 == 0)) && echo $x FizzBuzz > >> ((x % 3 != 0 && x % 5 != 0)) && echo $x > >> ((x++)) > >> done > > > > Cool... but can any of you guys go: > > > > for(i=0;i<1e2;console.log((++i%3?"":"Fizz")+(i%5?"":"Buzz")||i)); > > > > I chuckle a bit every time it see that idea ;) > > console.log ;) And no curlies!
[toc] | [prev] | [next] | [standalone]
| From | Snit <usenet@gallopinginsanity.com> |
|---|---|
| Date | 2017-08-04 11:23 -0700 |
| Message-ID | <D5AA09B7.AEB0D%usenet@gallopinginsanity.com> |
| In reply to | #425737 |
On 8/4/17, 10:56 AM, in article H46dnWTpbbjZKBnEnZ2dnUU7-VednZ2d@giganews.com, "Marek Novotny" <marek.novotny@marspolar.com> wrote: > On 2017-08-04, owl <owl@rooftop.invalid> wrote: >> anon@lowtide:~/fasm/fasm$ tail melzout >> 99991 >> 99992 >> Fiz >> 99994 >> Buz >> Fiz >> 99997 >> 99998 >> Fiz >> Buz > > Playing with FizzBuzz in the bash shell. > > #!/bin/bash > > let x=1 > while (( x <= 100 )) > do > ((x % 3 == 0 && x % 5 != 0)) && echo $x Fizz > ((x % 3 != 0 && x % 5 == 0)) && echo $x Buzz > ((x % 3 == 0 && x % 5 == 0)) && echo $x FizzBuzz > ((x % 3 != 0 && x % 5 != 0)) && echo $x > ((x++)) > done Tried using mod in AppleScript... and it took FOREVER (going to 100,000 it took it several minutes, even when saved as an app -- which is much faster than running from the Script Editor). Yeah, AppleScript is PAINFULLY slow at stuff like this. -- Personal attacks from those who troll show their own insecurity. They cannot use reason to show the message to be wrong so they try to feel somehow superior by attacking the messenger. They cling to their attacks and ignore the message time and time again. <https://youtu.be/H4NW-Cqh308>
[toc] | [prev] | [next] | [standalone]
| From | Marek Novotny <marek.novotny@marspolar.com> |
|---|---|
| Date | 2017-08-04 14:24 -0500 |
| Subject | Re: Marek Novotny is a command line jockey. |
| Message-ID | <pLOdnU7L6NSdVxnEnZ2dnUU7-UmdnZ2d@giganews.com> |
| In reply to | #425737 |
On 2017-08-04, Jeff-Relf.Me @. <Jeff-Relf.Me@> wrote:
><PRE Style='Font-Family: OCR A, monospace !important;'>
> You ( Marek Novotny ) presented "the best" version of FizzBuzz,
> but it tells us that, for better or worse, you're a command line jockey.
In c
#include <stdio.h>
int main(void) {
int x = 1 ;
while ( x <= 100 ) {
if ( x % 3 == 0 && x % 5 != 0 ) {
printf("%d Fizz\n", x) ;
}
if ( x % 3 != 0 && x % 5 == 0 ) {
printf("%d Buzz\n", x) ;
}
if ( x % 3 == 0 && x % 5 == 0 ) {
printf("%d FizzBuzz\n", x) ;
}
if ( x % 3 != 0 && x % 5 != 0 ) {
printf("%d\n", x) ;
}
x++ ;
}
return 0 ;
}
--
Marek Novotny
https://github.com/marek-novotny
[toc] | [prev] | [next] | [standalone]
| From | Snit <usenet@gallopinginsanity.com> |
|---|---|
| Date | 2017-08-04 12:45 -0700 |
| Subject | Re: Marek Novotny is a command line jockey. |
| Message-ID | <D5AA1CF6.AEB3F%usenet@gallopinginsanity.com> |
| In reply to | #425763 |
On 8/4/17, 12:24 PM, in article
pLOdnU7L6NSdVxnEnZ2dnUU7-UmdnZ2d@giganews.com, "Marek Novotny"
<marek.novotny@marspolar.com> wrote:
> On 2017-08-04, Jeff-Relf.Me @. <Jeff-Relf.Me@> wrote:
>> <PRE Style='Font-Family: OCR A, monospace !important;'>
>> You ( Marek Novotny ) presented "the best" version of FizzBuzz,
>> but it tells us that, for better or worse, you're a command line jockey.
>
> In c
>
> #include <stdio.h>
>
> int main(void) {
>
> int x = 1 ;
>
> while ( x <= 100 ) {
> if ( x % 3 == 0 && x % 5 != 0 ) {
> printf("%d Fizz\n", x) ;
> }
> if ( x % 3 != 0 && x % 5 == 0 ) {
> printf("%d Buzz\n", x) ;
> }
> if ( x % 3 == 0 && x % 5 == 0 ) {
> printf("%d FizzBuzz\n", x) ;
> }
> if ( x % 3 != 0 && x % 5 != 0 ) {
> printf("%d\n", x) ;
> }
> x++ ;
> }
>
> return 0 ;
> }
>
Curious, assuming you wanted to do this for much higher numbers, why you
would use two mods and not an if-than-else structure? If you do 15 first
then it need not check the others -- so seems good to use this logic:
-----
repeat with loop from 1 to WHATEVER
if loop mod 15 = 0 then
WRITE "FizzBuzz\n"
else if loop mod 3 = 0 then
WRITE "Fizz\n"
else if loop mod 5 = 0 then
WRITE "Buzz\n"
else
WRITE loop & "\n"
end if
end repeat
-----
To be clear: NOT saying you are wrong, just curious.
--
Personal attacks from those who troll show their own insecurity. They cannot
use reason to show the message to be wrong so they try to feel somehow
superior by attacking the messenger.
They cling to their attacks and ignore the message time and time again.
<https://youtu.be/H4NW-Cqh308>
[toc] | [prev] | [next] | [standalone]
| From | Marek Novotny <marek.novotny@marspolar.com> |
|---|---|
| Date | 2017-08-04 15:24 -0500 |
| Subject | Re: This is better, no ? |
| Message-ID | <ebmdnf-s9u2ORRnEnZ2dnUU7-d3NnZ2d@giganews.com> |
| In reply to | #425763 |
On 2017-08-04, Jeff-Relf.Me @. <Jeff-Relf.Me@> wrote:
><PRE Style='Font-Family: OCR A, monospace !important;'>
> C wasn't your _first_ choice, Marek Novotny.
> This is better, no ? :
>
> int x = 0, F, B ;
> while ( x++ < 100 ) printf("\n"), F = !(x%3), B = !(x%5), printf(
> F && B ? "FizBuz" : F ? "Fiz" : B ? "Buz" : "%d", x );
Of course it is. Nicely done.
--
Marek Novotny
https://github.com/marek-novotny
[toc] | [prev] | [next] | [standalone]
Page 1 of 5 [1] 2 3 4 5 Next page →
Back to top | Article view | comp.os.linux.advocacy
csiph-web