Skip to content

Instantly share code, notes, and snippets.

View kmbenjel's full-sized avatar

Khalid Benjelloun kmbenjel

View GitHub Profile
@kmbenjel
kmbenjel / until_zero.rb
Created April 18, 2021 07:23
This program keeps accepting numbers from the user till he submits the number 0, then it prints out the sum of the numbers, the max, the min and the average and ends.
min = 0
max = 0
sum = 0
count = 0
input = ""
def results(min,max,avg)
puts "End of program"
puts "-------------------------"
puts "The lowest number was: #{min}"
puts "The highest number was: #{max}"
def is_solved(board)
all_nine = board.join.chars.map{|i| i.to_i}
all_lines = []
all_lines << [all_nine[0],all_nine[1],all_nine[2]]
all_lines << [all_nine[0],all_nine[3],all_nine[6]]
all_lines << [all_nine[0],all_nine[4],all_nine[8]]
all_lines << [all_nine[2],all_nine[5],all_nine[8]]
all_lines << [all_nine[2],all_nine[4],all_nine[6]]
all_lines << [all_nine[1],all_nine[4],all_nine[7]]
//code
@kmbenjel
kmbenjel / sudoku.rb
Created August 14, 2021 03:37 — forked from gregnavis/sudoku.rb
A simple Sudoku solver in Ruby.
class Sudoku
SIZE = 9
NUMBERS = (1..9).to_a
def initialize
@board = Array.new(SIZE) { Array.new(SIZE, nil) }
end
def [](x, y)
@board[y][x]
#include<unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_print_comb2(void)
{
int a;
int b;
@kmbenjel
kmbenjel / fall2022.rb
Created December 25, 2022 15:22
Just to get ideas, it is not much efficient for the moment, don't try it on CodinGame IDE
STDOUT.sync = true # DO NOT REMOVE
$opp_units_initial = []
# Find the farthest point in the field
def farthest(w, h, x, y)
far_x = x > w/2 ? 0 : w
far_y = y > h/2 ? 0 : h
{ x: far_x, y: far_y }
end
@kmbenjel
kmbenjel / words.rb
Last active May 29, 2023 18:32
My submission to: `Integer to English Words` challenge on LeetCode (Hard)
# frozen_string_literal: true
def three_digit_to_words(num)
ones = %w[zero one two three four five six seven eight nine]
teens = %w[ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen]
tens = %w[ten twenty thirty forty fifty sixty seventy eighty ninety]
words = []
if (num / 100).positive?
words << ones[num / 100].capitalize
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kbenjel <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/07 02:58:22 by kbenjel #+# #+# */
/* Updated: 2023/09/08 03:59:10 by kbenjel ### ########.fr */
/* */
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_combn.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kbenjell <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/26 12:53:33 by kbenjell #+# #+# */
/* Updated: 2024/08/17 18:21:27 by kbenjell ### ########.fr */
/* */
#include <stdio.h>
void print_tab(int *tab, int size);
void ft_swap(int *a, int *b)
{
int tmp;
tmp = *a;
*a = *b;
*b = tmp;