Solving HackerRank HARD Problems with Codestral.
HTML-код
- Опубликовано: 3 июн 2024
- Codestral is a really good model and i wanted to see if It can solving coding problems efficiently!
I used Mistral's codestral a really powerful (22B coding expert model) with 32K context window to solve hard python hackerrank problems!
🔗 Links 🔗
Codestral - mistral.ai/news/codestral/
Codestral on HF mode hub - huggingface.co/mistralai/Code...
❤️ If you want to support the channel ❤️
Support here:
Patreon - / 1littlecoder
Ko-Fi - ko-fi.com/1littlecoder
🧭 Follow me on 🧭
Twitter - / 1littlecoder
Linkedin - / amrrs Наука
I think these types of problems are surely part of the training dataset.
codestral vs claude opus?
I really hope AI masters all that DSA, in next 2-3 years. Just prompt your problem and AI comes up with proper DS , Algo and system design.
impressive I'm keen to see how it would go in Aider
How do you know that the model was not trained on problems like this? It could have memorized the solution, couldn’t it?
I tried Codestral many times last days to solve not standard problems and it was failed. I couldn't get any suitable response (Python and Typescript) so I guess it can solve popular tasks but can't do anything good with specific things
Thank you for the great video! I did try a one shot test of making a Snake game, and a Tetris game (very hard, only top models like gpt 4 and claude opus can do) and it did a great Snake game but the Tetris did not work. However for the 22B size I think it's a very good model and it's great there is some competition to the closed source (which probably will always be better due to their huge training and parameters)
Thanks for testing. Did you try to make Tetris in Python? Was it supposed to use Pygame?
@@1littlecoder Yes it was all in Python, I test all the models in Python because this is usually the language they are best at, and also most useful for ai and machine learning. I don't remember which library it used specifically I will check
Ok, I see it used Pygame library for both. Btw all the requests are via the Mistral official API.
Here is the complete response that I got for a snake game, containing a nice working snake game (you need to press the arrows to start). The Tetris is not functioning so I won't add it but it also tried to use the Pygame.
Everything from here until the end of the comment is Codestral response nothing I wrote-
-------------------------------
Headline: "Creating a Simple Snake Game in Python: A Step-by-Step Guide"
Introduction:
Python, with its simplicity and readability, is an excellent language for beginners to learn programming. One of the most popular projects for beginners is creating a snake game. This article will guide you through the process of creating a simple snake game in Python using the Pygame library.
Step 1: Install Pygame
Before we start, make sure you have Pygame installed on your computer. If not, you can install it using pip:
```python
pip install pygame
```
Step 2: Import Necessary Libraries
In your Python script, import the necessary libraries:
```python
import pygame
import time
import random
```
Step 3: Initialize Pygame
Initialize Pygame and create a game window:
```python
pygame.init()
white = (255, 255, 255)
yellow = (255, 255, 102)
black = (0, 0, 0)
red = (213, 50, 80)
green = (0, 255, 0)
blue = (50, 153, 213)
dis_width = 800
dis_height = 600
dis = pygame.display.set_mode((dis_width, dis_height))
pygame.display.set_caption('Snake Game')
clock = pygame.time.Clock()
snake_block = 10
snake_speed = 30
```
Step 4: Create the Snake Function
Define a function to draw the snake:
```python
def our_snake(snake_block, snake_List):
for x in snake_List:
pygame.draw.rect(dis, white, [x[0], x[1], snake_block, snake_block])
```
Step 5: Create the Game Loop
Create the main game loop:
```python
def gameLoop():
game_over = False
game_close = False
x1 = dis_width / 2
y1 = dis_height / 2
x1_change = 0
y1_change = 0
snake_List = []
Length_of_snake = 1
foodx = round(random.randrange(0, dis_width - snake_block) / 10.0) * 10.0
foody = round(random.randrange(0, dis_height - snake_block) / 10.0) * 10.0
while not game_over:
while game_close == True:
dis.fill(blue)
font_style = pygame.font.SysFont(None, 50)
message = font_style.render("You Lost! Press Q-Quit or C-Play Again", True, red)
dis.blit(message, [dis_width / 2, dis_height / 2])
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_q:
game_over = True
game_close = False
if event.key == pygame.K_c:
gameLoop()
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_over = True
game_close = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
y1_change = -snake_block
x1_change = 0
elif event.key == pygame.K_DOWN:
y1_change = snake_block
x1_change = 0
elif event.key == pygame.K_LEFT:
x1_change = -snake_block
y1_change = 0
elif event.key == pygame.K_RIGHT:
x1_change = snake_block
y1_change = 0
if x1 >= dis_width or x1 < 0 or y1 >= dis_height or y1 < 0:
game_close = True
x1 += x1_change
y1 += y1_change
dis.fill(blue)
pygame.draw.rect(dis, green, [foodx, foody, snake_block, snake_block])
snake_Head = []
snake_Head.append(x1)
snake_Head.append(y1)
snake_List.append(snake_Head)
if len(snake_List) > Length_of_snake:
del snake_List[0]
for x in snake_List[:-1]:
if x == snake_Head:
game_close = True
our_snake(snake_block, snake_List)
pygame.display.update()
if x1 == foodx and y1 == foody:
foodx = round(random.randrange(0, dis_width - snake_block) / 10.0) * 10.0
foody = round(random.randrange(0, dis_height - snake_block) / 10.0) * 10.0
Length_of_snake += 1
clock.tick(snake_speed)
pygame.quit()
quit()
gameLoop()
```
Conclusion:
Creating a snake game in Python is a fun and educational project for beginners. By following this guide, you can create a simple yet engaging snake game using the Pygame library. Remember to experiment with the code and customize it to your liking. Happy coding!
Ok, I see it used Pygame library for both. Btw all the requests are via the Mistral official API.
Here is the complete response that I got for a snake game, containing a nice working snake game (you need to press the arrows to start). The Tetris is not functioning so I won't add it but it also tried to use the Pygame.
Everything from here until the end of the comment is Codestral response nothing I wrote-
------------------------------------
Headline: "Creating a Simple Snake Game in Python: A Step-by-Step Guide"
Introduction:
Python, with its simplicity and readability, is an excellent language for beginners to learn programming. One of the most popular projects for beginners is creating a snake game. This article will guide you through the process of creating a simple snake game in Python using the Pygame library.
Step 1: Install Pygame
Before we start, make sure you have Pygame installed on your computer. If not, you can install it using pip:
```python
pip install pygame
```
Step 2: Import Necessary Libraries
In your Python script, import the necessary libraries:
```python
import pygame
import time
import random
```
Step 3: Initialize Pygame
Initialize Pygame and create a game window:
```python
pygame.init()
white = (255, 255, 255)
yellow = (255, 255, 102)
black = (0, 0, 0)
red = (213, 50, 80)
green = (0, 255, 0)
blue = (50, 153, 213)
dis_width = 800
dis_height = 600
dis = pygame.display.set_mode((dis_width, dis_height))
pygame.display.set_caption('Snake Game')
clock = pygame.time.Clock()
snake_block = 10
snake_speed = 30
```
Step 4: Create the Snake Function
Define a function to draw the snake:
```python
def our_snake(snake_block, snake_List):
for x in snake_List:
pygame.draw.rect(dis, white, [x[0], x[1], snake_block, snake_block])
```
Step 5: Create the Game Loop
Create the main game loop:
```python
def gameLoop():
game_over = False
game_close = False
x1 = dis_width / 2
y1 = dis_height / 2
x1_change = 0
y1_change = 0
snake_List = []
Length_of_snake = 1
foodx = round(random.randrange(0, dis_width - snake_block) / 10.0) * 10.0
foody = round(random.randrange(0, dis_height - snake_block) / 10.0) * 10.0
while not game_over:
while game_close == True:
dis.fill(blue)
font_style = pygame.font.SysFont(None, 50)
message = font_style.render("You Lost! Press Q-Quit or C-Play Again", True, red)
dis.blit(message, [dis_width / 2, dis_height / 2])
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_q:
game_over = True
game_close = False
if event.key == pygame.K_c:
gameLoop()
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_over = True
game_close = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
y1_change = -snake_block
x1_change = 0
elif event.key == pygame.K_DOWN:
y1_change = snake_block
x1_change = 0
elif event.key == pygame.K_LEFT:
x1_change = -snake_block
y1_change = 0
elif event.key == pygame.K_RIGHT:
x1_change = snake_block
y1_change = 0
if x1 >= dis_width or x1 < 0 or y1 >= dis_height or y1 < 0:
game_close = True
x1 += x1_change
y1 += y1_change
dis.fill(blue)
pygame.draw.rect(dis, green, [foodx, foody, snake_block, snake_block])
snake_Head = []
snake_Head.append(x1)
snake_Head.append(y1)
snake_List.append(snake_Head)
if len(snake_List) > Length_of_snake:
del snake_List[0]
for x in snake_List[:-1]:
if x == snake_Head:
game_close = True
our_snake(snake_block, snake_List)
pygame.display.update()
if x1 == foodx and y1 == foody:
foodx = round(random.randrange(0, dis_width - snake_block) / 10.0) * 10.0
foody = round(random.randrange(0, dis_height - snake_block) / 10.0) * 10.0
Length_of_snake += 1
clock.tick(snake_speed)
pygame.quit()
quit()
gameLoop()
```
Conclusion:
Creating a snake game in Python is a fun and educational project for beginners. By following this guide, you can create a simple yet engaging snake game using the Pygame library. Remember to experiment with the code and customize it to your liking. Happy coding!
Yes both used Pygame-
import pygame
import time
import random
these are the imports for the snake, and for the tetris (which didnt work) without the time..
Btw all was tested via Mistral official API
What OCR extension is that!? I need that in my life
the one i'm using is a mac specific one, but i heard windows might have this inbuilt.
The mac one is Shottr. I'm using their free version!
Try copy fish
question is if this model was trained on these problems
Hi 1littlecode, I'm also a mac user. Yesterday I was surprised by the tool that you are using for the image to text by clipping the screen. May i know that tool please?
Thank you
Guna Sekhar
Hey it's Shottr.
@@1littlecoder Thankyou. Also in so many days back I have asked you one question that how to build a embedding model from scratch for llm training instead of converting the original text into desired text using any language translators... If possible Could you make any video on that by chance!
Thank you
Guna Sekhar
I don't agree the problem difficulty, first problem is just maximum all possible sum of square of elements. there more harder problems In hackerrank itself
Why didn't you compare it with GPT 4o?
I did internally but I decided to not publish it thinking it's an unfair comparison. for context, this is a 22B open model. gpt-4o could be a trillion paramter or in the hundreds of billion closed model. I just felt maybe I'd be doing a disservice by doing that comparison. what do you think?
@@1littlecoder I think it makes sense to compare several models at once, after all, many of them are free and the end user is interested in the result, and not the number of parameters in the model
@@DLBrawlStars That's right, people interested in model performance not the parameter size. In fact, Codestral beats gpt4o for mere 22 B param! I tested the model locally with my peasant RTX 3060 12 GB and cpu intel i5 12400 with the below prompt and using Ollama and Page Assist chrome extension and it give me the working code with only one freaking shot! GPT4o cannot give the working code even after vigorous chat back and forth, until I ask it to better rephrase my broken English prompt and then use the provided better prompt and with another couple of back and forth chatting, finally it solved it. But codestral give the working script with only one shot. How amazing is it for only 22 B param that can be run locally:
I am using Windows 11 and ffmpeg binary already in path. So make me simple python script with GUI using tkinter and make it responsive using threading..to speed up mp4 video using ffmpeg with value of x speed time which I can slide the value from 1x to 5x..and increment for each is 0.1x. Display the value too when I slide the slider in the little box beside the slider. And use crf value of 29. And I can browse and select multiple mp4 videos. Put a button called "Speed up now" too when I clicked, it will start process..and when finish it will beep like 3 second using ffplay which also on path already..and I can browse what folder I want to put the output videos too..
Wow, nice idea for a test.