Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Dec 1, 2021. It is now read-only.

Commit fd65813

Browse files
Merge pull request #169 from tlseabra/master
added about 30 solutions in various languages
2 parents 2d9f25d + 5f95694 commit fd65813

File tree

32 files changed

+850
-13
lines changed

32 files changed

+850
-13
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//tlseabra @github
2+
3+
#include <stdio.h>
4+
#include <math.h>
5+
#include <string.h>
6+
7+
float shannon(char* str){
8+
float count[128] = {0};
9+
float sum = 0;
10+
for(int i=0; i < strlen(str); i++)
11+
count[str[i]]++;
12+
13+
for(int i=0; i < 128; i++)
14+
sum += count[i] ? (count[i] / strlen(str)) * log2f(count[i] / strlen(str)) : 0;
15+
16+
return -1 * sum;
17+
}
18+
19+
int main(int argc, char* argv[]){
20+
printf("%f", shannon(argv[1]));
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//tlseabra @github
2+
#include <stdio.h>
3+
4+
float p(int d, int h){
5+
if(h > d)
6+
return (1 / (float) d) * p(d, h-d);
7+
else
8+
return (1 / (float) d * (d-h+1));
9+
}
10+
11+
int main(void){
12+
int input[][2] = {{4,1}, {4,4}, {4,5}, {4,6}, {1,10}, {100, 200}, {8,20}};
13+
for(int i=0; i < 7; i++)
14+
printf("%3d : %3d --> %0.5f\n", input[i][0], input[i][1], p(input[i][0], input[i][1]));
15+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//tlseabra @github
2+
#include <string.h>
3+
#include <stdio.h>
4+
5+
unsigned char validSymbol(char *n, char *s){
6+
if(strlen(s) != 2) return 0;
7+
8+
char name[50], symbol[3];
9+
strcpy(name, n);
10+
strcpy(symbol, s);
11+
name[0] += 32; //making the first letter
12+
symbol[0] += 32; //of each string lowercase;
13+
for(int i=0, index=0, flag; i < 2; i++){
14+
flag = 0;
15+
for(int j=index; j < strlen(name); j++){
16+
if(symbol[i] == name[j]){
17+
index = j+1;
18+
flag++;
19+
break;
20+
}
21+
}
22+
if(!flag) return 0;
23+
}
24+
return 1;
25+
}
26+
27+
int main(int argc, char* argv[]){
28+
printf("%s, %s -> %s\n", argv[1],
29+
argv[2],
30+
validSymbol(argv[1], argv[2]) ? "true" : "false");
31+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# tlseabra @github
2+
3+
4+
fizzbuzz <- function(n){
5+
for(i in 1:n){
6+
a <- if(i%%3 == 0 && i%%5 == 0){
7+
"FizzBuzz"
8+
} else if(i%%3 == 0){
9+
"Fizz"
10+
} else if(i%%5 == 0){
11+
"Buzz"
12+
} else{
13+
i
14+
}
15+
print(a, quote = FALSE)
16+
}
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// tlseabra @github
2+
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
6+
int main(int argc, char* argv[]){
7+
8+
int n = (int) strtol(argv[1], NULL, 10);
9+
10+
for(int i = 1; i <= n; i++){
11+
if(i%3 == 0 && i%5 == 0){
12+
printf("FizzBuzz\n");
13+
}else if(i%3 == 0){
14+
printf("Fizz\n");
15+
}else if(i%5 == 0){
16+
printf("Buzz\n");
17+
}else{
18+
printf("%d\n", i);
19+
}
20+
}
21+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// tlseabra @github
2+
use std::io;
3+
use std::io::Write;
4+
5+
fn main(){
6+
print!("Input a number: ");
7+
io::stdout().flush().unwrap();
8+
let mut x = String::new();
9+
io::stdin().read_line(&mut x).expect("Failed to read number.");
10+
let x: u32 = x.trim().parse().expect("Please enter a number.");
11+
for i in 1..x+1 {
12+
if i%3 == 0 && i%5 == 0 {
13+
println!("FizzBuzz");
14+
} else if i%3 == 0 {
15+
println!("Fizz");
16+
} else if i%5 == 0 {
17+
println!("Buzz");
18+
} else{
19+
println!("{}", i);
20+
}
21+
}
22+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// tlseabra @github
2+
3+
Array.apply(null, { length: 1000 }).map((_, i) => console.log(i+1));
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// tlseabra @github
2+
3+
var input = prompt("Please enter a sentence:");
4+
5+
for(var line ="*", pad="*", i=0; i < input.length+2; i++){
6+
line+="*";
7+
pad+=" ";
8+
}
9+
line+="*\n";
10+
pad+="*\n";
11+
12+
console.log(line + pad + "* " + input + " *\n" + pad + line);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// tlseabra @github
2+
3+
function txtBreak(input){
4+
var broken = input.split(/[\.\!\?]/g);
5+
var output = broken.reduce((pre, curr) => curr.length > pre.length ? curr : pre);
6+
console.log(output);
7+
console.log(output.split(" ").filter(a => a.length > 0).length);
8+
output = output.split(" ").map( a => a.replace(/[,円\;]/, ""));
9+
for(var i = 0, words = []; i < output.length; i++){
10+
if(output[i].length > 4){
11+
words.push(output[i]);
12+
}
13+
}
14+
console.log(words.toString());
15+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* 18/12/2016 */
2+
3+
function drawBoard(rows, cols, width, height){
4+
var output = "";
5+
6+
for(var i = 0; i < rows; i++){
7+
for(var j = 0; j < (width + 1) * cols + 1; j++){
8+
output += "*";
9+
}
10+
output += "\n";
11+
for(var j = 0; j < height; j++){
12+
for(var k = 0; k < cols; k++){
13+
output += "*";
14+
if( (!(i%2) && k%2) || (i%2 && !(k%2)) ){
15+
for(l = 0; l < width; l++){
16+
output += "#";
17+
}
18+
}else{
19+
for(l = 0; l < width; l++){
20+
output += " ";
21+
}
22+
}
23+
}
24+
output += "*\n";
25+
}
26+
}
27+
28+
for(var j = 0; j < (width + 1) * cols + 1; j++){
29+
output += "*";
30+
}
31+
32+
console.log(output);
33+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /