Skip to content

Instantly share code, notes, and snippets.

@wrenoud
Forked from anonymous/README.md
Last active September 10, 2015 02:31
Show Gist options
  • Save wrenoud/07a13233506e18a9ec78 to your computer and use it in GitHub Desktop.
Save wrenoud/07a13233506e18a9ec78 to your computer and use it in GitHub Desktop.

This is solution for a problem from the Recourse Center's application: https://www.recurse.com/apply

Write a program that prints out the numbers 1 to 100 (inclusive). If the number is divisible by 3, print Crackle instead of the number. If it's divisible by 5, print Pop. If it's divisible by both 3 and 5, print CracklePop. You can use any language.

#include <iostream>
using namespace std;
void main()
{
for (int i = 1; i <= 100; i++)
{
bool divisible = false;
if (i % 3 == 0)
{
cout << "Crackle";
divisible = true;
}
if (i % 5 == 0)
{
cout << "Pop";
divisible = true;
}
if (!divisible) cout << i;
cout << "\n";
}
}
#include <iostream>
#define P(s) std::cout<<s
void main(){for(int i=1;i<=100;i++){int d;if(d=i%3==0)P("Crackle");if(i%5==0){P("Pop");d=1;}if(!d)P(i);P("\n");}}
from __future__ import print_function #future proofing
def isDivisible(number, divisor):
return number % divisor == 0 # check if the residual from division is zero
for i in range(1,101):
output = ""
if isDivisible(i, 3):
output += "Crackle"
if isDivisible(i, 5):
output += "Pop"
print(i if output == "" else output)
for i in range(1,101):
o="Crackle" if i%3==0 else ""+"Pop" if i%5==0 else ""
print(i if o=="" else o)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment