Created
April 18, 2012 11:43
-
-
Save YoukaiCat/2413044 to your computer and use it in GitHub Desktop.
Решение простой задачи на различных языках
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Найти все натуральные числа a,b,c из интервала от 1 до 20, | |
-- для которых выполняется равенство c2 = b*a2 | |
numbers :: [(Int, Int, Int)] | |
numbers = [ (a,b,c) | a <- [1..20], b <- [1..20], c <- [1..20], c * 2 == b * a * 2 ] | |
main :: IO () | |
main = mapM_ printParams numbers | |
where | |
printParams (a,b,c) = putStrLn $ "a = " ++ show a ++ ", b = " ++ show b ++ ", c = " ++ show c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ Найти все натуральные числа a,b,c из интервала от 1 до 20, | |
для которых выполняется равенство c2 = b*a2 } | |
program zadacha; | |
var | |
a, b, c:integer; | |
begin | |
for a:=1 to 20 do | |
for b:=1 to 20 do | |
for c:=1 to 20 do | |
if ( c * 2 = b * a * 2 ) then | |
writeln( 'a = ', a, ' b = ', b, ' c = ', c ); | |
readln; | |
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Найти все натуральные числа a,b,c из интервала от 1 до 20, | |
# для которых выполняется равенство c2 = b*a2 | |
i = s = e = ""; ('a'..'c').each { |x| i += "(1..20).each {|#{x}| "; s += "#{x} = \#{#{x}}, "; e += "}" } | |
eval "#{i} puts \"#{s}\" if c * 2 == b * a * 2 #{e}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment