[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Alright guys! Fizzbuzz time. Write a program that prints the
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 28
Thread images: 2
File: fizzbuzz[1].jpg (12 KB, 362x270) Image search: [Google]
fizzbuzz[1].jpg
12 KB, 362x270
Alright guys! Fizzbuzz time.

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”. You are not allowed to use if statements/conditionals, loops, or arrays! Good luck!
>>
#!/bin/cat
1
2
Fizz
4
Buzz
Fizz
7
8
....


where's my cs degree?
>>
>>55412441
>no if statements/conditionals, loops, or arrays
>>
>>55412441
>You are not allowed to use if statements/conditionals, loops, or arrays!
Is this even possible? I mean, not only explicitly, but without using anything that compiles to the same thing those three compile.
>>
>>55412500
Yes, just use recursion and encode the pattern in something besides an array
>>
>>55412527
>recursion without a conditional

how's that supposed to halt
>>
>>55412500
>Is this even possible?

I found an example of using C++ template metaprogramming to do FizzBuzz. Google it if you want your head to explode.
>>
>>55412441
Are switch statements permitted? What about enums?
>>
>>55412542
Maybe you can configure the runtime callstack to be only 100ish deep and let it throw an exception when calling the method for the 101st time. lol
>>
>>55412441
Does this count?

fb = map f [1..100]
f x = case (mod x 3, mod x 5) of
(0,0) -> "FizzBuzz"
(0,_) -> "Fizz"
(_,0) -> "Buzz"
(_,_) -> show x
>>
>>55412658
OP HERE

NOTHINGS ALLOWED YOU TWATS GODOLUCK LOL

NO LITERALS EITHER
>>
>>55412727
>case
BUZZZZZ CONDITIONAL
>>
>>55412851
What about this

fb = map (a.f) [1..100]

f x = (x,mod x 3,mod x 5)

a (_,0,0) = "FizzBuzz"
a x = b x

b (_,0,_) = "Fizz"
b x = c x

c (_,_,0) = "Buzz"
c (x,_,_) = show x
>>
>>55413022
>fp fag doesn't understand how his language is implemented

I fucking hate you people, you probably think computers run on magic
>>
>>55413225
There's no way you can do this without conditional jumps on machine code level.
>>
>>55413340
see >>55412467
it's probably the only way
>>
>>55413377
printing to stdout would also use loops and conditionals on machine code level somewhere
>>
>>55413429
if we're going this far down the rabbithole, it's probably impossible
>>
Bretty easy
<!DOCTYPE html>
<html>
<head>
<style>
span:nth-child(3n):before{
content: "Fizz";
font-size: initial;
}
span:nth-child(5n):after{
content: "Buzz";
font-size: initial;
}
span:nth-child(3n), span:nth-child(5n){font-size: 0}
span{
font-family: Helvetica;
display: block;
font-weight: 300
}
</style>
</head>
<body>
<span>0</span><span>1</span><span>2</span><span>3</span><span>4</span><span>5</span><span>6</span><span>7</span><span>8</span><span>9</span><span>10</span><span>11</span><span>12</span><span>13</span><span>14</span><span>15</span><span>16</span><span>17</span><span>18</span><span>19</span><span>20</span><span>21</span><span>22</span><span>23</span><span>24</span><span>25</span><span>26</span><span>27</span><span>28</span><span>29</span><span>30</span><span>31</span><span>32</span><span>33</span><span>34</span><span>35</span><span>36</span><span>37</span><span>38</span><span>39</span><span>40</span><span>41</span><span>42</span><span>43</span><span>44</span><span>45</span><span>46</span><span>47</span><span>48</span><span>49</span><span>50</span><span>51</span><span>52</span><span>53</span><span>54</span><span>55</span><span>56</span><span>57</span><span>58</span><span>59</span><span>60</span><span>61</span><span>62</span><span>63</span><span>64</span><span>65</span><span>66</span><span>67</span><span>68</span><span>69</span><span>70</span><span>71</span><span>72</span><span>73</span><span>74</span><span>75</span><span>76</span><span>77</span><span>78</span><span>79</span><span>80</span><span>81</span><span>82</span><span>83</span><span>84</span><span>85</span><span>86</span><span>87</span><span>88</span><span>89</span><span>90</span><span>91</span><span>92</span><span>93</span><span>94</span><span>95</span><span>96</span><span>97</span><span>98</span><span>99</span><span>100.</span>
</body>
</html>
>>
>>55413485
Great job, Daniel Subramanian
>>
>>55413485
your solution outputs 15 instead of FizzBuzz
>>
>>55413485
Loops are used while parsing HTML. Nice try, though.
>>
>>55413515
oh fug
remove the first span
>>55413546
then it's literally imposiible
>>
>>55412718
>throw ... when

That's a conditional. This isn't possible.
>>
>>55413485
oh god my sides
>>
>>55412441
10 PRINT “1“
20 PRINT “2“
30 PRINT “fizz“
40 PRINT “4“
50 PRINT “buzz“
60 PRINT “fizz“
70 PRINT “7“
80 PRINT “8“
90 PRINT “fizz“
100 PRINT “buzz“
110 PRINT “11“
120 PRINT “fizz“
130 PRINT “13“
140 PRINT “14“
150 PRINT “fizzbuzz“
160 PRINT “16“
170 PRINT “17“
180 PRINT “fizz“
190 PRINT “19“
200 PRINT “buzz“
210 PRINT “fizz“
220 PRINT “22“
230 PRINT “23“
240 PRINT “fizz“
250 PRINT “buzz“
260 PRINT “26“
270 PRINT “fizz“
280 PRINT “28“
290 PRINT “29“
300 PRINT “fizzbuzz“
310 PRINT “31“
320 PRINT “32“
330 PRINT “fizz“
340 PRINT “34“
350 PRINT “buzz“
360 PRINT “fizz“
370 PRINT “37“
380 PRINT “38“
390 PRINT “fizz“
400 PRINT “buzz“
410 PRINT “41“
420 PRINT “fizz“
430 PRINT “43“
440 PRINT “44“
450 PRINT “fizzbuzz“
460 PRINT “46“
470 PRINT “47“
480 PRINT “fizz“
490 PRINT “49“
500 PRINT “buzz“
510 PRINT “fizz“
520 PRINT “52“
530 PRINT “53“
540 PRINT “fizz“
550 PRINT “buzz“
560 PRINT “56“
570 PRINT “fizz“
580 PRINT “58“
590 PRINT “59“
600 PRINT “fizzbuzz“
610 PRINT “61“
620 PRINT “62“
630 PRINT “fizz“
640 PRINT “64“
650 PRINT “buzz“
660 PRINT “fizz“
670 PRINT “67“
680 PRINT “68“
690 PRINT “fizz“
700 PRINT “buzz“
710 PRINT “71“
720 PRINT “fizz“
730 PRINT “73“
740 PRINT “74“
750 PRINT “fizzbuzz“
760 PRINT “76“
770 PRINT “77“
780 PRINT “fizz“
790 PRINT “79“
800 PRINT “buzz“
810 PRINT “fizz“
820 PRINT “82“
830 PRINT “83“
840 PRINT “fizz“
850 PRINT “buzz“
860 PRINT “86“
870 PRINT “fizz“
880 PRINT “88“
890 PRINT “89“
>>
>>55415038
900    PRINT “fizzbuzz“
910 PRINT “91“
920 PRINT “92“
930 PRINT “fizz“
940 PRINT “94“
950 PRINT “buzz“
960 PRINT “fizz“
970 PRINT “97“
980 PRINT “98“
990 PRINT “fizz“
1000 PRINT “buzz“
>>
>>55415038
>hiding the loops, conditionals, and arrays behind the PRINT statement
Thread replies: 28
Thread images: 2

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

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.