reorganisation + hashmap
This commit is contained in:
		
							
								
								
									
										48
									
								
								q2/algo/hashmap.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								q2/algo/hashmap.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,48 @@ | ||||
| public class hashmap implements Map{ | ||||
|  | ||||
| 	public static final TAB_SIZE = 1024; | ||||
| 	Object[] values = new Object[TAB_SIZE]; | ||||
| 	class tuple{ public Object key, values;  | ||||
| 		public tuple(Object key, Object value){ | ||||
| 			this.key = key; | ||||
| 			this.value = value; | ||||
| 		} | ||||
| 	 | ||||
| 	} | ||||
|  | ||||
| 	public hashmap() { | ||||
| 	} | ||||
|  | ||||
| 	public void put(Object key, Object value){ | ||||
| 		int pos = key.hashCode() % values.lenght(); | ||||
| 		if (values[pos] == null){ | ||||
| 			values[pos] = value; | ||||
| 			return; | ||||
| 		} | ||||
| 		if(value[pos] instanceof ArrayList<tuple> t){ | ||||
| 			t.add(new tuple(key, value)); | ||||
| 			return; | ||||
| 		} | ||||
| 		Object temp = values[pos]; | ||||
| 		values[pos] = new ArrayList<tuple>; | ||||
| 		value[pos].add(temp); | ||||
| 		value[pos].add(new tuple(key, value)); | ||||
| 	} | ||||
|  | ||||
| 	public Object get(Object key){ | ||||
| 		int pos = key.hashCode() % values.lenght(); | ||||
| 		if(values[pos].equals(key)){ | ||||
| 			return values[pos].value; | ||||
| 		} | ||||
| 		if(values[pos] instanceof ArrayList<tuple> t){ | ||||
| 			for (v : t) { | ||||
| 				if (v.key.equals(key)){ | ||||
| 					return v.value | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		return null; | ||||
|  | ||||
| 	} | ||||
| } | ||||
|  | ||||
							
								
								
									
										0
									
								
								q2/tp2/recursif/.idea/.gitignore → q2/algo/tp2/recursif/.idea/.gitignore
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										0
									
								
								q2/tp2/recursif/.idea/.gitignore → q2/algo/tp2/recursif/.idea/.gitignore
									
									
									
										generated
									
									
										vendored
									
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										29
									
								
								q2/fonctio/tp1/algo_q21.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								q2/fonctio/tp1/algo_q21.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,29 @@ | ||||
| #!/bin/python | ||||
|  | ||||
| def toBinaryString(user_i:int): | ||||
|     squares  = [2**i for i in range(32)] | ||||
|     squares.reverse() | ||||
|  | ||||
|     ret = '' | ||||
|     show = False | ||||
|  | ||||
|     for s in squares: | ||||
|         if user_i & s: | ||||
|             ret += '1' | ||||
|             show=True | ||||
|         else: | ||||
|             if show: | ||||
|                 ret += '0' | ||||
|     return ret  | ||||
|  | ||||
|  | ||||
| def main(): | ||||
|     """ | ||||
|     Ask the user for an input | ||||
|     """ | ||||
|     user_in = input("entrez un nombre :") | ||||
|     print(toBinaryString(int(user_in))) | ||||
|  | ||||
|  | ||||
| if __name__ == "__main__": | ||||
|     main() | ||||
							
								
								
									
										85
									
								
								q2/fonctio/tp1/exercices.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										85
									
								
								q2/fonctio/tp1/exercices.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,85 @@ | ||||
| # Exercices | ||||
|  | ||||
| ## Binary | ||||
|  | ||||
| 1) \\(  \\)  | ||||
|  | ||||
| 2) 4095 | ||||
|  | ||||
| 3) 100000 (2) = 32 (10) | ||||
| 4) 000010 (2) = 2 (10) | ||||
| 5) 111111 (2) = 63 (10) | ||||
| 6) 010101 (2) = 21 (10) | ||||
|  | ||||
| 7) 64 (10) = 0100 0000 (2) | ||||
| 8) 7 (10) = 0000 0100 (2) | ||||
| 9) 192 (10) = 1100 0000 (2) | ||||
| 10) 3073 (10) = 0110 0000 0001 (2) | ||||
|  | ||||
| 11) 0x1010 = 4112 | ||||
| 12) 0x10A0 = 4256 | ||||
| 13) 0xBABE = 47806 | ||||
|  | ||||
| 14) 020 = 16 | ||||
| 15) 072 = 58 | ||||
|  | ||||
| 16) sur papier = 0xCAFE | ||||
| 17) sur papier = 02001 | ||||
|  | ||||
| 18) 0xCAFE = 1100 1010 1111 1110 | ||||
| 19) 0xCAFE = 0145376 | ||||
| 20) 072 = 111010 | ||||
|  | ||||
| 21) > ./algo_q21.py | ||||
|  | ||||
| ## Complement a 2 | ||||
|  | ||||
| 22) | ||||
| 23) \\( -2^11 → 2^11-1 \\)   | ||||
|  | ||||
| 24) 17 = 0001 0001 | ||||
| 25) -17 = 1110 1101 | ||||
| 26) 255 = 1111 1111 (Imposible car pas dans l'interval) | ||||
| 27) -128 = 1000 0000 | ||||
| 28) -73 = 10110111  | ||||
|  | ||||
| 29)   01001111 | ||||
|    +  00000001 | ||||
|    =  01010000 | ||||
|  | ||||
| 30) - 10010110 = 01101010 | ||||
|  | ||||
| 31)   01001111 | ||||
|     + 01000001 | ||||
|     --------- | ||||
|     = 10010000 (Overflow, le nombre n'est pas dans la range de nombre accesible sur 8 bits en ca2) | ||||
|  | ||||
| 32)   00000001 | ||||
|     - 00000010 | ||||
|     ---------- | ||||
|     = 11111111 | ||||
|  | ||||
| 33)   00001001 | ||||
|     x 00000110 | ||||
|     ---------- | ||||
|      000010010       | ||||
|   + 0000100100 | ||||
|   ------------ | ||||
|   = 0000110110 | ||||
|  | ||||
| 34)   10000001 | ||||
|     - 10000010 | ||||
|     ---------- | ||||
|     = 11111111  | ||||
| 35) - 10000000 = 011111111 (Imposible a representer sur 8 bits) | ||||
|  | ||||
| 36)   00010100 | ||||
|     / 00000101 | ||||
|     ---------- | ||||
|       00000100 | ||||
|  | ||||
| 37)   00010111 | ||||
|     / 00001001 | ||||
|     ---------- | ||||
|       00000010 (reste 101) | ||||
| 38) | ||||
							
								
								
									
										
											BIN
										
									
								
								q2/fonctio/tp1/fonct-ordis-tp1-integers.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								q2/fonctio/tp1/fonct-ordis-tp1-integers.pdf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user