Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
BRivasTorres committed Jan 1, 2024
2 parents 0cef203 + 6b63ff6 commit 613a648
Show file tree
Hide file tree
Showing 6 changed files with 271 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class nwpablodeveloper {
public static void main(String[] args) {
for(int i=1;i<=100;i++){
String out= (i%3==0 && i%5==0)?"fizzbuzz"
:(i%5 == 0 )?"buzz"
:(i%3 == 0 )?"buzz":String.valueOf(i);
System.out.println(i+"\t"+out);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(()=>{
for(let i = 1; i<=100; i++){
let out = (i % 3 == 0 && i % 5 == 0) ? "fizzbuzz"
: (i % 3 == 0) ? "fizz"
: (i % 5 == 0) ? "buzz" : i;
console.log(out)
}
})()
24 changes: 24 additions & 0 deletions Retos/Reto #10 - LA API [Media]/go/anita-87.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"io"
"log"
"net/http"
)

func main() {
c := http.Client{}

resp, err := c.Get("https://uselessfacts.jsph.pl/api/v2/facts/random")
if err != nil {
log.Fatalf("Error: %v", err)
}
defer resp.Body.Close()

data, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatalf("Error: %v", err)
}

log.Printf("Response: %v", string(data))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import pygame
import sys
import random

# Initialize Pygame
pygame.init()

# Screen configuration
width, height = 800, 600
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Car Race")

# Color definitions
white = (255, 255, 255)
black = (0, 0, 0)
red = (255, 0, 0)

# Class definitions
class Car(pygame.sprite.Sprite):
"""Class to represent a car sprite."""
def __init__(self, color, width, height, x, y):
"""
Initialize a car sprite.
Args:
color (tuple): RGB color tuple (e.g., (255, 0, 0) for red).
width (int): Width of the car sprite.
height (int): Height of the car sprite.
x (int): Initial x-coordinate of the car sprite.
y (int): Initial y-coordinate of the car sprite.
"""
super().__init__()

self.image = pygame.Surface([width, height])
self.image.fill(white)
self.image.set_colorkey(white)

pygame.draw.rect(self.image, color, [0, 0, width, height])

self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y

def move(self, x_change, y_change):
"""
Move the car by changing its x and y coordinates.
Args:
x_change (int): Change in the x-coordinate.
y_change (int): Change in the y-coordinate.
"""
self.rect.x += x_change
self.rect.y += y_change

# Function to generate random obstacles
def generate_obstacles():
"""
Generate a group of random obstacles.
Returns:
pygame.sprite.Group: Group of obstacle sprites.
"""
obstacles = pygame.sprite.Group()
for _ in range(5):
obstacle = Car(black, 30, 30, random.randrange(width - 30), random.randrange(height - 30))
obstacles.add(obstacle)
return obstacles

# Create players and obstacles
player1 = Car(red, 50, 50, 50, height // 2 - 25)
player2 = Car(red, 50, 50, 50, height // 2 - 25)
obstacles = generate_obstacles()

# Sprite groups
all_sprites = pygame.sprite.Group()
all_sprites.add(player1, player2, obstacles)

# Clock to control game speed
clock = pygame.time.Clock()

# Main game loop
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()

# Game logic
keys = pygame.key.get_pressed()
player1.move(keys[pygame.K_RIGHT] - keys[pygame.K_LEFT], keys[pygame.K_DOWN] - keys[pygame.K_UP])

# Collision detection with obstacles
collisions = pygame.sprite.spritecollide(player1, obstacles, False)
if collisions:
player1.rect.x = 50
player1.rect.y = height // 2 - 25

# Update the screen
screen.fill(white)
all_sprites.draw(screen)

# Update the screen
pygame.display.flip()

# Control game speed
clock.tick(30)
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
def calculate_points(word):
"""
Calculate the points for a word based on the assigned value for each letter.
Args:
word (str): The word for which the points will be calculated.
Returns:
int: Total points for the word.
"""
letter_values = {
"A": 1, "B": 2, "C": 3, "D": 4, "E": 5, "F": 6, "G": 7, "H": 8, "I": 9,
"J": 10, "K": 11, "L": 12, "M": 13, "N": 14, "Ñ": 15, "O": 16, "P": 17,
"Q": 18, "R": 19, "S": 20, "T": 21, "U": 22, "V": 23, "W": 24, "X": 25,
"Y": 26, "Z": 27,
}
total_points = sum(letter_values.get(letter.upper(), 0) for letter in word)
return total_points


def word_100_points_game():
"""
Game to accumulate points by forming words.
The game ends when 100 points or more are reached in a word.
"""
print('''
Rules: To win, you must enter a word and the sum of its
letters should be 100 points. The letter 'A' is worth 1 point and 'Z'
is worth 27 points. It is case-insensitive. Enjoy the game!
''')
total_points = 0

while total_points < 100:
word = input("Enter a word: ")
word_points = calculate_points(word)

print(f"Word: {word}, Points for the word: {word_points}")

if word_points >= 100:
print("Congratulations! You have reached 100 points.")
break

print(f'Total accumulated points: {total_points + word_points}')
print('Do you want to try again? (Y/N)')
response = input()[0].upper()

if response != "Y":
print("Thanks for participating!")
break

total_points += word_points


if __name__ == "__main__":
word_100_points_game()
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package main

import (
"bufio"
"fmt"
"log"
"os"
"strings"
)

func main() {
fmt.Print("Enter a string to check: ")
reader := bufio.NewReader(os.Stdin)
word, err := reader.ReadString('\n')
if err != nil {
log.Fatal(err)
}
word = strings.Trim(word, "\n")
word = strings.ReplaceAll(word, " ", "")
m := getMap(strings.ToLower(word))

isHeterogram(word, m)
isIsogram(word, m)
isPangram(word, m)
}

func getMap(word string) map[string]int {
m := map[string]int{}

for _, l := range word {
m[string(l)]++
}

return m
}

func isHeterogram(word string, wordMap map[string]int) {
for _, v := range wordMap {
if v > 1 {
fmt.Printf("%s is NOT an heterogram\n", word)
return
}
}
fmt.Printf("%s is an heterogram\n", word)
}

func isIsogram(word string, wordMap map[string]int) {
firstLetter := word[0]
for _, v := range wordMap {
if v != wordMap[string(firstLetter)] {
fmt.Printf("%s is NOT an isogram\n", word)
return
}
}
fmt.Printf("%s is an isogram\n", word)
}

func isPangram(word string, wordMap map[string]int) {
alphabet := "abcdefghijklmnopqrstuvwxyz"

for _, l := range alphabet {
if wordMap[string(l)] == 0 {
fmt.Printf("%s is NOT a pangram\n", word)
return
}
}
fmt.Printf("%s is a pangram\n", word)
}

0 comments on commit 613a648

Please sign in to comment.