ITT: We post programming challenges of varying difficulty and laugh as anons struggle to solve them

ITT: We post programming challenges of varying difficulty and laugh as anons struggle to solve them.

Let's start off with a classic. FizzBuzz.

Other urls found in this thread:

joelgrus.com/2016/05/23/fizz-buzz-in-tensorflow/
twitter.com/NSFWRedditImage

Next?

fizzbuzz :: Integer -> IO ()
fizzbuzz = show ( [ fb x | x

>programming challenge thread
>starts with fizz buzz

Thread is dead.

>mom I copy pasted it again im so leet xD

Remove the vowels from any given string.

def remove_vowels(text):
vowels = "aeiou"
result = ""
for char in text:
if char not in vowels:
result += char
return result

string = input("String: ")
print(remove_vowels(string))

import re
print(re.sub('[aeiou]', '', string))

I might be wrong, because I'm not a funcitonak prigrammer, but shouldn't it be like this?

fizzbuzz :: Integer -> IO ()
fizzbuzz = show ( [ fb x | x

CONT:

Try to recover the original string as accurately as possible.

def rem(r, s):
if len(s):
return rem(r, s[1:]) if s[0] in r else s[0] + rem(r, s[1:])
return ''

print rem('aeiou', 'hello world')

clearly superior

Print the number of mines on arbitrary minefields.

Example:

char field[] = {
"* * *",
" * * ",
" * "
};

Becomes:

char field[] = {
"*3*3*",
"2*4*2",
"02*20"
};

...

>clearly superior
>compared to regex which is faster than you looping through every vowel for every letter in a word
fampai..

Nice one..
I'd do it somehow like that:

1. Read in "dictionary.txt" (some dictionary with lots of words)
2. Create a hash table, where the hash for each word is the worditself, only without vowels
3. Lookup the hash value bin for the given input


I'm just too lazy right now to put it up.

wouldn't solve the words that have a consonant typo

...

True.

But user said "as accurately as possible".

It's obviously impossible to make it 100% correct, since the information is lost.

ur cheeky m8

Not bad at all.

Coding like a true WebDev: Letting others do the work..

Python retard here, can some user please explain how this works? I can do fizzbuzz, but not in just five lines!

perhaps, but clearly you wouldn't be getting the most accurate result possible (except for input cases that avoid the issue)

also cases like "hugee", you might get "hog" where a more accurate answer would be "huge"

pic related read it and weep faggots

Would work real good for the first 3 words or so then return nothing after that.

Cute, but won't work if voweless words are legit words or acronyms.

intentional samefag

it just does the math and pulls out the correct string from the string "FizzBuzz"

>FizzBuzz
Please stop

The only good fizzbuzz solution. Also if you don't do everything in javascript you probably don't know anything about computers.

function FizzBuzz (n) {
for (i = 1; i < n; i++) {
var div3 = false;
var div5 = false;

// Sums the digits until less than 10
string = i.toString();
while (string.length > 1) {
var temp = 0;
for (j = 0; j < string.length; j++) {
temp += +string[j];
}
string = temp.toString();
}
// if the result is 0, 3, 6 or 9 it can be divided by 3
if (string == 0 || string == 3 || string == 6 || string == 9) {
div3 = true;
}

// if last digit is 5 or 0 is can be divided by 5
string = i.toString();
if (string[string.length - 1] == 0 || string[string.length - 1] == 5) {
div5 = true;
}

var output = "";
if (div3) {output += "Fizz"}
if (div5) {output += "Buzz"}
if (output == "") {output = i}
console.log(output);
}
}

FizzBuzz(100);

>javascript
>made in 10 days
>good
kek

There are many parts to it.

In most languages, booleans aside, 'or' returns the rightmost expression if the leftmost returns false. In python, an empty string evaluates to false, so it's saying: if it's not fizz, buzz or fizzbuzz, print the number, so that part of the algorithm is sorted.

For the actual magic bit, the : in the square brackets indicates a slice. You will slice the word Fizzbuzz where the start of the slice is left of the :, and the end of the slice is the right of the :

The actual expressions to the left and right of the : use Fermat's little theorem:
i^2 will return 1 if i % 3 != 0, and will return 0 if i % 3 == 0. So if it's divisible by 3, it will return a word beginning with F (you will see it will be Fizz or Fizzbuzz). Otherwise, it will return a word beginning with B (0x4 = 0th index = F. 1x4 = 4th index = B)
i^4 will return 1 if i % 5 != 0, and will return 0 if i % 5 == 0. However, order of operations manipulates it a bit:

First the unary operator - makes i^4 negative, so that modulo will return 0 or 4, rather than 0 or 1.
Then the modulo operator acts. If i % 5 != 0, i^4 % 5 will equal 4. If i % 5 == 0, i^4 % 5 will equal 0.
Then it's subtracted from 8. So if i % 5 != 0, Fizzbuzz will be sliced up to 8-4=4th index. If i % 5 == 0, Fizzbuzz will be sliced up to 8-0=8th index.

To recap, if i is divisible by 3, the string will start at F, otherwise it will start at B
If is divisible by 5, it will end at the last z in Buzz, otherwise it will end at the last z in Fixx.
Otherwise, it will return i

This is all you need to do FizzBuzz

hired

781 is a pretty low amount of characters right?

I made a "proof of concept", not a be-all-end-all solution.

The result of my suggestion would be a list, for example "hg" would output "huge, hug, hag, .." and so on.

So if you want to decide for a result, the only additional information we have in this scenario is the context.

So we need a AI or pretty clever matching algorithm that finds out that "gv hg" might mean "I give you a hug".

But this would be out of scope here, wouldn't it?

thats a lower number of bytes than for a Go program

Wow, thanks.

Reminds me of this:

joelgrus.com/2016/05/23/fizz-buzz-in-tensorflow/

Etvmp$Jsspw%%%%
[e}$xs$ks%$]sy$lezi$wspzih$xli$lmhhir$qiwweki2$Rs{$mx$mw$}syv$xyvr$xs$nsmr
mr$sr$xlmw$tvero2$Hs$rsx$tswx$er}xlmrk$xlex${mpp$kmzi$e{e}$xlmw$qiwweki2$Pix
tistpi$higshi$xli$qiwweki$sr$xlimv$s{r$erh$vieh$xlmw$qiwweki2$]sy$ger$tpe}$epsrk
f}$RSX$tswxmrk$ls{$}sy$higshih$xlmw$qiwweki2$Mrwxieh$tswx$}syv$wspyxmsr$xs$fi$}syv
jezsvmxi$Lipps${svph$tvskveq$mr$sri$perkyeki$sj$}syv$glsmgi2$
Qeoi$wyvi$}syv$tvskveq$we}w$&Lipps$[svph%%%&${mxl$7$%$ex$xli$irh2$Xlmw${e}
tistpi$fvs{wmrk$xli$gleppirki${mpp$xlmro${i$lezi$epp$pswx$syv$qmrhw2$Xlswi${ls$tswx$lipps
{svph$wspyxmsrw${mxlsyx$xli$xlvii$%%%${mpp$lezi$rsx$higshih$xli$qiwweki$erh$ws$}sy$ger$
tspmxip}$tsmrx$syx$xlimv$wspyxmsr$mw$mr$ivvsv$,xli}$evi$nywx$jspps{mrk$epsrk${mxlsyx$ors{mrk-
Irns}$xlmw$jyr2$Xli$xvyxl${mpp$fi$liph$f}$xlswi${ls$ger$higshi$xli$qiwweki2$>-

The above text is an encoded English message. Try to decode it.

The challenge is generating a series of waveforms at specific frequencies, known as musical notes.

You will be given a sample rate in Hz (bytes per second), followed by a duration for each note (milliseconds), and then finally a string of notes represented as the letters A through G (and _ for rest).

You should output a string of bytes (unsigned 8 bit integers) either as a binary stream, or to a binary file. These bytes should represent the waveforms[1] for the frequencies[2] of the notes.

Ideally you would be able to push these frequencies directly to your speakers, but this can be difficult depending on your operating system. Linux systems with ALSA can use aplay.
./solution | aplay -f U8 -r 8000 Other systems can use Audacity, which features a raw data import utility.

The following is your input:
8000
300
ABCDEFG_GFEDCBA

[1] Wikipedia has some formulas for waveform generation. Note that t is measured in wavelengths. en dot wikipedia dot org/wiki/Waveform
[2] This page lists the exact frequencies for every note. phy dot mtu dot edu/~suits/notefreqs dot html

this isn't even a challenge
it's just boring everyday CRUD type work

This shit's fucking easy how can you retards not know how to code.



fizz buzz fizz fizz buzz fizz fizzbuzz

Problem is not well-defined as it's unclear what happens for field where there is a mine and a mine next to it.

you really never played minesweeper?

I posted this code awhile back, in a different way though.

Figure out what language it is, and try to rewrite it better in your own language
on = true


function Function()

word = readline()

if word == "#end\r\n"
!on
quit()
else

for i = 1:length(word)
if (i%2==0)
print(rand(34:234))
end
end

println(" ")

end

end


while on

@time @fastmath Function()

end

Fields in Minesweeper with no mines next to them do not display any number, but your example shows "0". Thus I assumed that Minesweeper rules for field labels do not apply.

stop being autistic

Sorry, I have nothing to do. I'm waiting for gentoo to recompile wine after porting my system to multilib so i can play EVE Online. So I guess you're a little bit late with that requirement.

I like this one
Naive idea:
let nb_row = len(field)
let nb_col = len(field[0])
for i in 0..nb_row:
for j in 0..nb_col:
if field[i][j] == '*': continue
var nb = 0
for r in max(0, i - 1)..min(i + 1, nb_row):
for c in max(0, j - 1)..min(j + 1, nb_col):
if field[r][c] == '*': nb += 1
field[i][j] = $nb

Meant for

say"Fizz"x!($_%3)."Buzz"x!($_%5)||$_ for 1..100

perl -pe 'y/aeiou//d'

perl -E 'open F,"/etc/dictionaries-common/words";@s=;do {$p=$_;y/aeiou//d;$s{$_}="$p " } for @s;say $s{}'

>markup language
>"""""coding"""""

hey bro your keyboard is broken. it keeps repeating quotation marks

>run through base64 decoder

What the fuck do you think the regex does other than loop through every vowel?

how do you think Regex's work? Magic?

>loop through every vowel

>Magic

This is who you share a board with Sup Forums

>being this new

A regexp engine trying to match /[aeiou]/g will try every vowel permutations against characters in the string one by one, and since there's no backtrack it is indeed theoretically equal to a nested loop. But there's the regexp parsing/compilation and probably a lot more branching, so I'd still use two loops (or one loop and 5 tests) for this if performance matters

given a string of arbitrary length, make a module in your language of choice to break it into an array of arrays

this will have 2 arguments: amount of elements in inner array and length of elements in inner array

protip: this is pretty much what you need to do if you want to store a PNG image as colored pixel arrays within a larger array representing the image

>"""""""""""""'being this new"""""""""""""""