Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ClemenceAl committed Nov 23, 2018
2 parents 00a201b + afacc69 commit 610f7bd
Show file tree
Hide file tree
Showing 5 changed files with 253 additions and 9 deletions.
49 changes: 49 additions & 0 deletions PastDatas/EventCandidatD.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@




class Fred
def initialize(v)
@val = v
end

# Set it and get it.
def set(v)
@val = v
end

def get
return @val
end
end

a = Fred.new(10)
b = Fred.new(22)

print "A: ", a.get, " ", b.get,"\n";
b.set(34)
print "B: ", a.get, " ", b.get,"\n";

class Fred
def inc
@val += 1
end
end

a.inc
b.inc
print "C: ", a.get, " ", b.get,"\n";

def b.dec
@val -= 1
end

begin
b.dec
a.dec
rescue StandardError => msg
print "Error: ", msg, "\n"
end

print "D: ", a.get, " ", b.get,"\n";

162 changes: 162 additions & 0 deletions PastDatas/EventCandidatE.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
class EventCandidatC < ApplicationRecord
self.table_name = 'events'
KIND = %w(opening appointment).freeze

validates :kind, inclusion: { in: KIND, message: 'is not a valid kind of event' }
validates :starts_at, presence: true
validates :ends_at, presence: true
validate :starts_at_cannot_be_greater_than_ends_at,
:ends_at_cannot_be_a_different_day_than_starts_at,
:hours_must_be_a_multiple_of_thirty_minutes,
:same_kind_of_event_cannot_be_in_a_same_time_slot

with_options if: :appointment? do |appointment|
appointment.validates :weekly_recurring, absence: true
appointment.validate :appointment_cannot_be_outside_of_opening_hours
end


# Function to evaluate a polynomial at x. The polynomial is given
# as a list of coefficients, from the greatest to the least.
def polyval(x, coef)
sum = 0
coef = coef.clone # Don't want to destroy the original
while true
sum += coef.shift # Add and remove the next coef
break if coef.empty? # If no more, done entirely.
sum *= x # This happens the right number of times.
end
return sum
end

#
# Function to read a line containing a list of integers and return
# them as an array of integers. If the string conversion fails, it
# throws TypeError. If the input line is the word 'quit', then it
# converts it to an end-of-file exception
def readints(prompt)
# Read a line
print prompt
line = readline.chomp
raise EOFError.new if line == 'quit' # You can also use a real EOF.

# Go through each item on the line, converting each one and adding it
# to retval.
retval = [ ]
for str in line.split(/\s+/)
# Objects may have methods all to themselves.
if str =~ /^\-?\d+$/
retval.push(str.to_i)
else
raise TypeError.new
end
end

return retval
end

#
# Take a coeff and an exponent and return the string representation, ignoring
# the sign of the coefficient.
def term_to_str(coef, exp)
ret = ""

# Show coeff, unless it's 1 or at the right
coef = coef.abs
ret = coef.to_s unless coef == 1 && exp > 0
ret += "x" if exp > 0 # x if exponent not 0
ret += "^" + exp.to_s if exp > 1 # ^exponent, if > 1.

return ret
end



return result
end

#
# Run until some kind of endfile.
begin
# Repeat until an exception or quit gets us out.
while true
# Read a poly until it works. An EOF will except out of the
# program.
print "\n"
begin
poly = readints("Enter a polynomial coefficients: ")
rescue TypeError
print "Try again.\n"
retry
end
break if poly.empty?

# Read and evaluate x values until the user types a blank line.
# Again, an EOF will except out of the pgm.
while true
# Request an integer.
print "Enter x value or blank line: "
x = readline.chomp
break if x == ''
raise EOFError.new if x == 'quit'

# If it looks bad, let's try again.
if x !~ /^\-?\d+$/
print "That doesn't look like an integer. Please try again.\n"
next
end

# Convert to an integer and print the result.
x = x.to_i
print "p(x) = ", polystr(poly), "\n"
print "p(", x, ") = ", polyval(x, poly), "\n"
end
end
rescue EOFError
print "\n=== EOF ===\n"
rescue Interrupt, SignalException
print "\n=== Interrupted ===\n"
else
print "--- Bye ---\n"
end

def opening?
kind.eql? 'opening'
end

def appointment?
kind.eql? 'appointment'
end



private

def starts_at_cannot_be_greater_than_ends_at
if starts_at.present? and ends_at.present? and starts_at >= ends_at
errors.add(:starts_at, 'cannot be greater than ends_at')
end
end

def ends_at_cannot_be_a_different_day_than_starts_at
if starts_at.present? and ends_at.present? and starts_at.to_date != ends_at.to_date
errors.add(:ends_at, 'cannot be a different day than starts_at')
end
end



def same_kind_of_event_cannot_be_in_a_same_time_slot
if kind.present? and starts_at.present? and ends_at.present? and
EventCandidatA.where(kind: kind).overlapping(starts_at, ends_at).any?
errors.add(:base, 'cannot be in a same time slot than an other')
end
end

def appointment_cannot_be_outside_of_opening_hours
if starts_at.present? and ends_at.present? and
EventCandidatA.openings_on(starts_at).cover(starts_at, ends_at).empty?
errors.add(:base, 'cannot be outside of opening hours')
end
end
end
1 change: 1 addition & 0 deletions PastDatas/EventCandidatF.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print "Hello, World!\n"
41 changes: 41 additions & 0 deletions PastDatas/EventCandidatG.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# An N-bit adder built of one-bit adders with simple carry propagation.
#

require "oba"

class Adder < Blueprint
# This initializes the object, If we already have a one-bit adder
# blueprint lying around, we can reuse it with that second argument.
def initialize(n, bp = nil)
super(n.to_s + "-bit adder")

# Blueprint for a the one-bit adder
bp = OBA.new unless bp
@one_bit_bp = bp

# Make all the adders, and specify them as inputs.
addrs = bp.manyothers(n)
self.inputs(addrs,addrs)

# Create output connectors and chain the carries.
prev = nil
for addr in addrs
c = Connector.new
addr.join(c)
if prev then
prev.out(1).join(addr)
end
self.outputs(c)

prev = addr
end

# Overflow
self.outputs(prev)

self.lock
end

attr_reader :one_bit_bp
end
9 changes: 0 additions & 9 deletions server/script.py

This file was deleted.

0 comments on commit 610f7bd

Please sign in to comment.